From a3088068b6d3f6d6719ca5943eec556d01c0655d Mon Sep 17 00:00:00 2001 From: Thomas <> Date: Thu, 1 Jul 2021 07:37:47 +0200 Subject: add new 'errorHandling' type that illustrate any error on application side before forwarding to SP --- .../core/impl/idp/auth/services/IErrorService.java | 2 +- .../services/ProtocolAuthenticationService.java | 3 +- .../ProtocolFinalizationControllerTest.java | 57 +++++++++++++++++++++- 3 files changed, 59 insertions(+), 3 deletions(-) diff --git a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/services/IErrorService.java b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/services/IErrorService.java index e545cb47..b6bc1056 100644 --- a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/services/IErrorService.java +++ b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/services/IErrorService.java @@ -12,7 +12,7 @@ public interface IErrorService { * Describes the kind of action that should be taken. */ enum ActionType { - TICKET("ticket"), NO_TICKET("no_ticket"); + TICKET("ticket"), NO_TICKET("no_ticket"), ERRORPAGE("errorpage"); private final String name; 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 635cfa0e..49acfadc 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 @@ -241,7 +241,8 @@ public class ProtocolAuthenticationService implements IProtocolAuthenticationSer revisionsLogger.logEvent(protocolRequest, EventConstants.TRANSACTION_ERROR, protocolRequest.getUniqueTransactionIdentifier()); - if (ActionType.TICKET.equals(errorData.getActionType())) { + if (ActionType.TICKET.equals(errorData.getActionType()) + || ActionType.ERRORPAGE.equals(errorData.getActionType())) { if (errorData.getErrorIdTokenForRedirect() != null) { // Put pending request diff --git a/eaaf_core/src/test/java/at/gv/egiz/eaaf/core/impl/idp/auth/controller/ProtocolFinalizationControllerTest.java b/eaaf_core/src/test/java/at/gv/egiz/eaaf/core/impl/idp/auth/controller/ProtocolFinalizationControllerTest.java index 8aa3e8a9..4341d141 100644 --- a/eaaf_core/src/test/java/at/gv/egiz/eaaf/core/impl/idp/auth/controller/ProtocolFinalizationControllerTest.java +++ b/eaaf_core/src/test/java/at/gv/egiz/eaaf/core/impl/idp/auth/controller/ProtocolFinalizationControllerTest.java @@ -254,7 +254,62 @@ public class ProtocolFinalizationControllerTest { } - + @Test + public void performErrorHandlingWithoutTokenAndRedirect() throws EaafException, IOException { + MockHttpServletRequest httpReq = new MockHttpServletRequest("POST", "https://localhost/authhandler"); + httpReq.addHeader("Accept", "application/json"); + MockHttpServletResponse httpResp = new MockHttpServletResponse(); + guiConfigFactory.setErrorGuiConfig( + new DummyGuiBuilderConfig("https://localhost/authhandler", "jUnitView", "/junitSubmit")); + + String token = requestIdValidationStragegy.generateExternalPendingRequestId(); + httpReq.setParameter(EaafConstants.PARAM_HTTP_ERROR_CODE, token); + + TestRequestImpl protocolRequest = new TestRequestImpl(); + Map spConfig = new HashMap<>(); + spConfig.put(EaafConfigConstants.SERVICE_UNIQUEIDENTIFIER, RandomStringUtils.randomAlphabetic(10)); + + protocolRequest.setSpConfig(new DummySpConfiguration(spConfig, config)); + protocolRequest.setTransactionId(RandomStringUtils.randomAlphanumeric(10)); + + Throwable throwable = new EaafException("internal.00"); + final ExceptionContainer exceptionContainer = new ExceptionContainer(protocolRequest, throwable); + final byte[] serialized = SerializationUtils.serialize(exceptionContainer); + storage.put(token, serialized, -1); + + String secondErrorTicket = requestIdValidationStragegy.generateExternalPendingRequestId(); + errorService.setErrorIdTokenForRedirect(secondErrorTicket); + errorService.setTicketType(ActionType.ERRORPAGE); + + // perform test + controller.errorHandling(httpReq, httpResp); + + //validate state + assertNull("Exception not removed from cache", storage.get( + requestIdValidationStragegy.getPendingRequestIdWithOutChecks(token))); + + assertNotNull("No gui builder request", guiBuilder.getConfig()); + assertFalse("No GUI form infos", guiBuilder.getConfig().getViewParameters().isEmpty()); + assertTrue("No GUI form infos", guiBuilder.getConfig().getViewParameters().containsKey("msg")); + Map params = ((Map) guiBuilder.getConfig().getViewParameters().get("msg")); + assertFalse("No GUI form infos", params.isEmpty()); + assertEquals("wrong intErrorCode", "internal.00", params.get("errorCode")); + assertTrue("wrong extErrorCode", ((String) params.get("extErrorCode")).contains("internal.00")); + + byte[] secondErrorSerialized = storage.get( + requestIdValidationStragegy.getPendingRequestIdWithOutChecks(secondErrorTicket), byte[].class); + assertNotNull("Exception not removed from cache", secondErrorSerialized); + ExceptionContainer secondError = (ExceptionContainer) SerializationUtils.deserialize(secondErrorSerialized); + assertEquals("wrong pengingReq", protocolRequest.getUniqueTransactionIdentifier(), + secondError.getPendingRequest().getUniqueTransactionIdentifier()); + assertEquals("wrong exception", throwable.getMessage(), secondError.getExceptionThrown().getMessage()); + + assertTrue("GUI sp redirect", guiBuilder.getConfig().getViewParameters() + .containsKey(DummyDefaultErrorService.JUNIT_EL_SPREDIRECT)); + + } + + private class DummyGuiBuilderConfig extends AbstractGuiFormBuilderConfiguration implements ModifyableGuiBuilderConfiguration { -- cgit v1.2.3