Joaquín Reñé
2026-03-27 4ee50e257b32f6ec0f72907305d1f2b1212808a4
securis/src/main/java/net/curisit/securis/DefaultExceptionHandler.java
....@@ -67,8 +67,6 @@
6767 HttpServletRequest request;
6868 @Context
6969 SecurityContext bsc;
70
- @Context
71
- EntityManager em;
7270
7371 /**
7472 * toResponse
....@@ -81,20 +79,42 @@
8179 releaseEntityManager();
8280 if (e instanceof ForbiddenException) {
8381 LOG.warn("ForbiddenException: {}", e.toString());
84
- return Response.status(Status.UNAUTHORIZED).header(ERROR_CODE_MESSAGE_HEADER, ErrorCodes.INVALID_CREDENTIALS)
85
- .header(ERROR_MESSAGE_HEADER, "Unathorized access to the application").type(MediaType.APPLICATION_JSON).build();
82
+ return Response.status(Status.UNAUTHORIZED)
83
+ .header(ERROR_CODE_MESSAGE_HEADER, ErrorCodes.INVALID_CREDENTIALS)
84
+ .header(ERROR_MESSAGE_HEADER, "Unathorized access to the application")
85
+ .type(MediaType.APPLICATION_JSON)
86
+ .build();
8687 }
8788
8889 if (e instanceof SeCurisServiceException) {
8990 LOG.warn("SeCurisServiceException: {}", e.toString());
90
- return Response.status(DEFAULT_APP_ERROR_STATUS_CODE).header(ERROR_CODE_MESSAGE_HEADER, ((SeCurisServiceException) e).getStatus())
91
- .header(ERROR_MESSAGE_HEADER, e.getMessage()).type(MediaType.APPLICATION_JSON).build();
91
+ return Response.status(DEFAULT_APP_ERROR_STATUS_CODE)
92
+ .header(ERROR_CODE_MESSAGE_HEADER, ((SeCurisServiceException) e).getStatus())
93
+ .header(ERROR_MESSAGE_HEADER, e.getMessage())
94
+ .type(MediaType.APPLICATION_JSON)
95
+ .build();
9296 }
9397
98
+ String path = request != null ? request.getPathInfo() : null;
99
+ Object user = (bsc != null && bsc.getUserPrincipal() != null) ? bsc.getUserPrincipal() : null;
100
+ String host = request != null ? request.getRemoteHost() : null;
101
+ String ua = request != null ? request.getHeader("User-Agent") : null;
102
+ String url = request != null ? String.valueOf(request.getRequestURL()) : null;
103
+
104
+ LOG.error("Unexpected error accessing to '{}' by user: {}", path, user);
105
+ LOG.error("Request sent from {}, with User-Agent: {}", host, ua);
106
+ LOG.error("Request url: {}", url, e);
107
+
108
+ /**
94109 LOG.error("Unexpected error accesing to '{}' by user: {}", request.getPathInfo(), bsc.getUserPrincipal());
95110 LOG.error("Request sent from {}, with User-Agent: {}", request.getRemoteHost(), request.getHeader("User-Agent"));
96111 LOG.error("Request url: " + request.getRequestURL(), e);
97
- return Response.serverError().header(ERROR_MESSAGE_HEADER, "Unexpected error: " + e.toString()).type(MediaType.APPLICATION_JSON).build();
112
+ */
113
+
114
+ return Response.serverError()
115
+ .header(ERROR_MESSAGE_HEADER, "Unexpected error: " + e.toString())
116
+ .type(MediaType.APPLICATION_JSON)
117
+ .build();
98118 }
99119
100120 /**
....@@ -103,6 +123,8 @@
103123 * Best-effort cleanup: rollback active transaction (if joined) and close the {@link EntityManager}.
104124 */
105125 private void releaseEntityManager() {
126
+
127
+ /**
106128 try {
107129 if (em != null && em.isOpen()) {
108130 LOG.debug("CLOSING EM: {}, trans: {}", em, em.isJoinedToTransaction());
....@@ -116,5 +138,6 @@
116138 ex.printStackTrace();
117139 LOG.error("Error closing EM: {}, {}", em, ex);
118140 }
141
+ */
119142 }
120143 }