| .. | .. |
|---|
| 17 | 17 | |
|---|
| 18 | 18 | @Provider |
|---|
| 19 | 19 | 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); |
|---|
| 21 | 21 | |
|---|
| 22 | | - public static final String ERROR_MESSAGE_HEADER = "X-SECURIS-ERROR"; |
|---|
| 22 | + public static final String ERROR_MESSAGE_HEADER = "X-SECURIS-ERROR"; |
|---|
| 23 | 23 | |
|---|
| 24 | | - public DefaultExceptionHandler() { |
|---|
| 25 | | - LOG.info("Creating DefaultExceptionHandler "); |
|---|
| 26 | | - } |
|---|
| 24 | + public DefaultExceptionHandler() { |
|---|
| 25 | + LOG.info("Creating DefaultExceptionHandler "); |
|---|
| 26 | + } |
|---|
| 27 | 27 | |
|---|
| 28 | | - @Context |
|---|
| 29 | | - HttpServletRequest request; |
|---|
| 30 | | - @Context |
|---|
| 31 | | - SecurityContext bsc; |
|---|
| 28 | + @Context |
|---|
| 29 | + HttpServletRequest request; |
|---|
| 30 | + @Context |
|---|
| 31 | + SecurityContext bsc; |
|---|
| 32 | 32 | |
|---|
| 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 | + } |
|---|
| 39 | 40 | |
|---|
| 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 | + } |
|---|
| 44 | 46 | |
|---|
| 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 | + } |
|---|
| 50 | 52 | } |
|---|