aboutsummaryrefslogtreecommitdiff
path: root/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/saml1/GetArtifactAction.java
diff options
context:
space:
mode:
Diffstat (limited to 'id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/saml1/GetArtifactAction.java')
-rw-r--r--id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/saml1/GetArtifactAction.java127
1 files changed, 127 insertions, 0 deletions
diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/saml1/GetArtifactAction.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/saml1/GetArtifactAction.java
new file mode 100644
index 000000000..d4ee5f46c
--- /dev/null
+++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/saml1/GetArtifactAction.java
@@ -0,0 +1,127 @@
+package at.gv.egovernment.moa.id.protocols.saml1;
+
+import java.io.UnsupportedEncodingException;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+
+import org.apache.commons.lang.StringEscapeUtils;
+
+import at.gv.egovernment.moa.id.AuthenticationException;
+import at.gv.egovernment.moa.id.BuildException;
+import at.gv.egovernment.moa.id.auth.WrongParametersException;
+import at.gv.egovernment.moa.id.auth.data.AuthenticationSession;
+import at.gv.egovernment.moa.id.config.ConfigurationException;
+import at.gv.egovernment.moa.id.moduls.AuthenticationManager;
+import at.gv.egovernment.moa.id.moduls.IAction;
+import at.gv.egovernment.moa.id.moduls.IRequest;
+import at.gv.egovernment.moa.id.util.ParamValidatorUtils;
+import at.gv.egovernment.moa.logging.Logger;
+import at.gv.egovernment.moa.util.URLEncoder;
+
+public class GetArtifactAction implements IAction {
+
+ public void processRequest(IRequest req, HttpServletRequest httpReq,
+ HttpServletResponse httpResp) {
+ HttpSession httpSession = httpReq.getSession();
+
+ AuthenticationSession session = AuthenticationManager
+ .getAuthenticationSession(httpSession);
+
+ String oaURL = (String) httpReq.getAttribute(PARAM_OA);
+ oaURL = StringEscapeUtils.escapeHtml(oaURL);
+
+ try {
+
+ // check parameter
+ if (!ParamValidatorUtils.isValidOA(oaURL))
+ throw new WrongParametersException("StartAuthentication",
+ PARAM_OA, "auth.12");
+
+ if (oaURL == null) {
+ oaURL = session.getOAURLRequested();
+ }
+
+ if (oaURL == null) {
+ throw new WrongParametersException("StartAuthentication",
+ PARAM_OA, "auth.12");
+ }
+
+ String samlArtifactBase64 = SAML1AuthenticationServer
+ .BuildSAMLArtifact(session);
+
+ String redirectURL = oaURL;
+ session.getOAURLRequested();
+ if (!session.getBusinessService()) {
+ redirectURL = addURLParameter(redirectURL, PARAM_TARGET,
+ URLEncoder.encode(session.getTarget(), "UTF-8"));
+
+ }
+ redirectURL = addURLParameter(redirectURL, PARAM_SAMLARTIFACT,
+ URLEncoder.encode(samlArtifactBase64, "UTF-8"));
+ redirectURL = httpResp.encodeRedirectURL(redirectURL);
+
+ httpResp.setContentType("text/html");
+ httpResp.setStatus(302);
+
+ httpResp.addHeader("Location", redirectURL);
+ Logger.debug("REDIRECT TO: " + redirectURL);
+
+ // CONFIRMATION FOR SSO!
+ /*
+ * OAAuthParameter oaParam =
+ * AuthConfigurationProvider.getInstance().
+ * getOnlineApplicationParameter(oaURL);
+ *
+ * String friendlyName = oaParam.getFriendlyName(); if(friendlyName
+ * == null) { friendlyName = oaURL; }
+ *
+ *
+ * LoginConfirmationBuilder builder = new
+ * LoginConfirmationBuilder();
+ * builder.addParameter(PARAM_SAMLARTIFACT, samlArtifactBase64);
+ * String form = builder.finish(oaURL, session.getIdentityLink()
+ * .getName(), friendlyName);
+ */
+
+ /*
+ * resp.setContentType("text/html");
+ *
+ * OutputStream out = resp.getOutputStream();
+ * out.write(form.getBytes("UTF-8")); out.flush(); out.close();
+ */
+
+ } catch (WrongParametersException ex) {
+ // handleWrongParameters(ex, req, httpResp);
+ ex.printStackTrace();
+ } catch (ConfigurationException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (BuildException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (AuthenticationException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (UnsupportedEncodingException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ protected static String addURLParameter(String url, String paramname,
+ String paramvalue) {
+ String param = paramname + "=" + paramvalue;
+ if (url.indexOf("?") < 0)
+ return url + "?" + param;
+ else
+ return url + "&" + param;
+ }
+
+ public boolean needAuthentication(IRequest req, HttpServletRequest httpReq,
+ HttpServletResponse httpResp) {
+ return true;
+ }
+
+}