[java-identity-provider] branch main updated: Add an ECP flow test.

Scott Cantor cantor.2 at osu.edu
Thu Mar 24 16:58:55 UTC 2022


This is an automated email from the git hooks/post-receive script.

scantor pushed a commit to branch main
in repository java-identity-provider.

View the commit online:
http://git.shibboleth.net/view/?p=java-identity-provider.git;a=commit;h=93cc4ae257585ca4a3e0e3a732028aad0ead8ed8

The following commit(s) were added to refs/heads/main by this push:
     new 93cc4ae25 Add an ECP flow test.
93cc4ae25 is described below

commit 93cc4ae257585ca4a3e0e3a732028aad0ead8ed8
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Thu Mar 24 12:58:52 2022 -0400

    Add an ECP flow test.
---
 .../test/flows/saml2/AbstractSAML2SSOFlowTest.java |  36 ++++++--
 .../idp/test/flows/saml2/SAML2ECPSSOFlowTest.java  | 101 +++++++++++++++++++++
 .../test/resources/metadata/example-metadata.xml   |   3 +-
 3 files changed, 132 insertions(+), 8 deletions(-)

diff --git a/idp-conf/src/test/java/net/shibboleth/idp/test/flows/saml2/AbstractSAML2SSOFlowTest.java b/idp-conf/src/test/java/net/shibboleth/idp/test/flows/saml2/AbstractSAML2SSOFlowTest.java
index 0be613a94..6371ca78a 100644
--- a/idp-conf/src/test/java/net/shibboleth/idp/test/flows/saml2/AbstractSAML2SSOFlowTest.java
+++ b/idp-conf/src/test/java/net/shibboleth/idp/test/flows/saml2/AbstractSAML2SSOFlowTest.java
@@ -102,15 +102,34 @@ public abstract class AbstractSAML2SSOFlowTest extends AbstractSAML2FlowTest {
         }
     }
 
