From 0d827d781679187d4a73e7b51510539a69a46d79 Mon Sep 17 00:00:00 2001 From: Thomas Lenz Date: Thu, 18 Feb 2016 19:22:52 +0100 Subject: fix error handling: always make a redirect to MOA-ID in case of error --- .../moa/id/auth/servlet/AbstractController.java | 45 +++++++++------------- 1 file changed, 18 insertions(+), 27 deletions(-) (limited to 'id/server/idserverlib/src') diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/auth/servlet/AbstractController.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/auth/servlet/AbstractController.java index acff2e40e..8c0708fd5 100644 --- a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/auth/servlet/AbstractController.java +++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/auth/servlet/AbstractController.java @@ -126,42 +126,33 @@ public abstract class AbstractController extends MOAIDAuthConstants { loggedException = exceptionThrown; try { - //switch to protocol-finalize method to generate a protocol-specific error message - if (MiscUtil.isNotEmpty(pendingRequestID)) { + //switch to protocol-finalize method to generate a protocol-specific error message + + //put exception into transaction store for redirect + String key = Random.nextRandom(); + transactionStorage.put(key, loggedException); - //put exception into transaction store for redirect - String key = Random.nextRandom(); - transactionStorage.put(key, loggedException); - - //build up redirect URL - String redirectURL = null; - redirectURL = ServletUtils.getBaseUrl(req); - redirectURL += "/"+AbstractAuthProtocolModulController.FINALIZEPROTOCOL_ENDPOINT - + "?" + ERROR_CODE_PARAM + "=" + key - + "&" + MOAIDAuthConstants.PARAM_TARGET_PENDINGREQUESTID + "=" + pendingRequestID; + //build up redirect URL + String redirectURL = null; + redirectURL = ServletUtils.getBaseUrl(req); + redirectURL += "/"+AbstractAuthProtocolModulController.FINALIZEPROTOCOL_ENDPOINT + + "?" + ERROR_CODE_PARAM + "=" + key + + "&" + MOAIDAuthConstants.PARAM_TARGET_PENDINGREQUESTID + "=" + pendingRequestID; - resp.setContentType("text/html"); - resp.setStatus(302); + resp.setContentType("text/html"); + resp.setStatus(302); - resp.addHeader("Location", redirectURL); - Logger.debug("REDIRECT TO: " + redirectURL); + resp.addHeader("Location", redirectURL); + Logger.debug("REDIRECT TO: " + redirectURL); - return; - - } else { - //write exception into browser window, because protocol-specific error message - // is not possible without pendingRequest - handleErrorNoRedirect(loggedException, req, resp, true); - - } - + return; + } catch (MOADatabaseException e) { Logger.warn("Exception can not be stored to Database.", e); handleErrorNoRedirect(loggedException, req, resp, true); } - - + } /** -- cgit v1.2.3