From dc8587693201e34fe0f7a87b3e401fac4325ce04 Mon Sep 17 00:00:00 2001 From: Thomas Lenz Date: Fri, 3 May 2019 06:59:13 +0200 Subject: update process finalization and update pendingReqIdGenerationStrategy --- .../eaaf/core/impl/idp/auth/RequestStorage.java | 6 +-- .../idp/auth/modules/AbstractAuthServletTask.java | 55 +++++++++++++++------- .../services/ProtocolAuthenticationService.java | 2 +- 3 files changed, 42 insertions(+), 21 deletions(-) (limited to 'eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth') diff --git a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/RequestStorage.java b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/RequestStorage.java index 2115d9b0..2b0cbab3 100644 --- a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/RequestStorage.java +++ b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/RequestStorage.java @@ -98,7 +98,7 @@ public class RequestStorage implements IRequestStorage{ if (pendingRequest instanceof IRequest) { try { //validate pending-requestId - final String internalPendingRequestId = pendingReqIdGenerationStrategy.validateAndGetPendingRequestId(pendingRequest.getPendingRequestId()); + final String internalPendingRequestId = pendingReqIdGenerationStrategy.getPendingRequestIdWithOutChecks(pendingRequest.getPendingRequestId()); //store pending request transactionStorage.put(internalPendingRequestId, pendingRequest, -1); @@ -128,7 +128,7 @@ public class RequestStorage implements IRequestStorage{ if (pendingReqID != null) { String internalPendingReqId = null; try { - internalPendingReqId = pendingReqIdGenerationStrategy.validateAndGetPendingRequestId(pendingReqID); + internalPendingReqId = pendingReqIdGenerationStrategy.getPendingRequestIdWithOutChecks(pendingReqID); } catch (final PendingReqIdValidationException e) { internalPendingReqId = e.getInvalidInternalPendingReqId(); @@ -170,7 +170,7 @@ public class RequestStorage implements IRequestStorage{ String newInternalPendingRequestId = null; try { - newInternalPendingRequestId = pendingReqIdGenerationStrategy.validateAndGetPendingRequestId(newRequestID); + newInternalPendingRequestId = pendingReqIdGenerationStrategy.getPendingRequestIdWithOutChecks(newRequestID); } catch (final PendingReqIdValidationException e) { throw new EAAFException("internal.99", new Object[]{"Generate invalid pendingRequestId. Something looks WRONG"}, e); diff --git a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/modules/AbstractAuthServletTask.java b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/modules/AbstractAuthServletTask.java index eb87e893..5027a84b 100644 --- a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/modules/AbstractAuthServletTask.java +++ b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/modules/AbstractAuthServletTask.java @@ -52,8 +52,10 @@ import at.gv.egiz.eaaf.core.api.IRequest; import at.gv.egiz.eaaf.core.api.IRequestStorage; import at.gv.egiz.eaaf.core.api.data.EAAFConstants; import at.gv.egiz.eaaf.core.api.idp.IConfiguration; +import at.gv.egiz.eaaf.core.api.idp.auth.services.IProtocolAuthenticationService; import at.gv.egiz.eaaf.core.api.idp.process.ExecutionContext; import at.gv.egiz.eaaf.core.api.logging.IRevisionLogger; +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.idp.process.springweb.AbstractTask; @@ -66,6 +68,7 @@ import at.gv.egiz.eaaf.core.impl.utils.DataURLBuilder; public abstract class AbstractAuthServletTask extends AbstractTask { private static final Logger log = LoggerFactory.getLogger(AbstractAuthServletTask.class); + @Autowired(required=true) IProtocolAuthenticationService protAuchService; @Autowired(required=true) protected IRequestStorage requestStoreage; @Autowired(required=true) protected IConfiguration authConfig; @@ -75,10 +78,12 @@ public abstract class AbstractAuthServletTask extends AbstractTask { protected IRequest pendingReq = null; + @Override public abstract void execute(ExecutionContext executionContext, HttpServletRequest request, HttpServletResponse response) throws TaskExecutionException; + @Override protected final IRequest internalExecute(IRequest pendingReq, ExecutionContext executionContext, HttpServletRequest request, HttpServletResponse response) throws TaskExecutionException { //set pending-request object @@ -96,12 +101,28 @@ public abstract class AbstractAuthServletTask extends AbstractTask { /** * Redirect the authentication process to protocol specific finalization endpoint. + * @param executionContext * * @param pendingReq Actually processed protocol specific authentication request * @param httpResp + * @throws IOException + * @throws EAAFException */ - protected void performRedirectToProtocolFinialization(IRequest pendingReq, HttpServletResponse httpResp) { - performRedirectToItself(pendingReq, httpResp, ProtocolFinalizationController.ENDPOINT_FINALIZEPROTOCOL); + protected void performRedirectToProtocolFinialization(ExecutionContext executionContext, IRequest pendingReq, HttpServletRequest httpReq, HttpServletResponse httpResp) throws EAAFException, IOException { + final Object frontChannelRedirectFlagObj = executionContext.get(EAAFConstants.PROCESS_ENGINE_REQUIRES_NO_POSTAUTH_REDIRECT); + if (frontChannelRedirectFlagObj != null && frontChannelRedirectFlagObj instanceof Boolean && + (Boolean)frontChannelRedirectFlagObj) { + log.info("AuthProcess finished. Forward to Protocol finalization."); + protAuchService.finalizeAuthentication(httpReq, httpResp, pendingReq); + + } else { + log.info("AuthProcess finished. Redirect to Protocol Dispatcher."); + requestStoreage.storePendingRequest(pendingReq); + performRedirectToItself(pendingReq, httpResp, ProtocolFinalizationController.ENDPOINT_FINALIZEPROTOCOL); + + } + + } @@ -113,7 +134,7 @@ public abstract class AbstractAuthServletTask extends AbstractTask { * @param idpEndPoint Servlet EndPoint that should receive the redirect */ protected void performRedirectToItself(IRequest pendingReq, HttpServletResponse httpResp, String idpEndPoint) { - String redirectURL = new DataURLBuilder().buildDataURL(pendingReq.getAuthURL(), + final String redirectURL = new DataURLBuilder().buildDataURL(pendingReq.getAuthURL(), idpEndPoint, pendingReq.getPendingRequestId()); httpResp.setContentType("text/html"); @@ -142,32 +163,32 @@ public abstract class AbstractAuthServletTask extends AbstractTask { protected Map getParameters(HttpServletRequest req) throws IOException, FileUploadException { - Map parameters = new HashMap(); + final Map parameters = new HashMap(); if (ServletFileUpload.isMultipartContent(req)) { // request is encoded as mulitpart/form-data - FileItemFactory factory = new DiskFileItemFactory(); + final FileItemFactory factory = new DiskFileItemFactory(); ServletFileUpload upload = null; upload = new ServletFileUpload(factory); List items = null; items = upload.parseRequest(req); for (int i = 0; i < items.size(); i++) { - FileItem item = (FileItem) items.get(i); + final FileItem item = (FileItem) items.get(i); if (item.isFormField()) { // Process only form fields - no file upload items parameters.put(item.getFieldName(), item.getString("UTF-8")); //log requests on trace if (log.isTraceEnabled()) { - String logString = item.getString("UTF-8"); + final String logString = item.getString("UTF-8"); // TODO use RegExp - String startS = ""; - String endS = "urn:publicid:gv.at:baseid"; + final String startS = ""; + final String endS = "urn:publicid:gv.at:baseid"; String logWithMaskedBaseid = logString; - int start = logString.indexOf(startS); + final int start = logString.indexOf(startS); if (start > -1) { - int end = logString.indexOf(endS); + final int end = logString.indexOf(endS); if (end > -1) { logWithMaskedBaseid = logString.substring(0, start); logWithMaskedBaseid += startS; @@ -188,11 +209,11 @@ public abstract class AbstractAuthServletTask extends AbstractTask { } else { - Iterator> requestParamIt = req.getParameterMap().entrySet().iterator(); + final Iterator> requestParamIt = req.getParameterMap().entrySet().iterator(); while (requestParamIt.hasNext()) { - Entry entry = requestParamIt.next(); - String key = entry.getKey(); - String[] values = entry.getValue(); + final Entry entry = requestParamIt.next(); + final String key = entry.getKey(); + final String[] values = entry.getValue(); // take the last value from the value array since the legacy code above also does it this way parameters.put(key, ArrayUtils.isEmpty(values) ? null : values[values.length-1]); } @@ -214,7 +235,7 @@ public abstract class AbstractAuthServletTask extends AbstractTask { */ protected String readBytesUpTo(InputStream in, char delimiter) throws IOException { - ByteArrayOutputStream bout = new ByteArrayOutputStream(); + final ByteArrayOutputStream bout = new ByteArrayOutputStream(); boolean done = false; int b; while (!done && (b = in.read()) >= 0) { @@ -239,7 +260,7 @@ public abstract class AbstractAuthServletTask extends AbstractTask { */ protected static String addURLParameter(String url, String paramname, String paramvalue) { - String param = paramname + "=" + paramvalue; + final String param = paramname + "=" + paramvalue; if (url.indexOf("?") < 0) return url + "?" + param; else 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 4edde029..7d3ca2f8 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 @@ -381,7 +381,7 @@ public class ProtocolAuthenticationService implements IProtocolAuthenticationSer // HTTPUtils.extractAuthURLFromRequest(req), // DefaultGUIFormBuilderConfiguration.VIEW_ERRORMESSAGE, // null); - + //add errorcode and errormessage if (config instanceof ModifyableGuiBuilderConfiguration) { ((ModifyableGuiBuilderConfiguration)config).putCustomParameter("errorMsg", msg); -- cgit v1.2.3