diff options
author | Thomas <> | 2024-08-09 15:32:36 +0200 |
---|---|---|
committer | Thomas <> | 2024-08-09 15:32:36 +0200 |
commit | da1f3a2ce05f713a4c2e5cea0efd2f1de31392ea (patch) | |
tree | b2180f78b214cc9f5e9514dca66e4d6e4ff27709 | |
parent | d140efeaa939a6dff3182cdfd5f4f7ca87a6b5b1 (diff) | |
download | EAAF-Components-da1f3a2ce05f713a4c2e5cea0efd2f1de31392ea.tar.gz EAAF-Components-da1f3a2ce05f713a4c2e5cea0efd2f1de31392ea.tar.bz2 EAAF-Components-da1f3a2ce05f713a4c2e5cea0efd2f1de31392ea.zip |
feat(core): add extension point to customize error-responses in centrial error handling
-rw-r--r-- | eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/services/ProtocolAuthenticationService.java | 33 |
1 files changed, 27 insertions, 6 deletions
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 4ec9f028..7ed23619 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 @@ -504,6 +504,26 @@ public class ProtocolAuthenticationService implements IProtocolAuthenticationSer } + /** + * Extension point to customize error-response generation. + * + * @param httpReq Current HTTP request + * @param httpResp Current HTTP response + * @param msg Error message from exception + * @param errorCode internal error-code + * @param params Parameters for internal error-code + * @param externalErrorCode external error-code + * @param errorData full error-data object from central error-handling + * @throws EaafException In case of response-generation error + */ + protected void writeErrorResponse(@NonNull final HttpServletRequest httpReq, + @NonNull final HttpServletResponse httpResp, @NonNull final String msg, @NonNull final String errorCode, + @Nullable final Object[] params, String externalErrorCode, IErrorService.IHandleData errorData) + throws EaafException { + writeHtmlErrorResponse(httpReq, httpResp, msg, errorCode, params, externalErrorCode, errorData); + + } + // private void writeHtmlErrorResponse(@NonNull final HttpServletRequest // httpReq, // @NonNull final HttpServletResponse httpResp, @NonNull final String msg, @@ -578,6 +598,7 @@ public class ProtocolAuthenticationService implements IProtocolAuthenticationSer final IErrorService.IHandleData errorData) throws IOException, EaafException { final Throwable e = errorData.getThrowable(); final String internalErrorCode = errorData.getInternalErrorCode(); + String externalErrorCode = errorTicketService.getExternalCodeFromInternal(internalErrorCode); // send error response if (e instanceof ProtocolNotActiveException) { @@ -589,20 +610,20 @@ public class ProtocolAuthenticationService implements IProtocolAuthenticationSer } else if (e instanceof AuthnRequestValidatorException || e instanceof InvalidProtocolRequestException || e instanceof ProcessExecutionException || e instanceof ConfigurationException) { // write error message - writeHtmlErrorResponse(req, resp, e.getMessage(), internalErrorCode, + writeErrorResponse(req, resp, e.getMessage(), internalErrorCode, e instanceof EaafException ? ((EaafException) e).getParams() : null, - errorTicketService.getExternalCodeFromInternal(internalErrorCode), errorData); + externalErrorCode, errorData); } else if (e instanceof EaafException) { // send HTML formated error message - writeHtmlErrorResponse(req, resp, e.getMessage(), internalErrorCode, ((EaafException) e).getParams(), - errorTicketService.getExternalCodeFromInternal(internalErrorCode), errorData); + writeErrorResponse(req, resp, e.getMessage(), internalErrorCode, ((EaafException) e).getParams(), + externalErrorCode, errorData); } else { // write generic message for general exceptions final String msg = statusMessager.getMessage(IStatusMessenger.CODES_INTERNAL_ERROR_GENERIC, null); - writeHtmlErrorResponse(req, resp, msg, internalErrorCode, null, - errorTicketService.getExternalCodeFromInternal(internalErrorCode), errorData); + writeErrorResponse(req, resp, msg, internalErrorCode, null, + externalErrorCode, errorData); } } |