From 4ee50e257b32f6ec0f72907305d1f2b1212808a4 Mon Sep 17 00:00:00 2001
From: Joaquín Reñé <jrene@curisit.net>
Date: Fri, 27 Mar 2026 15:07:12 +0000
Subject: [PATCH] #4479 - upgrade SecurisServer to Java 21
---
securis/src/main/java/net/curisit/securis/DefaultExceptionHandler.java | 37 ++++++++++++++++++++++++++++++-------
1 files changed, 30 insertions(+), 7 deletions(-)
diff --git a/securis/src/main/java/net/curisit/securis/DefaultExceptionHandler.java b/securis/src/main/java/net/curisit/securis/DefaultExceptionHandler.java
index 6605752..014103d 100644
--- a/securis/src/main/java/net/curisit/securis/DefaultExceptionHandler.java
+++ b/securis/src/main/java/net/curisit/securis/DefaultExceptionHandler.java
@@ -67,8 +67,6 @@
HttpServletRequest request;
@Context
SecurityContext bsc;
- @Context
- EntityManager em;
/**
* toResponse
@@ -81,20 +79,42 @@
releaseEntityManager();
if (e instanceof ForbiddenException) {
LOG.warn("ForbiddenException: {}", e.toString());
- return Response.status(Status.UNAUTHORIZED).header(ERROR_CODE_MESSAGE_HEADER, ErrorCodes.INVALID_CREDENTIALS)
- .header(ERROR_MESSAGE_HEADER, "Unathorized access to the application").type(MediaType.APPLICATION_JSON).build();
+ return Response.status(Status.UNAUTHORIZED)
+ .header(ERROR_CODE_MESSAGE_HEADER, ErrorCodes.INVALID_CREDENTIALS)
+ .header(ERROR_MESSAGE_HEADER, "Unathorized access to the application")
+ .type(MediaType.APPLICATION_JSON)
+ .build();
}
if (e instanceof SeCurisServiceException) {
LOG.warn("SeCurisServiceException: {}", e.toString());
- return Response.status(DEFAULT_APP_ERROR_STATUS_CODE).header(ERROR_CODE_MESSAGE_HEADER, ((SeCurisServiceException) e).getStatus())
- .header(ERROR_MESSAGE_HEADER, e.getMessage()).type(MediaType.APPLICATION_JSON).build();
+ return Response.status(DEFAULT_APP_ERROR_STATUS_CODE)
+ .header(ERROR_CODE_MESSAGE_HEADER, ((SeCurisServiceException) e).getStatus())
+ .header(ERROR_MESSAGE_HEADER, e.getMessage())
+ .type(MediaType.APPLICATION_JSON)
+ .build();
}
+ String path = request != null ? request.getPathInfo() : null;
+ Object user = (bsc != null && bsc.getUserPrincipal() != null) ? bsc.getUserPrincipal() : null;
+ String host = request != null ? request.getRemoteHost() : null;
+ String ua = request != null ? request.getHeader("User-Agent") : null;
+ String url = request != null ? String.valueOf(request.getRequestURL()) : null;
+
+ LOG.error("Unexpected error accessing to '{}' by user: {}", path, user);
+ LOG.error("Request sent from {}, with User-Agent: {}", host, ua);
+ LOG.error("Request url: {}", url, e);
+
+ /**
LOG.error("Unexpected error accesing to '{}' by user: {}", request.getPathInfo(), bsc.getUserPrincipal());
LOG.error("Request sent from {}, with User-Agent: {}", request.getRemoteHost(), request.getHeader("User-Agent"));
LOG.error("Request url: " + request.getRequestURL(), e);
- return Response.serverError().header(ERROR_MESSAGE_HEADER, "Unexpected error: " + e.toString()).type(MediaType.APPLICATION_JSON).build();
+ */
+
+ return Response.serverError()
+ .header(ERROR_MESSAGE_HEADER, "Unexpected error: " + e.toString())
+ .type(MediaType.APPLICATION_JSON)
+ .build();
}
/**
@@ -103,6 +123,8 @@
* Best-effort cleanup: rollback active transaction (if joined) and close the {@link EntityManager}.
*/
private void releaseEntityManager() {
+
+ /**
try {
if (em != null && em.isOpen()) {
LOG.debug("CLOSING EM: {}, trans: {}", em, em.isJoinedToTransaction());
@@ -116,5 +138,6 @@
ex.printStackTrace();
LOG.error("Error closing EM: {}, {}", em, ex);
}
+ */
}
}
--
Gitblit v1.3.2