From 474776a864ae6de0d1c5b2cefb76899a328207f5 Mon Sep 17 00:00:00 2001 From: Geoffrey Frogeye Date: Sun, 5 Feb 2017 12:11:05 +0100 Subject: [PATCH] Implémentation JSON, on arrête les bêtises --- api.raml | 20 +++++++++----------- src/main/java/etunicorn/Application.java | 1 + src/main/java/etunicorn/SecurityInterceptor.java | 44 ++++++++++++++++++++++++++++++++------------ src/main/java/etunicorn/controller/BaseController.java | 113 +++++++++++++++++++++++++---------------------------------------------------------------------------------------- src/main/java/etunicorn/controller/LoginController.java | 31 +++++++++++++++++-------------- src/main/java/etunicorn/controller/PersonneController.java | 71 +++++++++++++++++++++++++++++++---------------------------------------- src/main/java/etunicorn/controller/RoleController.java | 34 ++++++++++------------------------ src/main/java/etunicorn/generated/LoginController.java | 18 ++++++++---------- src/main/java/etunicorn/generated/RoleController.java | 41 ++++++++++++++++++++--------------------- src/main/java/etunicorn/service/SessionService.java | 5 +++++ 10 files changed, 158 insertions(+), 220 deletions(-) diff --git a/api.raml b/api.raml index f319ba3..5c5acfe 100644 --- a/api.raml +++ b/api.raml @@ -46,14 +46,13 @@ version: v1 } 401: description: Authentication échouée - /{token}: - delete: - description: Se déconnecter - responses: - 204: - description: Déconnecté avec succès - 404: - description: Jeton non trouvé + delete: + description: Se déconnecter + responses: + 204: + description: Déconnecté avec succès + 404: + description: Jeton non trouvé /personne: get: description: Obtenir la liste des persones. Nécessite COMPTE_ADMIN @@ -233,10 +232,9 @@ version: v1 /{nomRole}: uriParameters: nomRole: - type: number + type: string required: true - description: ID du role - minimum: 0 + description: Nom du role delete: description: Supprime un rôle. Nécessite ROLE_ADMIN responses: diff --git a/src/main/java/etunicorn/Application.java b/src/main/java/etunicorn/Application.java index ed7cc45..00c8eec 100644 --- a/src/main/java/etunicorn/Application.java +++ b/src/main/java/etunicorn/Application.java @@ -44,6 +44,7 @@ public class Application { permissionRepository.save(new Permission("PERSONNE_GET")); permissionRepository.save(new Permission("PERSONNE_LIST")); permissionRepository.save(new Permission("PERSONNE_REMOVE")); + permissionRepository.save(new Permission("PERSONNE_ROLE")); permissionRepository.save(new Permission("ROLE_ADD")); permissionRepository.save(new Permission("ROLE_DELETE")); permissionRepository.save(new Permission("ROLE_PERMISSION_ADD")); diff --git a/src/main/java/etunicorn/SecurityInterceptor.java b/src/main/java/etunicorn/SecurityInterceptor.java index a2b3b9f..fda1f6a 100644 --- a/src/main/java/etunicorn/SecurityInterceptor.java +++ b/src/main/java/etunicorn/SecurityInterceptor.java @@ -1,11 +1,14 @@ package etunicorn; +import etunicorn.controller.BaseController; import etunicorn.entity.Permission; import etunicorn.entity.Session; import etunicorn.repository.PermissionRepository; import etunicorn.service.SessionService; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.method.HandlerMethod; import org.springframework.web.servlet.ModelAndView; @@ -13,6 +16,7 @@ import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import java.io.IOException; /** * etunicorn-server @@ -29,6 +33,16 @@ public class SecurityInterceptor extends HandlerInterceptorAdapter { super(); } + private void responseEntityToServletResponse(ResponseEntity responseEntity, HttpServletResponse response) throws IOException { + HttpHeaders httpHeaders = responseEntity.getHeaders(); + for (String header : httpHeaders.keySet()) { + for (String headerValue : httpHeaders.get(header)) { + response.setHeader(header, headerValue); + } + } + response.getWriter().write(responseEntity.getBody().toString()); + } + @Override @Transactional public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { @@ -37,20 +51,26 @@ public class SecurityInterceptor extends HandlerInterceptorAdapter { HandlerMethod method = (HandlerMethod) handler; RestrictedTo annotation = method.getMethodAnnotation(RestrictedTo.class); - Permission requiredPermission = permissionRepository.findByNom(annotation.value()); - if (requiredPermission == null) { - response.setStatus(HttpStatus.NOT_IMPLEMENTED.value()); - return false; - } - - if (annotation.authentifie()) { - if (session == null) { - response.setStatus(HttpStatus.UNAUTHORIZED.value()); + if (annotation != null) { + Permission requiredPermission = permissionRepository.findByNom(annotation.value()); + if (requiredPermission == null) { + response.setStatus(HttpStatus.NOT_IMPLEMENTED.value()); return false; - } else { - if (!session.hasPermission(requiredPermission)) { - response.setStatus(HttpStatus.FORBIDDEN.value()); + } + + if (annotation.authentifie()) { + BaseController baseController = new BaseController(); + baseController.setRequest(request); + if (session == null) { + ResponseEntity responseEntity = baseController.generateError(HttpStatus.UNAUTHORIZED); + responseEntityToServletResponse(responseEntity, response); return false; + } else { + if (!session.hasPermission(requiredPermission)) { + ResponseEntity responseEntity = baseController.generateError(HttpStatus.FORBIDDEN); + responseEntityToServletResponse(responseEntity, response); + return false; + } } } } diff --git a/src/main/java/etunicorn/controller/BaseController.java b/src/main/java/etunicorn/controller/BaseController.java index a543019..f7f5d3c 100644 --- a/src/main/java/etunicorn/controller/BaseController.java +++ b/src/main/java/etunicorn/controller/BaseController.java @@ -1,11 +1,7 @@ package etunicorn.controller; -import com.fasterxml.jackson.annotation.JsonProperty; import etunicorn.entity.Permission; import etunicorn.entity.Session; -import etunicorn.exception.EntityRequestMismatchException; -import etunicorn.exception.NotEnoughDataException; -import etunicorn.exception.ObjectNotFoundException; import etunicorn.repository.PermissionRepository; import etunicorn.service.SessionService; import net.minidev.json.JSONObject; @@ -15,12 +11,10 @@ import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.RestController; -import javax.persistence.Entity; import javax.servlet.http.HttpServletRequest; -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.LinkedHashMap; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.util.Date; import java.util.Map; /** @@ -42,6 +36,10 @@ public class BaseController { @Autowired private PermissionRepository permissionRepository; + public void setRequest(HttpServletRequest request) { + this.request = request; + } + protected boolean hasPermission(Permission permission) { Session session = sessionService.getSession(request); if (session == null || permission == null) { @@ -56,97 +54,36 @@ public class BaseController { } // Utilités pour générer des erreurs - ResponseEntity generateError(HttpStatus status, String message) { + private JSONObject generateErrorJSON(HttpStatus status, String message) { JSONObject json = new JSONObject(); + json.put("timestamp", new Date().getTime()); json.put("status", status.value()); json.put("message", message); - return new ResponseEntity(json, status); - } + json.put("path", request.getPathInfo()); + return json; - ResponseEntity generateError(HttpStatus status) { - return generateError(status, String.format("Erreur de type %d", status.value())); } - ResponseEntity generateError(HttpStatus status, Exception exception, String message) { - JSONObject json = new JSONObject(); - json.put("status", status.value()); - json.put("message", message); - json.put("errorMessage", exception.getLocalizedMessage()); - json.put("stacktrace", exception.getStackTrace().toString()); + public ResponseEntity generateError(HttpStatus status, String message) { + JSONObject json = generateErrorJSON(status, message); return new ResponseEntity(json, status); } - ResponseEntity generateError(Exception exception) { - return generateError(HttpStatus.INTERNAL_SERVER_ERROR, exception, exception.getLocalizedMessage()); + public ResponseEntity generateError(HttpStatus status, Exception exception, String message) { + JSONObject json = generateErrorJSON(status, message); + json.put("error", exception.getMessage()); + // From http://stackoverflow.com/a/1149721 + StringWriter sw = new StringWriter(); + exception.printStackTrace(new PrintWriter(sw)); + json.put("stacktrace", sw.toString()); + return new ResponseEntity(json, status); } - protected Object getEntityFromObject(String className, LinkedHashMap object) throws NotEnoughDataException { - Object repository = repositories.get(className + "Repository"); - for (Method findMethod : repository.getClass().getMethods()) { - String findMethodName = findMethod.getName(); - if (findMethodName.startsWith("findBy")) { - String key = Character.toLowerCase(findMethodName.charAt(6)) + findMethodName.substring(7); - if (object.containsKey(key)) { - try { - Object data = object.get(key); - return findMethod.invoke(repository, data); - } catch (IllegalAccessException e) { - continue; - } catch (InvocationTargetException e) { - continue; - } - } else { - continue; - } - } - } - throw new NotEnoughDataException(); + public ResponseEntity generateError(HttpStatus status) { + return generateError(status, status.getReasonPhrase()); } - protected void mergeRequestInEntity(Object request, Object entity) throws EntityRequestMismatchException, NotEnoughDataException, ObjectNotFoundException { - for (Method getMethode : request.getClass().getMethods()) { - String getMethodName = getMethode.getName(); - JsonProperty annotation = getMethode.getAnnotation(JsonProperty.class); - if (getMethodName.startsWith("get") && annotation != null) { - String fieldName = annotation.value(); - String setMethodName = "s" + getMethodName.substring(1); - Method setMethode; - Class fieldClass; - try { - fieldClass = entity.getClass().getMethod(getMethodName).getReturnType(); - setMethode = entity.getClass().getMethod(setMethodName, fieldClass); - } catch (NoSuchMethodException e) { - throw new EntityRequestMismatchException(); - } - try { - if (getMethode.invoke(request) != null) { - Object data = getMethode.invoke(request); - if (data.getClass() != fieldClass) { - if (fieldClass.getAnnotation(Entity.class) != null) { - data = getEntityFromObject(fieldName, (LinkedHashMap) data); - if (data == null) { - throw new ObjectNotFoundException(); - } - } else { - Constructor constructor = fieldClass.getConstructor(data.getClass()); - if (constructor != null) { - data = constructor.newInstance(data); - } - } - } - setMethode.invoke(entity, data); - } - } catch (IllegalAccessException e) { - throw new EntityRequestMismatchException(); - } catch (InvocationTargetException e) { - throw new EntityRequestMismatchException(); - } catch (NoSuchMethodException e) { - throw new EntityRequestMismatchException(); - } catch (InstantiationException e) { - throw new EntityRequestMismatchException(); - } - } - - } + public ResponseEntity generateError(Exception exception) { + return generateError(HttpStatus.INTERNAL_SERVER_ERROR, exception, exception.getLocalizedMessage()); } } diff --git a/src/main/java/etunicorn/controller/LoginController.java b/src/main/java/etunicorn/controller/LoginController.java index 20458db..4912af3 100644 --- a/src/main/java/etunicorn/controller/LoginController.java +++ b/src/main/java/etunicorn/controller/LoginController.java @@ -9,11 +9,10 @@ import etunicorn.service.SessionService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; +import javax.servlet.http.HttpServletRequest; import javax.validation.Valid; /** @@ -22,27 +21,25 @@ import javax.validation.Valid; * Tous droits réservés */ @RestController -public class LoginController implements etunicorn.generated.LoginController { +public class LoginController extends BaseController implements etunicorn.generated.LoginController { + @Autowired + HttpServletRequest request; @Autowired private PersonneRepository personneRepository; - @Autowired private SessionService sessionService; @Override @RestrictedTo(authentifie = false) public ResponseEntity updateLogin(@Valid @RequestBody UpdateLoginRequest updateLoginRequest) { - return null; - } - public ResponseEntity updateLogin(@RequestParam String login, @RequestParam String password) { - Personne personne = personneRepository.findByLogin(login); + Personne personne = personneRepository.findByLogin(updateLoginRequest.getLogin()); if (personne == null) { - return new ResponseEntity(HttpStatus.UNAUTHORIZED); + return generateError(HttpStatus.UNAUTHORIZED); } // TODO Vraie vérification du mot de passe - if (!password.equals("test")) { - return new ResponseEntity(HttpStatus.UNAUTHORIZED); + if (!updateLoginRequest.getPassword().equals("test")) { + return generateError(HttpStatus.UNAUTHORIZED); } Session session = sessionService.createSession(personne); @@ -50,9 +47,15 @@ public class LoginController implements etunicorn.generated.LoginController { return new ResponseEntity(session, HttpStatus.OK); } - @Override - public ResponseEntity deleteLoginByToken(@PathVariable String token) { - return null; + @RestrictedTo(authentifie = false) + public ResponseEntity deleteLogin() { + Session session = sessionService.getSession(request); + if (session != null) { + sessionService.deleteSession(session); + } + return new ResponseEntity(HttpStatus.NO_CONTENT); } + + } diff --git a/src/main/java/etunicorn/controller/PersonneController.java b/src/main/java/etunicorn/controller/PersonneController.java index 4c58c4a..8680602 100644 --- a/src/main/java/etunicorn/controller/PersonneController.java +++ b/src/main/java/etunicorn/controller/PersonneController.java @@ -3,9 +3,6 @@ package etunicorn.controller; import etunicorn.RestrictedTo; import etunicorn.entity.Personne; import etunicorn.entity.Role; -import etunicorn.exception.EntityRequestMismatchException; -import etunicorn.exception.NotEnoughDataException; -import etunicorn.exception.ObjectNotFoundException; import etunicorn.generated.model.UpdatePersonneByIdRequest; import etunicorn.generated.model.UpdatePersonneRequest; import etunicorn.repository.PersonneRepository; @@ -16,12 +13,12 @@ import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import javax.validation.Valid; import java.math.BigDecimal; import java.util.Date; +import java.util.LinkedHashMap; import java.util.List; /** @@ -44,26 +41,32 @@ public class PersonneController extends BaseController implements etunicorn.gene return new ResponseEntity((List) this.personneRepository.findAll(), HttpStatus.OK); } - private ResponseEntity mergePersonne(Personne personne, String carte, Date naissance, String login, String role) { - if (carte != null) { - personne.setCarte(carte); + private ResponseEntity mergePersonne(Personne personne, UpdatePersonneRequest updatePersonneRequest) { + if (updatePersonneRequest.getNaissance() != null) { + personne.setNaissance(new Date(updatePersonneRequest.getNaissance())); } - if (naissance != null) { - personne.setNaissance(naissance); + if (updatePersonneRequest.getCarte() != null) { + personne.setCarte(updatePersonneRequest.getCarte()); } - if (login != null) { - personne.setLogin(login); + if (updatePersonneRequest.getLogin() != null) { + personne.setLogin(updatePersonneRequest.getLogin()); } - // TODO Il faut que login ou carte soient mis - if (role != null) { - if (hasPermission("PERSONNE_ROLE")) { - Role roleObj = roleRepository.findByNom(role); - personne.setRole(roleObj); - if (roleObj == null) { - return new ResponseEntity("Rôle inconnu", HttpStatus.NOT_FOUND); + if (personne.getCarte() == null && personne.getLogin() == null) { + return generateError(HttpStatus.BAD_REQUEST, "La date ou la carte doivent être au moins renseignés."); + } + if (updatePersonneRequest.getRole() != null) { + System.out.println("HELLO"); + LinkedHashMap roleMap = (LinkedHashMap) updatePersonneRequest.getRole(); + Role role = roleRepository.findByNom(roleMap.get("nom")); + if (role == null) { + return generateError(HttpStatus.NOT_FOUND, "Rôle inconnu"); + } + if (personne.getRole() != role) { + if (hasPermission("PERSONNE_ROLE")) { + personne.setRole(role); + } else { + return generateError(HttpStatus.FORBIDDEN, "Vous ne pouvez pas changer le rôle"); } - } else { - return new ResponseEntity(HttpStatus.FORBIDDEN); } } try { @@ -78,20 +81,7 @@ public class PersonneController extends BaseController implements etunicorn.gene @RestrictedTo("PERSONNE_ADD") public ResponseEntity updatePersonne(@Valid @RequestBody UpdatePersonneRequest updatePersonneRequest) { Personne personne = new Personne(); - try { - mergeRequestInEntity(updatePersonneRequest, personne); - } catch (EntityRequestMismatchException e) { - return generateError(e); - } catch (NotEnoughDataException e) { - return generateError(HttpStatus.BAD_REQUEST, e, "Il n'y a pas suffisament de données pour identifier un sous-objet"); - } catch (ObjectNotFoundException e) { - return generateError(HttpStatus.NOT_FOUND, e, "Sous-objet non trouvé"); - } - return new ResponseEntity(personne, HttpStatus.CREATED); - } - public ResponseEntity updatePersonne(@RequestParam(required = false) String carte, @RequestParam(required = false) Date naissance, @RequestParam(required = false) String login, @RequestParam(required = false) String role) { - Personne personne = new Personne(); - return mergePersonne(personne, carte, naissance, login, role); + return mergePersonne(personne, updatePersonneRequest); } @Override @@ -107,15 +97,16 @@ public class PersonneController extends BaseController implements etunicorn.gene @Override @RestrictedTo("PERSONNE_EDIT") public ResponseEntity updatePersonneById(@PathVariable BigDecimal idPersonne, @Valid @RequestBody UpdatePersonneByIdRequest updatePersonneByIdRequest) { - return null; - } - - public ResponseEntity updatePersonneById(@PathVariable BigDecimal idPersonne, @RequestParam(required = false) String carte, @RequestParam(required = false) Date naissance, @RequestParam(required = false) String login, @RequestParam(required = false) String role) { Personne personne = personneRepository.findById(idPersonne.intValueExact()); if (personne == null) { - return new ResponseEntity(HttpStatus.NOT_FOUND); + return generateError(HttpStatus.NOT_FOUND, "Personne introuvable"); } - return mergePersonne(personne, carte, naissance, login, role); + UpdatePersonneRequest updatePersonneRequest = new UpdatePersonneRequest(); + updatePersonneRequest.setCarte(updatePersonneByIdRequest.getCarte()); + updatePersonneRequest.setNaissance(updatePersonneByIdRequest.getNaissance()); + updatePersonneRequest.setLogin(updatePersonneByIdRequest.getLogin()); + updatePersonneRequest.setRole(updatePersonneByIdRequest.getRole()); + return mergePersonne(personne, updatePersonneRequest); } @Override diff --git a/src/main/java/etunicorn/controller/RoleController.java b/src/main/java/etunicorn/controller/RoleController.java index 8750f24..9a18c64 100644 --- a/src/main/java/etunicorn/controller/RoleController.java +++ b/src/main/java/etunicorn/controller/RoleController.java @@ -14,11 +14,9 @@ import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import javax.validation.Valid; -import java.math.BigDecimal; import java.util.List; /** @@ -42,32 +40,26 @@ public class RoleController extends BaseController implements etunicorn.generate @Override @RestrictedTo("ROLE_ADD") public ResponseEntity updateRole(@Valid @RequestBody UpdateRoleRequest updateRoleRequest) { - return null; - } - public ResponseEntity updateRole(@RequestParam String nom) { - Role oldRole = roleRepository.findByNom(nom); + Role oldRole = roleRepository.findByNom(updateRoleRequest.getNom()); if (oldRole != null) { - return new ResponseEntity(HttpStatus.CONFLICT); + return generateError(HttpStatus.CONFLICT, "Un rôle avec le même nom existe déjà"); } Role role = new Role(); - role.setNom(nom); + role.setNom(updateRoleRequest.getNom()); try { roleRepository.save(role); } catch (DataIntegrityViolationException e) { - return new ResponseEntity(HttpStatus.CONFLICT); + return generateError(HttpStatus.CONFLICT, "Un rôle avec le même nom existe déjà"); } return new ResponseEntity(role, HttpStatus.CREATED); } @Override @RestrictedTo("ROLE_DELETE") - public ResponseEntity deleteRoleById(@PathVariable BigDecimal nomRole) { - return null; - } public ResponseEntity deleteRoleById(@PathVariable String nomRole) { Role role = roleRepository.findByNom(nomRole); if (role == null) { - return new ResponseEntity("Rôle inconnu", HttpStatus.NOT_FOUND); + return generateError(HttpStatus.NOT_FOUND, "Rôle introuvable"); } roleRepository.delete(role); return new ResponseEntity(HttpStatus.NO_CONTENT); @@ -75,17 +67,14 @@ public class RoleController extends BaseController implements etunicorn.generate @Override @RestrictedTo("ROLE_PERMISSION_ADD") - public ResponseEntity updateRoleById(@PathVariable BigDecimal nomRole, @Valid @RequestBody UpdateRoleByIdRequest updateRoleByIdRequest) { - return null; - } - public ResponseEntity updateRoleById(@PathVariable String nomRole, @RequestParam String nom) { + public ResponseEntity updateRoleById(@PathVariable String nomRole, @Valid @RequestBody UpdateRoleByIdRequest updateRoleByIdRequest) { Role role = roleRepository.findByNom(nomRole); if (role == null) { - return new ResponseEntity("Rôle inconnu", HttpStatus.NOT_FOUND); + return generateError(HttpStatus.NOT_FOUND, "Rôle introuvable"); } - Permission permission = permissionRepository.findByNom(nom); + Permission permission = permissionRepository.findByNom(updateRoleByIdRequest.getNom()); if (permission == null) { - return new ResponseEntity("Permission inconnue", HttpStatus.NOT_FOUND); + return generateError(HttpStatus.NOT_FOUND, "Permission introuvable"); } role.addPermission(permission); try { @@ -98,13 +87,10 @@ public class RoleController extends BaseController implements etunicorn.generate @Override @RestrictedTo("ROLE_PERMISSION_REMOVE") - public ResponseEntity deleteRoleByNomPermission(@PathVariable String nomPermission, @PathVariable BigDecimal nomRole) { - return null; - } public ResponseEntity deleteRoleByNomPermission(@PathVariable String nomPermission, @PathVariable String nomRole) { Role role = roleRepository.findByNom(nomRole); if (role == null) { - return new ResponseEntity("Rôle inconnu", HttpStatus.NOT_FOUND); + return generateError(HttpStatus.NOT_FOUND, "Rôle introuvable"); } Permission permission = permissionRepository.findByNom(nomPermission); if (permission == null) { diff --git a/src/main/java/etunicorn/generated/LoginController.java b/src/main/java/etunicorn/generated/LoginController.java index 2d6545f..a242618 100644 --- a/src/main/java/etunicorn/generated/LoginController.java +++ b/src/main/java/etunicorn/generated/LoginController.java @@ -1,15 +1,15 @@ package etunicorn.generated; -import javax.validation.Valid; import etunicorn.generated.model.UpdateLoginRequest; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; +import javax.validation.Valid; + /** * No description @@ -26,18 +26,16 @@ public interface LoginController { * */ @RequestMapping(value = "", method = RequestMethod.POST) - public ResponseEntity updateLogin( - @Valid - @RequestBody - UpdateLoginRequest updateLoginRequest); + ResponseEntity updateLogin( + @Valid + @RequestBody + UpdateLoginRequest updateLoginRequest); /** * Se déconnecter * */ - @RequestMapping(value = "/{token}", method = RequestMethod.DELETE) - public ResponseEntity deleteLoginByToken( - @PathVariable - String token); + @RequestMapping(value = "", method = RequestMethod.DELETE) + ResponseEntity deleteLogin(); } diff --git a/src/main/java/etunicorn/generated/RoleController.java b/src/main/java/etunicorn/generated/RoleController.java index aea8612..ffae33b 100644 --- a/src/main/java/etunicorn/generated/RoleController.java +++ b/src/main/java/etunicorn/generated/RoleController.java @@ -1,7 +1,6 @@ package etunicorn.generated; -import java.math.BigDecimal; import etunicorn.generated.model.UpdateRoleByIdRequest; import etunicorn.generated.model.UpdateRoleRequest; import org.springframework.http.ResponseEntity; @@ -26,55 +25,55 @@ public interface RoleController { * */ @RequestMapping(value = "", method = RequestMethod.GET) - public ResponseEntity getRole(); + ResponseEntity getRole(); /** * Ajoute un nouveau rôle. Nécessite ROLE_ADMIN * */ @RequestMapping(value = "", method = RequestMethod.POST) - public ResponseEntity updateRole( - @javax.validation.Valid - @org.springframework.web.bind.annotation.RequestBody - UpdateRoleRequest updateRoleRequest); + ResponseEntity updateRole( + @javax.validation.Valid + @org.springframework.web.bind.annotation.RequestBody + UpdateRoleRequest updateRoleRequest); /** * Supprime un rôle. Nécessite ROLE_ADMIN * */ @RequestMapping(value = "/{nomRole}", method = RequestMethod.DELETE) - public ResponseEntity deleteRoleById( - @PathVariable - BigDecimal nomRole); + ResponseEntity deleteRoleById( + @PathVariable + String nomRole); /** * Ajoute une permission à un rôle. Nécessite ROLE_ADMIN * */ @RequestMapping(value = "/{nomRole}", method = RequestMethod.POST) - public ResponseEntity updateRoleById( - @PathVariable - BigDecimal nomRole, - @javax.validation.Valid - @org.springframework.web.bind.annotation.RequestBody - UpdateRoleByIdRequest updateRoleByIdRequest); + ResponseEntity updateRoleById( + @PathVariable + String nomRole, + @javax.validation.Valid + @org.springframework.web.bind.annotation.RequestBody + UpdateRoleByIdRequest updateRoleByIdRequest); /** * Enlève la permission du rôle. Nécessite ROLE_ADMIN * */ @RequestMapping(value = "/{nomRole}/{nomPermission}", method = RequestMethod.DELETE) - public ResponseEntity deleteRoleByNomPermission( - @PathVariable - String nomPermission, - @PathVariable - BigDecimal nomRole); + ResponseEntity deleteRoleByNomPermission( + @PathVariable + String nomPermission, + @PathVariable + String nomRole); /** * Liste les permissions. Nécessite ROLE_ADMIN * */ @RequestMapping(value = "/permission", method = RequestMethod.GET) - public ResponseEntity getPermission(); + ResponseEntity getPermission(); } diff --git a/src/main/java/etunicorn/service/SessionService.java b/src/main/java/etunicorn/service/SessionService.java index d63e857..f2de8e0 100644 --- a/src/main/java/etunicorn/service/SessionService.java +++ b/src/main/java/etunicorn/service/SessionService.java @@ -53,10 +53,15 @@ public class SessionService { } } + public void deleteSession(Session session) { + sessionRepository.delete(session); + } + public Session createSession(Personne personne) { Session session = new Session(personne); sessionRepository.save(session); return session; } + } -- libgit2 0.21.2