summaryrefslogtreecommitdiff
path: root/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/services/ProtocolAuthenticationService.java
diff options
context:
space:
mode:
authorlalber <lukas.alber@iaik.tugraz.at>2021-03-21 12:52:27 +0100
committerThomas <>2021-03-30 20:22:45 +0200
commitae6d01d3eef70fb5892430aee88438dc15c02cf9 (patch)
treeb8c9e747caa09baa4f3440db7c9be4cd1513ee4d /eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/services/ProtocolAuthenticationService.java
parentfaa131a65b46a5c42a7b6b85e0ff3b414c93bea5 (diff)
downloadEAAF-Components-ae6d01d3eef70fb5892430aee88438dc15c02cf9.tar.gz
EAAF-Components-ae6d01d3eef70fb5892430aee88438dc15c02cf9.tar.bz2
EAAF-Components-ae6d01d3eef70fb5892430aee88438dc15c02cf9.zip
Junit fixes
Diffstat (limited to 'eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/services/ProtocolAuthenticationService.java')
-rw-r--r--eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/services/ProtocolAuthenticationService.java103
1 files changed, 81 insertions, 22 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 5d656e76..e04fc626 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
@@ -54,6 +54,7 @@ import at.gv.egiz.eaaf.core.api.idp.IAction;
import at.gv.egiz.eaaf.core.api.idp.IAuthData;
import at.gv.egiz.eaaf.core.api.idp.IAuthenticationDataBuilder;
import at.gv.egiz.eaaf.core.api.idp.IConfiguration;
+import at.gv.egiz.eaaf.core.api.idp.IModulInfo;
import at.gv.egiz.eaaf.core.api.idp.ISpConfiguration;
import at.gv.egiz.eaaf.core.api.idp.auth.IAuthenticationManager;
import at.gv.egiz.eaaf.core.api.idp.auth.ISsoManager;
@@ -234,14 +235,9 @@ 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.NOTICKET_REDIRECT) || errorData.getActionType()
- .equals(ErrorTicketService.ActionType.TICKET_REDIRECT)) {
-
- displayException(req, resp, errorData);
+ if (errorData.getActionType().equals(ErrorTicketService.ActionType.TICKET_REDIRECT)) {
// Put pending request
ExceptionContainer exceptionContainer = new ExceptionContainer(protocolRequest, throwable);
@@ -258,6 +254,27 @@ public class ProtocolAuthenticationService implements IProtocolAuthenticationSer
// log Error Message
statisticLogger.logErrorOperation(throwable, protocolRequest);
+ displayException(req, resp, errorData);
+
+ } else if (errorData.getActionType().equals(ErrorTicketService.ActionType.NOTICKET_REDIRECT)) {
+ IModulInfo handlingModule = extractShibbolethHandling(protocolRequest, applicationContext);
+
+ if (handlingModule.generateErrorMessage(throwable, req, resp, protocolRequest)) {
+
+ // log Error to technical log
+ logExceptionToTechnicalLog(errorData);
+
+ // log Error Message
+ statisticLogger.logErrorOperation(throwable, protocolRequest);
+
+ // write revision log entries
+ revisionsLogger.logEvent(protocolRequest, EventConstants.TRANSACTION_ERROR,
+ protocolRequest.getUniqueTransactionIdentifier());
+
+ } else {
+ throw throwable; //through it on to handleErrorNoRedirect
+
+ }
} else {
throw throwable; //through it on to handleErrorNoRedirect
@@ -265,32 +282,73 @@ public class ProtocolAuthenticationService implements IProtocolAuthenticationSer
}
} catch (final Throwable e) { //
- handleErrorNoRedirect(throwable, req, resp, true);
+ // if building error response results in error, we try with with handleErrorNoRedirect
+ handleErrorNoRedirect(e, req, resp, true);
}
}
+ /**
+ * Retrieves shibboleth module info.
+ * @param protocolRequest current request
+ * @param applicationContext spring context
+ * @return IModulInfo
+ * @throws ClassNotFoundException If no shibboleth handling implementation found
+ */
+ public static IModulInfo extractShibbolethHandling(IRequest protocolRequest,
+ ApplicationContext applicationContext) throws ClassNotFoundException {
+ final Class<?> clazz = Class.forName(protocolRequest.requestedModule());
+
+ if (clazz == null || !IModulInfo.class.isAssignableFrom(clazz)) {
+ log.error(
+ "Requested protocol module Class is NULL or does not implement the IModulInfo interface.");
+ throw new ClassCastException(
+ "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) throws IOException, EaafException {
+ final HttpServletResponse resp, final boolean writeExceptionToStatisticLog) {
+ handleErrorNoRedirect(throwable, req, resp, writeExceptionToStatisticLog, false);
+ }
- ErrorTicketService.HandleData errorData = errorTicketService.createHandleData(throwable, req);
+ 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);
- // log Exception into statistic database
- if (writeExceptionToStatisticLog) {
- statisticLogger.logErrorOperation(throwable);
- }
+ // log Exception into statistic database
+ if (writeExceptionToStatisticLog) {
+ statisticLogger.logErrorOperation(throwable);
+ }
- // write errror to console
- logExceptionToTechnicalLog(errorData);
+ // 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);
+
+ } catch (IOException e) {
+ // retry
+ handleErrorNoRedirect(new EaafException(IStatusMessenger.CODES_INTERNAL_ERROR_GENERIC, null, e), req, resp,
+ writeExceptionToStatisticLog, true);
- if (errorData.getActionType().equals(ErrorTicketService.ActionType.NOTICKET_NOREDIRECT) || errorData.getActionType()
- .equals(ErrorTicketService.ActionType.TICKET_NOREDIRECT)) {
- // return error to Web browser
- displayException(req, resp, errorData);
- } else {
- throw new EaafException(IStatusMessenger.CODES_INTERNAL_ERROR_GENERIC, null,
- new Exception("On Erroraction mapping mismatch", throwable));
}
}
@@ -478,6 +536,7 @@ public class ProtocolAuthenticationService implements IProtocolAuthenticationSer
ModifyableGuiBuilderConfiguration c = (ModifyableGuiBuilderConfiguration) config;
c.putCustomParameter(AbstractGuiFormBuilderConfiguration.PARAM_GROUP_MSG, PARAM_GUI_ERROMSG, msg);
c.putCustomParameter(AbstractGuiFormBuilderConfiguration.PARAM_GROUP_MSG, PARAM_GUI_ERRORCODE, errorCode);
+ // TODO: should we keep the internal errorcode secret?
c.putCustomParameter(AbstractGuiFormBuilderConfiguration.PARAM_GROUP_MSG, PARAM_GUI_EXTERNAL_ERRORCODE,
externalErrorCode);
c.putCustomParameterWithOutEscaption(AbstractGuiFormBuilderConfiguration.PARAM_GROUP_MSG,