-    public AuthnRequest buildAuthnRequest(HttpServletRequest servletRequest) throws EncryptionException {
+    public String getDestinationECP(HttpServletRequest servletRequest) {
+        // TODO servlet context
+        String destinationPath = "/idp/profile/SAML2/SOAP/ECP";
+        try {
+            String baseUrl = SimpleURLCanonicalizer.canonicalize(getBaseUrl(servletRequest));
+            URLBuilder urlBuilder = new URLBuilder(baseUrl);
+            urlBuilder.setPath(destinationPath);
+            return urlBuilder.buildURL();
+        } catch (final MalformedURLException e) {
+            log.error("Couldn't parse base URL, reverting to internal default destination");
+            return "http://localhost:8080" + destinationPath;
+        }
+    }
+
+    public AuthnRequest buildAuthnRequest(final HttpServletRequest servletRequest) throws EncryptionException {
+        return buildAuthnRequest(servletRequest, getAcsUrl(servletRequest), SAMLConstants.SAML2_POST_BINDING_URI);
+    }
+    
+    public AuthnRequest buildAuthnRequest(final HttpServletRequest servletRequest, final String acsURL, final String outboundBinding)
+            throws EncryptionException {
         final AuthnRequest authnRequest =
                 (AuthnRequest) builderFactory.getBuilder(AuthnRequest.DEFAULT_ELEMENT_NAME).buildObject(
                         AuthnRequest.DEFAULT_ELEMENT_NAME);
 
         authnRequest.setID(idGenerator.generateIdentifier());
         authnRequest.setIssueInstant(Instant.now());
-        authnRequest.setAssertionConsumerServiceURL(getAcsUrl(servletRequest));
-        authnRequest.setProtocolBinding(SAMLConstants.SAML2_POST_BINDING_URI);
+        authnRequest.setAssertionConsumerServiceURL(acsURL);
+        authnRequest.setProtocolBinding(outboundBinding);
 
         final Issuer issuer =
                 (Issuer) builderFactory.getBuilder(Issuer.DEFAULT_ELEMENT_NAME)
@@ -162,17 +181,20 @@ public abstract class AbstractSAML2SSOFlowTest extends AbstractSAML2FlowTest {
         return encrypter;
     }
 
-    public String getAcsUrl(HttpServletRequest servletRequest) {
+    public String getAcsUrl(final HttpServletRequest servletRequest) {
+        return getAcsUrl(servletRequest, "/sp/SAML2/POST/ACS"); 
+    }
+    
+    public String getAcsUrl(final HttpServletRequest servletRequest, final String acsURL) {
         // TODO servlet context
-        String acsPath = "/sp/SAML2/POST/ACS";
         String baseUrl = getBaseUrl(servletRequest);
         try {
             URLBuilder urlBuilder = new URLBuilder(SimpleURLCanonicalizer.canonicalize(baseUrl));
-            urlBuilder.setPath(acsPath);
+            urlBuilder.setPath(acsURL);
             return urlBuilder.buildURL();
         } catch (MalformedURLException e) {
             log.error("Couldn't parse base URL, reverting to internal default ACS: {}", baseUrl);
-            return "http://localhost:8080" + acsPath;
+            return "http://localhost:8080" + acsURL;
         }
     }
 
diff --git a/idp-conf/src/test/java/net/shibboleth/idp/test/flows/saml2/SAML2ECPSSOFlowTest.java b/idp-conf/src/test/java/net/shibboleth/idp/test/flows/saml2/SAML2ECPSSOFlowTest.java
new file mode 100644
index 000000000..6669131d9
--- /dev/null
+++ b/idp-conf/src/test/java/net/shibboleth/idp/test/flows/saml2/SAML2ECPSSOFlowTest.java
@@ -0,0 +1,101 @@
+/*
+ * Licensed to the University Corporation for Advanced Internet Development,
+ * Inc. (UCAID) under one or more contributor license agreements.  See the
+ * NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The UCAID licenses this file to You under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file except in
+ * compliance with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.shibboleth.idp.test.flows.saml2;
+
+import java.io.IOException;
+
+import javax.annotation.Nonnull;
+
+import net.shibboleth.utilities.java.support.xml.SerializeSupport;
+
+import org.opensaml.core.xml.io.MarshallingException;
+import org.opensaml.core.xml.util.XMLObjectSupport;
+import org.opensaml.messaging.context.MessageContext;
+import org.opensaml.saml.common.SAMLObject;
+import org.opensaml.saml.common.xml.SAMLConstants;
+import org.opensaml.saml.saml2.core.AuthnRequest;
+import org.springframework.mock.web.MockHttpServletRequest;
+import org.springframework.webflow.executor.FlowExecutionResult;
+import org.testng.annotations.Test;
+import org.w3c.dom.Element;
+
+/**
+ * SAML 2 ECP SSO flow test.
+ */
+public class SAML2ECPSSOFlowTest extends AbstractSAML2SSOFlowTest {
+
+    /** Flow id. */
+    @Nonnull public final static String FLOW_ID = "SAML2/SOAP/ECP";
+
+    /**
+     * Test the SAML 2 Redirect SSO flow.
+     * 
+     * @throws Exception if something goes wrong
+     */
+    @Test public void testSAML2ECPFlow() throws Exception {
+
+        buildRequest();
+
+        overrideEndStateOutput(FLOW_ID);
+
+        final FlowExecutionResult result = flowExecutor.launchExecution(FLOW_ID, null, externalContext);
+
+        validateResult(result, FLOW_ID);
+    }
+
+    /**
+     * Build the {@link MockHttpServletRequest}.
+     * 
+     * @throws Exception if an error occurs
+     */
+    public void buildRequest() throws Exception {
+
+        request.setMethod("POST");
+        request.setRequestURI("/idp/profile/" + FLOW_ID);
+        request.setContentType("text/xml");
+
+        final AuthnRequest authnRequest = buildAuthnRequest(request, getAcsUrl(request, "/sp/SAML2/PAOS/ACS"),
+                SAMLConstants.SAML2_PAOS_BINDING_URI);
+        authnRequest.setDestination(getDestinationECP(request));
+
+        final MessageContext messageContext =
+                buildOutboundMessageContext(authnRequest, SAMLConstants.SAML2_SOAP11_BINDING_URI);
+        final SAMLObject message = (SAMLObject) messageContext.getMessage();
+        request.setContent(encodeMessage(message).getBytes("UTF-8"));
+    }
+
+    /**
+     * Wrap the SAML message in a SOAP envelope.
+     * 
+     * @param message the SAML message
+     * @return wrapped message
+     * @throws MarshallingException if there is a problem marshalling the XMLObject
+     * @throws IOException if an I/O error has occurred
+     */
+    @Nonnull public String encodeMessage(@Nonnull final SAMLObject message) throws MarshallingException, IOException {
+
+        final String pre = "<S:Envelope xmlns:S=\"http://schemas.xmlsoap.org/soap/envelope/\"><S:Body>";
+        final String post = "</S:Body></S:Envelope>";
+
+        final Element domMessage = XMLObjectSupport.marshall(message);
+        final String messageXML = SerializeSupport.nodeToString(domMessage);
+
+        return pre + messageXML.substring(messageXML.indexOf("<saml2p:AuthnRequest")) + post;
+    }
+
+}
\ No newline at end of file
diff --git a/idp-conf/src/test/resources/metadata/example-metadata.xml b/idp-conf/src/test/resources/metadata/example-metadata.xml
index b47d54dae..3053295a4 100644
--- a/idp-conf/src/test/resources/metadata/example-metadata.xml
+++ b/idp-conf/src/test/resources/metadata/example-metadata.xml
@@ -112,7 +112,8 @@ h+XNZ5oAql/cjrwDWw==
         <AssertionConsumerService Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST" Location="http://localhost:8080/sp/SAML2/POST/ACS" index="4"/>
         <AssertionConsumerService Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Artifact" Location="https://localhost:8443/sp/SAML2/Artifact/ACS" index="5"/>
 
-        <AssertionConsumerService Binding="urn:oasis:names:tc:SAML:2.0:bindings:PAOS" Location="https://localhost:8443/sp/SAML2/PAOS/ACS" index="6"/>
+        <AssertionConsumerService Binding="urn:oasis:names:tc:SAML:2.0:bindings:PAOS" Location="http://localhost/sp/SAML2/PAOS/ACS" index="6"/>
+        <AssertionConsumerService Binding="urn:oasis:names:tc:SAML:2.0:bindings:PAOS" Location="https://localhost:8443/sp/SAML2/PAOS/ACS" index="7"/>
         
         <AssertionConsumerService Binding="urn:oasis:names:tc:SAML:1.0:profiles:browser-post" Location="http://localhost:8080/sp/SAML1/POST/ACS" index="9"/>
         <AssertionConsumerService Binding="urn:oasis:names:tc:SAML:1.0:profiles:browser-post" Location="https://localhost:8443/sp/SAML1/POST/ACS" index="10"/>

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list