From 3cbba3fcda614fa37357822d0eeb543c3e19276e Mon Sep 17 00:00:00 2001 From: Thomas <> Date: Wed, 21 Apr 2021 07:42:50 +0200 Subject: some small updates in central error-handling --- .../core/impl/idp/auth/services/IErrorService.java | 104 +++++++++++++++++---- 1 file changed, 86 insertions(+), 18 deletions(-) (limited to 'eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/services/IErrorService.java') 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 4e04a87f..e545cb47 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 @@ -1,7 +1,5 @@ package at.gv.egiz.eaaf.core.impl.idp.auth.services; -import java.util.HashSet; - import javax.annotation.Nonnull; import javax.servlet.http.HttpServletRequest; @@ -9,13 +7,12 @@ import at.gv.egiz.eaaf.core.api.gui.ModifyableGuiBuilderConfiguration; import at.gv.egiz.eaaf.core.exceptions.EaafException; public interface IErrorService { + /** * Describes the kind of action that should be taken. */ enum ActionType { - TICKET_REDIRECT("ticket_redirect"), TICKET_NOREDIRECT("ticket_noredirect"), NOTICKET_REDIRECT( - "noticket_redirect"), NOTICKET_NOREDIRECT("noticket_noredirect"), NOTICKET_AUTOREDIRECT( - "noticket_autoredirect"); + TICKET("ticket"), NO_TICKET("no_ticket"); private final String name; @@ -23,12 +20,66 @@ public interface IErrorService { this.name = text; } + + /** + * Get flow type for error-handling from String representation. + * + * @param s Config parameter + * @return Error-handling flow + */ + public static ActionType fromString(final String s) { + try { + return ActionType.valueOf(s.toUpperCase()); + + } catch (IllegalArgumentException | NullPointerException e) { + return null; + + } + } + @Override public String toString() { return name; } } + /** + * Defines the LogLevel for this types of errors. + */ + enum LogLevel { + ERROR("error"), WARN("warn"), INFO("info"), DEBUG("debug"); + + private final String level; + + LogLevel(final String logLevel) { + this.level = logLevel; + + } + + + /** + * Get the log-level from String representation. + * + * @param s Config parameter + * @return Log-Level from configuration or ERROR as backup + */ + public static LogLevel fromString(final String s) { + try { + return LogLevel.valueOf(s.toUpperCase()); + + } catch (IllegalArgumentException | NullPointerException e) { + return LogLevel.ERROR; + + } + } + + @Override + public String toString() { + return level; + } + + } + String PARAM_GUI_TICKET = "supportTicket"; String PARAM_GUI_REDIRECT = "redirectLink"; @@ -38,33 +89,43 @@ public interface IErrorService { * @return external error code */ @Nonnull - String getExternalCodeFromInternal(String internalCode); + String getExternalCodeFromInternal(@Nonnull String internalCode); /** - * creates error handling data. + * Creates error handling data. * - * @param throwable error - * @param req http request - * @return eror handle Data + * @param throwable Error that should be handled + * @param supportRedirctToSp true if the current process-state supports redirect + * to Service-Provider, otherwise false + * @return Information how the error should be handled * @throws EaafException In case of an internal error */ @Nonnull - IHandleData createHandleData(Throwable throwable, HttpServletRequest req) throws EaafException; + IHandleData createHandleData(@Nonnull Throwable throwable, boolean supportRedirctToSp) throws EaafException; /** * Displays the error using suitable errordata. * * @param c guibuilder * @param errorData Data to handle + * @param httpReq Current HTTP request * @throws EaafException In case of an internal error */ - void displayErrorData(ModifyableGuiBuilderConfiguration c, IErrorService.IHandleData errorData) - throws EaafException; + void displayErrorData(@Nonnull ModifyableGuiBuilderConfiguration c, @Nonnull IErrorService.IHandleData errorData, + @Nonnull HttpServletRequest httpReq) throws EaafException; /** * Contains all the Model data for Error Handling. */ interface IHandleData { + + /** + * Get a new pendingReqId that can be used to store the error for SP forwarding. + * + * @return errorToken as pendingRequest + */ + String getErrorIdTokenForRedirect(); + /** * Describes the kind of action that should be taken. * @@ -85,12 +146,19 @@ public interface IErrorService { * @return causing throwable */ Throwable getThrowable(); - + /** - * Write a Exception to the MOA-ID-Auth internal technical log. - * - * @param logOnInfoLevel set of what to log on info logging lvl + * Get the log-level for this internal errorId. + * + * @return Level to Log the error + */ + LogLevel getLogLevel(); + + /** + * Get pre-formated text for log message. + * + * @return log message */ - void logExceptionToTechnicalLog(HashSet logOnInfoLevel); + String getPreFormatedErrorMessage(); } } -- cgit v1.2.3