diff options
author | Thomas <thomas.lenz@egiz.gv.at> | 2019-05-04 09:37:22 +0200 |
---|---|---|
committer | Thomas <thomas.lenz@egiz.gv.at> | 2019-05-04 09:37:22 +0200 |
commit | f9a438a837221dae0320bcddefa6a86b6be7f75d (patch) | |
tree | 9eaba1b9db34e0cd7fbcf8914b6549bf0f78c2cc /eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/modules/AbstractAuthServletTask.java | |
parent | 6065ba01b3f49e6f79179cc85a38e4229e47d306 (diff) | |
parent | 2e921528557a23b96fb6b52b2b53a28048a826fd (diff) | |
download | EAAF-Components-f9a438a837221dae0320bcddefa6a86b6be7f75d.tar.gz EAAF-Components-f9a438a837221dae0320bcddefa6a86b6be7f75d.tar.bz2 EAAF-Components-f9a438a837221dae0320bcddefa6a86b6be7f75d.zip |
Merge branch 'master' of https://gitlab.iaik.tugraz.at/egiz/eaaf_components
Diffstat (limited to 'eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/modules/AbstractAuthServletTask.java')
-rw-r--r-- | eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/modules/AbstractAuthServletTask.java | 55 |
1 files changed, 38 insertions, 17 deletions
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<String, String> getParameters(HttpServletRequest req) throws IOException, FileUploadException { - Map<String, String> parameters = new HashMap<String, String>(); + final Map<String, String> parameters = new HashMap<String, String>(); 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 = "<pr:Identification><pr:Value>"; - String endS = "</pr:Value><pr:Type>urn:publicid:gv.at:baseid</pr:Type>"; + final String startS = "<pr:Identification><pr:Value>"; + final String endS = "</pr:Value><pr:Type>urn:publicid:gv.at:baseid</pr:Type>"; 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<Entry<String, String[]>> requestParamIt = req.getParameterMap().entrySet().iterator(); + final Iterator<Entry<String, String[]>> requestParamIt = req.getParameterMap().entrySet().iterator(); while (requestParamIt.hasNext()) { - Entry<String, String[]> entry = requestParamIt.next(); - String key = entry.getKey(); - String[] values = entry.getValue(); + final Entry<String, String[]> 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 |