summaryrefslogtreecommitdiff
path: root/eaaf_core/src/main
diff options
context:
space:
mode:
authorThomas <>2021-04-16 15:13:37 +0200
committerThomas <>2021-04-16 15:13:37 +0200
commitaf378b443868a0fecc5176a263dbd42718424d14 (patch)
treebefa161d2e34e0a864a0f91c69e9c780318d3dd7 /eaaf_core/src/main
parentb8b5f661b4b16f2ae82e9a63bf1e2d9279e1dcbc (diff)
parent4a418d3a55752850891dbb9a6b10d03728a27520 (diff)
downloadEAAF-Components-af378b443868a0fecc5176a263dbd42718424d14.tar.gz
EAAF-Components-af378b443868a0fecc5176a263dbd42718424d14.tar.bz2
EAAF-Components-af378b443868a0fecc5176a263dbd42718424d14.zip
Merge branch 'feature/VT-21-016' of gitlab.iaik.tugraz.at:egiz/eaaf_components into feature/VT-21-016
# Conflicts: # eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/services/ProtocolAuthenticationService.java # eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/controller/ProtocolFinalizationController.java
Diffstat (limited to 'eaaf_core/src/main')
-rw-r--r--eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/services/ErrorTicketService.java34
-rw-r--r--eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/services/IErrorService.java92
-rw-r--r--eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/services/ProtocolAuthenticationService.java128
-rw-r--r--eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/controller/ProtocolFinalizationController.java4
4 files changed, 154 insertions, 104 deletions
diff --git a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/services/ErrorTicketService.java b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/services/ErrorTicketService.java
index 08fb04c6..0834aa27 100644
--- a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/services/ErrorTicketService.java
+++ b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/services/ErrorTicketService.java
@@ -1,14 +1,13 @@
package at.gv.egiz.eaaf.core.impl.idp.auth.services;
-import at.gv.egiz.eaaf.core.api.IStatusMessenger;
-import at.gv.egiz.eaaf.core.api.data.EaafConstants;
-import at.gv.egiz.eaaf.core.api.idp.IConfiguration;
-import at.gv.egiz.eaaf.core.exceptions.EaafException;
-import at.gv.egiz.eaaf.core.exceptions.TaskExecutionException;
-import at.gv.egiz.eaaf.core.impl.idp.controller.ProtocolFinalizationController;
-import at.gv.egiz.eaaf.core.impl.utils.FileUtils;
-import at.gv.egiz.eaaf.core.impl.utils.ServletUtils;
-import lombok.Getter;
+import java.io.InputStream;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
+import javax.annotation.PostConstruct;
+import javax.servlet.http.HttpServletRequest;
+
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.text.StringEscapeUtils;
@@ -19,12 +18,15 @@ import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
import org.springframework.stereotype.Service;
-import javax.annotation.PostConstruct;
-import javax.servlet.http.HttpServletRequest;
-import java.io.InputStream;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Properties;
+import at.gv.egiz.eaaf.core.api.IStatusMessenger;
+import at.gv.egiz.eaaf.core.api.data.EaafConstants;
+import at.gv.egiz.eaaf.core.api.idp.IConfiguration;
+import at.gv.egiz.eaaf.core.exceptions.EaafException;
+import at.gv.egiz.eaaf.core.exceptions.TaskExecutionException;
+import at.gv.egiz.eaaf.core.impl.idp.controller.ProtocolFinalizationController;
+import at.gv.egiz.eaaf.core.impl.utils.FileUtils;
+import at.gv.egiz.eaaf.core.impl.utils.ServletUtils;
+import lombok.Getter;
@Service()
public class ErrorTicketService {
@@ -187,7 +189,7 @@ public class ErrorTicketService {
private void generateRedirect() {
redirectUrl = ServletUtils.getBaseUrl(req);
redirectUrl +=
- "/" + ProtocolFinalizationController.ENDPOINT_ERROR_REDIRECT + "?" + EaafConstants.PARAM_HTTP_ERROR_CODE + "="
+ ProtocolFinalizationController.ENDPOINT_ERROR_REDIRECT + "?" + EaafConstants.PARAM_HTTP_ERROR_CODE + "="
+ StringEscapeUtils.escapeHtml4(req.getParameter(EaafConstants.PARAM_HTTP_ERROR_CODE));
}
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
new file mode 100644
index 00000000..812a5171
--- /dev/null
+++ b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/services/IErrorService.java
@@ -0,0 +1,92 @@
+package at.gv.egiz.eaaf.core.impl.idp.auth.services;
+
+import at.gv.egiz.eaaf.core.api.gui.ModifyableGuiBuilderConfiguration;
+import at.gv.egiz.eaaf.core.exceptions.EaafException;
+
+import javax.servlet.http.HttpServletRequest;
+import java.util.HashSet;
+
+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");
+
+ private final String name;
+
+ ActionType(final String text) {
+ this.name = text;
+ }
+
+ @Override
+ public String toString() {
+ return name;
+ }
+ }
+
+ 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
+ */
+ String getExternalCodeFromInternal(String internalCode);
+
+ /**
+ * creates error handling data.
+ *
+ * @param throwable error
+ * @param req http request
+ * @return eror handle Data
+ * @throws EaafException In case of an internal error
+ */
+ IHandleData createHandleData(Throwable throwable, HttpServletRequest req) throws EaafException;
+
+ /**
+ * Displays the error using suitable errordata.
+ *
+ * @param c guibuilder
+ * @param errorData Data to handle
+ * @throws EaafException In case of an internal error
+ */
+ void displayErrorData(ModifyableGuiBuilderConfiguration c, IErrorService.IHandleData errorData)
+ throws EaafException;
+
+ /**
+ * Contains all the Model data for Error Handling.
+ */
+ interface IHandleData {
+ /**
+ * 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();
+
+ /**
+ * Write a Exception to the MOA-ID-Auth internal technical log.
+ *
+ * @param logOnInfoLevel set of what to log on info logging lvl
+ */
+ void logExceptionToTechnicalLog(HashSet<String> logOnInfoLevel);
+ }
+}
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 ac2be693..a64ad45e 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
@@ -82,6 +82,7 @@ import at.gv.egiz.eaaf.core.impl.utils.ServletUtils;
+
@Service
public class ProtocolAuthenticationService implements IProtocolAuthenticationService {
private static final Logger log = LoggerFactory.getLogger(ProtocolAuthenticationService.class);
@@ -106,12 +107,14 @@ public class ProtocolAuthenticationService implements IProtocolAuthenticationSer
private IConfiguration basicConfig;
@Autowired(required = true)
- private ErrorTicketService errorTicketService;
+ private IErrorService errorTicketService;
@Autowired(required = false)
private ISsoManager ssoManager;
+
@Autowired
private IStatisticLogger statisticLogger;
+
@Autowired
private IRevisionLogger revisionsLogger;
@@ -235,10 +238,10 @@ public class ProtocolAuthenticationService implements IProtocolAuthenticationSer
public void buildProtocolSpecificErrorResponse(final Throwable throwable, final HttpServletRequest req,
final HttpServletResponse resp, final IRequest protocolRequest) throws EaafException, IOException {
try {
- ErrorTicketService.HandleData errorData = errorTicketService.createHandleData(throwable, req);
-
- if (errorData.getActionType().equals(ErrorTicketService.ActionType.TICKET_REDIRECT)
- || errorData.getActionType().equals(ErrorTicketService.ActionType.NOTICKET_REDIRECT)) {
+ IErrorService.IHandleData errorData = errorTicketService.createHandleData(throwable, req);
+
+ if (errorData.getActionType().equals(IErrorService.ActionType.TICKET_REDIRECT) || errorData.getActionType()
+ .equals(IErrorService.ActionType.NOTICKET_REDIRECT)) {
// Put pending request
ExceptionContainer exceptionContainer = new ExceptionContainer(protocolRequest, throwable);
@@ -248,22 +251,21 @@ public class ProtocolAuthenticationService implements IProtocolAuthenticationSer
.validateAndGetPendingRequestId(req.getParameter(EaafConstants.PARAM_HTTP_ERROR_CODE));
transactionStorage.put(errorId, serialized, -1);
-
// log Error to technical log
- logExceptionToTechnicalLog(errorData);
+ errorData.logExceptionToTechnicalLog(logOnInfoLevel);
// log Error Message
statisticLogger.logErrorOperation(throwable, protocolRequest);
displayException(req, resp, errorData);
- } else if (errorData.getActionType().equals(ErrorTicketService.ActionType.NOTICKET_AUTOREDIRECT)) {
+ } else if (errorData.getActionType().equals(IErrorService.ActionType.NOTICKET_AUTOREDIRECT)) {
IModulInfo handlingModule = extractShibbolethHandling(protocolRequest, applicationContext);
if (handlingModule.generateErrorMessage(throwable, req, resp, protocolRequest)) {
// log Error to technical log
- logExceptionToTechnicalLog(errorData);
+ errorData.logExceptionToTechnicalLog(logOnInfoLevel);
// log Error Message
statisticLogger.logErrorOperation(throwable, protocolRequest);
@@ -285,7 +287,6 @@ public class ProtocolAuthenticationService implements IProtocolAuthenticationSer
} catch (final Throwable e) {
// if building error response results in error, we try with with handleErrorNoRedirect
handleErrorNoRedirect(e, req, resp, true);
-
}
}
@@ -307,52 +308,38 @@ public class ProtocolAuthenticationService implements IProtocolAuthenticationSer
"Requested protocol module Class is NULL or does not implement the IModulInfo interface.");
}
-
+
return (IModulInfo) applicationContext.getBean(clazz);
}
+
@Override
public void handleErrorNoRedirect(final Throwable throwable, final HttpServletRequest req,
- final HttpServletResponse resp, final boolean writeExceptionToStatisticLog) {
- handleErrorNoRedirect(throwable, req, resp, writeExceptionToStatisticLog, false);
- }
+ final HttpServletResponse resp, final boolean writeExceptionToStatisticLog) throws EaafException, IOException {
- private void handleErrorNoRedirect(final Throwable throwable, final HttpServletRequest req,
- final HttpServletResponse resp, final boolean writeExceptionToStatisticLog, final boolean recall) {
- ErrorTicketService.HandleData errorData = null;
- try {
- errorData = errorTicketService.createHandleData(throwable, req);
+ IErrorService.IHandleData errorData = null;
+ errorData = errorTicketService.createHandleData(throwable, req);
- // log Exception into statistic database
- if (writeExceptionToStatisticLog) {
- statisticLogger.logErrorOperation(throwable);
- }
-
- // write errror to console
- logExceptionToTechnicalLog(errorData);
-
- if (errorData.getActionType().equals(ErrorTicketService.ActionType.NOTICKET_NOREDIRECT) || errorData
- .getActionType().equals(ErrorTicketService.ActionType.TICKET_NOREDIRECT) || recall) {
- // return error to Web browser
- displayException(req, resp, errorData);
- } else {
- // TODO introduce separate error type?
- throw new EaafException("internal.configuration.01", new Object[]{
- errorData.getErrorCode() + " in on_error_action" + ".properties", "Erroraction mapping mismatch"});
- }
-
- } catch (EaafException e) {
- // retry
- handleErrorNoRedirect(e, req, resp, writeExceptionToStatisticLog, true);
+ // log Exception into statistic database
+ if (writeExceptionToStatisticLog) {
+ statisticLogger.logErrorOperation(throwable);
+ }
- } catch (IOException e) {
- // retry
- handleErrorNoRedirect(new EaafException(IStatusMessenger.CODES_INTERNAL_ERROR_GENERIC, null, e), req, resp,
- writeExceptionToStatisticLog, true);
+ // write errror to console
+ errorData.logExceptionToTechnicalLog(logOnInfoLevel);
+ if (errorData.getActionType().equals(IErrorService.ActionType.NOTICKET_NOREDIRECT) || errorData
+ .getActionType().equals(IErrorService.ActionType.TICKET_NOREDIRECT)) {
+ // return error to Web browser
+ displayException(req, resp, errorData);
+ } else {
+ // TODO introduce separate error type?
+ throw new EaafException("internal.configuration.01", new Object[]{
+ errorData.getInternalErrorCode() + " in on_error_action" + ".properties", "Erroraction mapping mismatch"});
}
}
+
@Override
public void forwardToErrorHandler(Pair<IRequest, Throwable> errorToHandle, String errorKey,
final HttpServletRequest req, final HttpServletResponse resp) throws GuiBuildException {
@@ -432,33 +419,6 @@ public class ProtocolAuthenticationService implements IProtocolAuthenticationSer
}
- /**
- * Write a Exception to the MOA-ID-Auth internal technical log.
- *
- * @param data errordata structure
- */
- protected void logExceptionToTechnicalLog(ErrorTicketService.HandleData data) {
- // In case of a TaskExecutionException, which is only a container for process-errors,
- // extract internal exception
-
-
- // Log exception
- if (!(data.getThrowable() instanceof EaafException)) {
- data.log_error();
-
- } else {
-
- if (logOnInfoLevel.contains(data.getErrorCode())) {
- data.log_info();
-
- } else {
- data.log_warn();
-
- }
- }
- }
-
-
@PostConstruct
private void initializer() {
log.trace("Initializing {} ...", ProtocolAuthenticationService.class.getName());
@@ -511,7 +471,8 @@ public class ProtocolAuthenticationService implements IProtocolAuthenticationSer
private void writeHtmlErrorResponse(@NonNull final HttpServletRequest httpReq,
@NonNull final HttpServletResponse httpResp, @NonNull final String msg, @NonNull final String errorCode,
- @Nullable final Object[] params, String externalErrorCode, String url, String ticket) throws EaafException {
+ @Nullable final Object[] params, String externalErrorCode, IErrorService.IHandleData errorData)
+ throws EaafException {
try {
final IGuiBuilderConfiguration config = guiConfigFactory
@@ -542,8 +503,8 @@ public class ProtocolAuthenticationService implements IProtocolAuthenticationSer
externalErrorCode);
c.putCustomParameterWithOutEscaption(AbstractGuiFormBuilderConfiguration.PARAM_GROUP_MSG,
PARAM_GUI_ERRORCODEPARAMS, ArrayUtils.toString(errorCodeParams));
- c.putCustomParameter(AbstractGuiFormBuilderConfiguration.PARAM_GROUP_MSG, PARAM_GUI_TICKET, ticket);
- c.putCustomParameter(AbstractGuiFormBuilderConfiguration.PARAM_GROUP_MSG, PARAM_GUI_REDIRECT, url);
+ errorTicketService.displayErrorData(c, errorData);
+
} else {
log.info("Can not ADD error message, because 'GUIBuilderConfiguration' is not modifieable ");
@@ -560,9 +521,9 @@ public class ProtocolAuthenticationService implements IProtocolAuthenticationSer
}
private void displayException(final HttpServletRequest req, final HttpServletResponse resp,
- final ErrorTicketService.HandleData errorData) throws IOException, EaafException {
+ final IErrorService.IHandleData errorData) throws IOException, EaafException {
final Throwable e = errorData.getThrowable();
- final String internalErrorCode = errorData.getErrorCode();
+ final String internalErrorCode = errorData.getInternalErrorCode();
// send error response
if (e instanceof ProtocolNotActiveException) {
@@ -575,30 +536,27 @@ public class ProtocolAuthenticationService implements IProtocolAuthenticationSer
|| e instanceof ProcessExecutionException || e instanceof ConfigurationException) {
// write error message
writeHtmlErrorResponse(req, resp, e.getMessage(), internalErrorCode, null,
- statusMessager.mapInternalErrorToExternalError(internalErrorCode), errorData.getRedirectUrl(),
- errorData.getSupportTicket());
+ statusMessager.mapInternalErrorToExternalError(internalErrorCode), errorData);
} else if (e instanceof EaafException) {
// send HTML formated error message
writeHtmlErrorResponse(req, resp, e.getMessage(), internalErrorCode, ((EaafException) e).getParams(),
- statusMessager.mapInternalErrorToExternalError(internalErrorCode), errorData.getRedirectUrl(),
- errorData.getSupportTicket());
+ statusMessager.mapInternalErrorToExternalError(internalErrorCode), 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,
- statusMessager.mapInternalErrorToExternalError(internalErrorCode), errorData.getRedirectUrl(),
- errorData.getSupportTicket());
+ statusMessager.mapInternalErrorToExternalError(internalErrorCode), errorData);
}
}
private IGuiBuilderConfiguration evaluateRequiredErrorHandlingMethod(IRequest first, String errorId) {
if (first != null && first.isProcessInIframe()) {
- return guiConfigFactory.getDefaultIFrameParentHopGui(first,
- ProtocolFinalizationController.ENDPOINT_ERRORHANDLING,
- errorId);
+ return guiConfigFactory
+ .getDefaultIFrameParentHopGui(first, "/" + ProtocolFinalizationController.ENDPOINT_ERRORHANDLING, errorId);
+
}
return null;
}
diff --git a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/controller/ProtocolFinalizationController.java b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/controller/ProtocolFinalizationController.java
index 90d8a28d..a8b0a961 100644
--- a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/controller/ProtocolFinalizationController.java
+++ b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/controller/ProtocolFinalizationController.java
@@ -19,7 +19,6 @@
package at.gv.egiz.eaaf.core.impl.idp.controller;
-
import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
@@ -59,8 +58,7 @@ public class ProtocolFinalizationController extends AbstractController {
public static final String ENDPOINT_ERRORHANDLING =
EaafConstants.ENDPOINT_PREFIX_SECURED + "/errorHandling";
public static final String ENDPOINT_ERROR_REDIRECT =
- EaafConstants.ENDPOINT_PREFIX_SECURED + "errorRedirect";
-
+ EaafConstants.ENDPOINT_PREFIX_SECURED + "/errorRedirect";
@Autowired(required = true)
IRequestStorage requestStorage;