Roberto Sánchez
2014-09-19 8d5386be38db25a2a41c3bf6c876adee21ca26cc
securis/src/main/java/net/curisit/securis/DefaultExceptionHandler.java
....@@ -17,34 +17,36 @@
1717
1818 @Provider
1919 public class DefaultExceptionHandler implements ExceptionMapper<Exception> {
20
- private static final Logger LOG = LogManager.getLogger(DefaultExceptionHandler.class);
20
+ private static final Logger LOG = LogManager.getLogger(DefaultExceptionHandler.class);
2121
22
- public static final String ERROR_MESSAGE_HEADER = "X-SECURIS-ERROR";
22
+ public static final String ERROR_MESSAGE_HEADER = "X-SECURIS-ERROR";
2323
24
- public DefaultExceptionHandler() {
25
- LOG.info("Creating DefaultExceptionHandler ");
26
- }
24
+ public DefaultExceptionHandler() {
25
+ LOG.info("Creating DefaultExceptionHandler ");
26
+ }
2727
28
- @Context
29
- HttpServletRequest request;
30
- @Context
31
- SecurityContext bsc;
28
+ @Context
29
+ HttpServletRequest request;
30
+ @Context
31
+ SecurityContext bsc;
3232
33
- @Override
34
- public Response toResponse(Exception e) {
35
- if (e instanceof ForbiddenException) {
36
- LOG.warn("Unauthorized access to {}, user: {}", request.getPathInfo(), bsc.getUserPrincipal());
37
- return Response.status(Status.UNAUTHORIZED).header(ERROR_MESSAGE_HEADER, "Unathorized access to the application").type(MediaType.APPLICATION_JSON).build();
38
- }
33
+ @Override
34
+ public Response toResponse(Exception e) {
35
+ if (e instanceof ForbiddenException) {
36
+ LOG.warn("Unauthorized access to {}, user: {}", request.getPathInfo(), bsc.getUserPrincipal());
37
+ return Response.status(Status.UNAUTHORIZED).header(ERROR_MESSAGE_HEADER, "Unathorized access to the application")
38
+ .type(MediaType.APPLICATION_JSON).build();
39
+ }
3940
40
- if (e instanceof SeCurisServiceException) {
41
- LOG.warn("SeCurisServiceException accessing to {}, user: {}", request.getPathInfo(), bsc.getUserPrincipal());
42
- return Response.status(Status.fromStatusCode(((SeCurisServiceException) e).getStatus())).header(ERROR_MESSAGE_HEADER, e.getMessage()).type(MediaType.APPLICATION_JSON).build();
43
- }
41
+ if (e instanceof SeCurisServiceException) {
42
+ LOG.warn("SeCurisServiceException accessing to {}, user: {}", request.getPathInfo(), bsc.getUserPrincipal());
43
+ return Response.status(Status.fromStatusCode(((SeCurisServiceException) e).getStatus())).header(ERROR_MESSAGE_HEADER, e.getMessage())
44
+ .type(MediaType.APPLICATION_JSON).build();
45
+ }
4446
45
- LOG.error("Unexpected error accesing to '{}' by user: {}", request.getPathInfo(), bsc.getUserPrincipal());
46
- LOG.error("Request sent from {}, with User-Agent: {}", request.getRemoteHost(), request.getHeader("User-Agent"));
47
- LOG.error("Request url: " + request.getRequestURL(), e);
48
- return Response.serverError().header(ERROR_MESSAGE_HEADER, "Unexpected error: " + e.toString()).type(MediaType.APPLICATION_JSON).build();
49
- }
47
+ LOG.error("Unexpected error accesing to '{}' by user: {}", request.getPathInfo(), bsc.getUserPrincipal());
48
+ LOG.error("Request sent from {}, with User-Agent: {}", request.getRemoteHost(), request.getHeader("User-Agent"));
49
+ LOG.error("Request url: " + request.getRequestURL(), e);
50
+ return Response.serverError().header(ERROR_MESSAGE_HEADER, "Unexpected error: " + e.toString()).type(MediaType.APPLICATION_JSON).build();
51
+ }
5052 }