package at.gv.egiz.eaaf.core.impl.idp.auth.services; import java.util.Map; import javax.annotation.Nonnull; import javax.annotation.Nullable; import at.gv.egiz.eaaf.core.api.IRequest; import at.gv.egiz.eaaf.core.api.gui.ModifyableGuiBuilderConfiguration; import at.gv.egiz.eaaf.core.exceptions.EaafException; import jakarta.servlet.http.HttpServletRequest; public interface IErrorService { /** * Describes the kind of action that should be taken. */ enum ActionType { TICKET("ticket"), NO_TICKET("no_ticket"), ERRORPAGE("errorpage"); private final String name; ActionType(final String text) { 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"; /** * Maps internal error codes to external ones. * @param internalCode internal error code * @return external error code */ @Nonnull String getExternalCodeFromInternal(@Nonnull String internalCode); /** * Creates error handling data. * *

* Redirect to Service-Provider is supported in case of an available * pendingRequest. *

* * @param throwable Error that should be handled * @param protocolRequest Current pendingRequest if available * @return Information how the error should be handled * @throws EaafException In case of an internal error */ @Nonnull IHandleData createHandleData(@Nonnull Throwable throwable, @Nullable IRequest protocolRequest) 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(@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. * * @return The appropriate action */ ActionType getActionType(); /** * Get internal errorCode describing the problem. * * @return internal error Code. */ String getInternalErrorCode(); /** * Get the original throwable of the error. * * @return causing throwable */ Throwable getThrowable(); /** * 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 */ String getPreFormatedErrorMessage(); /** * Get additional elements for error GUI model. * * @return Map of GUI model elements. */ Map getAdditionalGuiModelElements(); } }