From cc8c96de6330f9186ea271fe9e120e2fef0b5375 Mon Sep 17 00:00:00 2001 From: Thomas <> Date: Wed, 21 Apr 2021 13:49:36 +0200 Subject: add missing error-handling and add a few more tests --- .../impl/idp/auth/services/DefaultErrorService.java | 2 +- .../services/ProtocolAuthenticationService.java | 21 ++++++++++++++++----- .../controller/ProtocolFinalizationController.java | 16 +++++++++++++++- 3 files changed, 32 insertions(+), 7 deletions(-) (limited to 'eaaf_core/src/main/java/at/gv/egiz/eaaf') diff --git a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/services/DefaultErrorService.java b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/services/DefaultErrorService.java index e8be535c..e41905a6 100644 --- a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/services/DefaultErrorService.java +++ b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/services/DefaultErrorService.java @@ -20,7 +20,7 @@ import lombok.extern.slf4j.Slf4j; @Slf4j public class DefaultErrorService implements IErrorService { - private static final String TECH_LOG_MSG = "errorCode={} Message={}"; + private static final String TECH_LOG_MSG = "errorCode={0} Message={1}"; private static final String CONFIG_PROP_LOGGER_ON_INFO_LEVEL = "core.logging.level.info.errorcodes"; @Autowired IConfiguration basicConfig; diff --git a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/services/ProtocolAuthenticationService.java b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/services/ProtocolAuthenticationService.java index 4b2cbd0e..635cfa0e 100644 --- a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/services/ProtocolAuthenticationService.java +++ b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/services/ProtocolAuthenticationService.java @@ -242,10 +242,21 @@ public class ProtocolAuthenticationService implements IProtocolAuthenticationSer protocolRequest.getUniqueTransactionIdentifier()); if (ActionType.TICKET.equals(errorData.getActionType())) { - // Put pending request - final ExceptionContainer exceptionContainer = new ExceptionContainer(protocolRequest, throwable); - final byte[] serialized = SerializationUtils.serialize(exceptionContainer); - transactionStorage.put(errorData.getErrorIdTokenForRedirect(), serialized, -1); + + if (errorData.getErrorIdTokenForRedirect() != null) { + // Put pending request + final ExceptionContainer exceptionContainer = new ExceptionContainer(protocolRequest, throwable); + final byte[] serialized = SerializationUtils.serialize(exceptionContainer); + log.debug("Put error into cache to support SP forwarding ... "); + String internalErrorToken = pendingReqIdGenerationStrategy.getPendingRequestIdWithOutChecks( + errorData.getErrorIdTokenForRedirect()); + log.trace("errorIdToken: {}", internalErrorToken); + transactionStorage.put(internalErrorToken, serialized, -1); + + } else { + log.debug("No errorTokenId. Forwarding to SP will not be available"); + + } // render GUI displayException(req, resp, errorData); @@ -299,7 +310,7 @@ public class ProtocolAuthenticationService implements IProtocolAuthenticationSer final HttpServletResponse resp, final boolean writeExceptionToStatisticLog) throws EaafException, IOException { - final IErrorService.IHandleData errorData = errorTicketService.createHandleData(throwable, true); + final IErrorService.IHandleData errorData = errorTicketService.createHandleData(throwable, false); // log Exception into statistic database if (writeExceptionToStatisticLog) { diff --git a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/controller/ProtocolFinalizationController.java b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/controller/ProtocolFinalizationController.java index dce2251a..a22cbe9d 100644 --- a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/controller/ProtocolFinalizationController.java +++ b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/controller/ProtocolFinalizationController.java @@ -110,8 +110,15 @@ public class ProtocolFinalizationController extends AbstractController { } } - } + } + } else { + log.info("Find no exception with internal error-token: {}", errorId); + protAuthService + .handleErrorNoRedirect(new EaafException(IStatusMessenger.CODES_INTERNAL_ERROR_AUTH_TIMEOUT, null), + req, resp, false); + } + } catch (Throwable e) { log.error(e.getMessage(), e); protAuthService.handleErrorNoRedirect(e, req, resp, false); @@ -124,6 +131,13 @@ public class ProtocolFinalizationController extends AbstractController { } } + + } else { + log.debug("Request contains NO ErrorId"); + protAuthService + .handleErrorNoRedirect(new EaafException(IStatusMessenger.CODES_INTERNAL_ERROR_AUTH_NOPENDIGREQID, null), req, + resp, false); + } } -- cgit v1.2.3