[java-plugin-shibd-saml] branch main updated: Wiring and bug fixes to metadata flow, initial tests.
Codeberg
noreply at shibboleth.net
Wed Nov 11 16:11:20 UTC 2026
This is an automated email from the git hooks/post-receive script.
codeberg pushed a commit to branch main
in repository java-plugin-shibd-saml.
View the commit online:
https://codeberg.org/Shibboleth/java-plugin-shibd-saml/commit/5149c14ef7db58b6ac79dc948cd1cf16d340f2a4
The following commit(s) were added to refs/heads/main by this push:
new 5149c14 Wiring and bug fixes to metadata flow, initial tests.
5149c14 is described below
commit 5149c14ef7db58b6ac79dc948cd1cf16d340f2a4
Author: Scott Cantor <scott at restingparrotsoftware.com>
AuthorDate: Wed Nov 11 11:10:51 2026 -0500
Wiring and bug fixes to metadata flow, initial tests.
---
.../idp/flows/sp/metadata/saml2/saml2-beans.xml | 7 +-
.../idp/flows/sp/metadata/saml2/saml2-flow.xml | 8 +
.../sp/saml/flows/saml2/MetadataFlowTest.java | 218 +++++++++++++++++++++
.../idp/module/conf/sp/saml-test-agents.xml | 8 +-
4 files changed, 238 insertions(+), 3 deletions(-)
diff --git a/sp-saml-conf-impl/src/main/resources/META-INF/net/shibboleth/idp/flows/sp/metadata/saml2/saml2-beans.xml b/sp-saml-conf-impl/src/main/resources/META-INF/net/shibboleth/idp/flows/sp/metadata/saml2/saml2-beans.xml
index 0050229..8f16528 100644
--- a/sp-saml-conf-impl/src/main/resources/META-INF/net/shibboleth/idp/flows/sp/metadata/saml2/saml2-beans.xml
+++ b/sp-saml-conf-impl/src/main/resources/META-INF/net/shibboleth/idp/flows/sp/metadata/saml2/saml2-beans.xml
@@ -19,6 +19,8 @@
<util:constant id="shibboleth.metrics.ProfileCounter"
static-field="net.shibboleth.sp.saml.saml2.profile.config.impl.MetadataPublishingProfileConfiguration.PROFILE_COUNTER" />
+ <import resource="classpath:/META-INF/net/shibboleth/idp/flows/sp/saml2-common-beans.xml" />
+
<!-- This is a convenience as it does what is needed for this flow also. -->
<bean id="ValidateSessionInitiatorRequest"
class="net.shibboleth.sp.profile.impl.ValidateSessionInitiatorRequest" scope="prototype"
@@ -42,7 +44,8 @@
<bean id="AddMetadata"
class="net.shibboleth.sp.saml.saml2.profile.impl.AddMetadata" scope="prototype"
- p:velocityEngine-ref="shibboleth.VelocityEngine" />
+ p:velocityEngine-ref="shibboleth.VelocityEngine"
+ p:parserPool-ref="shibboleth.ParserPool" />
<bean id="SignMetadata"
class="net.shibboleth.idp.profile.impl.WebFlowMessageHandlerAdaptor" scope="prototype"
@@ -61,7 +64,7 @@
p:messageEncoderFactory-ref="metadataEncoderFactory" />
<bean id="metadataEncoderFactory" parent="shibboleth.Functions.Expression"
- c:_0="#{getObject('metadataEncoder')}"
+ c:_0="getObject('metadataEncoder')"
p:outputType="org.opensaml.messaging.encoder.MessageEncoder" />
<bean id="metadataEncoder"
diff --git a/sp-saml-conf-impl/src/main/resources/META-INF/net/shibboleth/idp/flows/sp/metadata/saml2/saml2-flow.xml b/sp-saml-conf-impl/src/main/resources/META-INF/net/shibboleth/idp/flows/sp/metadata/saml2/saml2-flow.xml
index 3daf5ca..854c21d 100644
--- a/sp-saml-conf-impl/src/main/resources/META-INF/net/shibboleth/idp/flows/sp/metadata/saml2/saml2-flow.xml
+++ b/sp-saml-conf-impl/src/main/resources/META-INF/net/shibboleth/idp/flows/sp/metadata/saml2/saml2-flow.xml
@@ -3,6 +3,14 @@
xsi:schemaLocation="http://www.springframework.org/schema/webflow http://www.springframework.org/schema/webflow/spring-webflow.xsd"
parent="sp/application">
+ <action-state id="InitializeProfileRequestContext">
+ <evaluate expression="InitializeProfileRequestContext" />
+ <evaluate expression="'proceed'" />
+
+ <!-- Branch to parent flow for authentication. -->
+ <transition on="proceed" to="AuthenticationSetup" />
+ </action-state>
+
<action-state id="DoApplicationOperation">
<evaluate expression="ValidateSessionInitiatorRequest" />
<evaluate expression="PrepareInboundMessageContext" />
diff --git a/sp-saml-conf-impl/src/test/java/net/shibboleth/sp/saml/flows/saml2/MetadataFlowTest.java b/sp-saml-conf-impl/src/test/java/net/shibboleth/sp/saml/flows/saml2/MetadataFlowTest.java
new file mode 100644
index 0000000..8ae25bd
--- /dev/null
+++ b/sp-saml-conf-impl/src/test/java/net/shibboleth/sp/saml/flows/saml2/MetadataFlowTest.java
@@ -0,0 +1,218 @@
+/*
+ * Licensed 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.sp.saml.flows.saml2;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.time.Instant;
+import java.util.List;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
+import org.opensaml.core.xml.XMLObject;
+import org.opensaml.core.xml.util.XMLObjectSupport;
+import org.opensaml.messaging.context.MessageContext;
+import org.opensaml.messaging.decoder.MessageDecodingException;
+import org.opensaml.profile.action.EventIds;
+import org.opensaml.profile.context.ProfileRequestContext;
+import org.opensaml.saml.common.SAMLObject;
+import org.opensaml.saml.common.binding.SAMLBindingSupport;
+import org.opensaml.saml.common.profile.SAMLEventIds;
+import org.opensaml.saml.common.xml.SAMLConstants;
+import org.opensaml.saml.saml2.binding.decoding.impl.HTTPRedirectDeflateDecoder;
+import org.opensaml.saml.saml2.core.AuthnContext;
+import org.opensaml.saml.saml2.core.AuthnContextComparisonTypeEnumeration;
+import org.opensaml.saml.saml2.core.AuthnRequest;
+import org.opensaml.saml.saml2.core.Issuer;
+import org.opensaml.saml.saml2.core.NameIDPolicy;
+import org.opensaml.saml.saml2.core.NameIDType;
+import org.opensaml.saml.saml2.core.RequestedAuthnContext;
+import org.opensaml.saml.saml2.metadata.EntityDescriptor;
+import org.opensaml.security.credential.Credential;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.mock.web.MockHttpServletRequest;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.web.WebAppConfiguration;
+import org.springframework.webflow.executor.FlowExecutionResult;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+import net.shibboleth.idp.authn.AuthnEventIds;
+import net.shibboleth.idp.profile.IdPEventIds;
+import net.shibboleth.idp.spring.IdPPropertiesApplicationContextInitializer;
+import net.shibboleth.idp.test.PreferFileSystemApplicationContextInitializer;
+import net.shibboleth.shared.collection.Pair;
+import net.shibboleth.shared.component.ComponentInitializationException;
+import net.shibboleth.shared.net.URISupport;
+import net.shibboleth.shared.primitive.NonnullSupplier;
+import net.shibboleth.shared.xml.ParserPool;
+import net.shibboleth.sp.context.AgentRequestContext;
+import net.shibboleth.sp.ddf.DDF;
+import net.shibboleth.sp.flows.AbstractSPFlowTest;
+import net.shibboleth.sp.messaging.RemotedHttpServletRequest;
+import net.shibboleth.sp.messaging.RemotedHttpServletResponse;
+import net.shibboleth.sp.profile.InitiatorConstants;
+import net.shibboleth.sp.profile.SPConstants;
+import net.shibboleth.sp.saml.saml2.profile.SAML2InitiatorConstants;
+
+/**
+ * Unit test for the metadata publishing flow.
+ */
+ at ContextConfiguration(
+ locations = {
+ "classpath:/net/shibboleth/sp/saml-test-beans.xml",
+ },
+ initializers = {
+ TestSPSAMLEnvironmentApplicationContextInitializer.class,
+ PreferFileSystemApplicationContextInitializer.class,
+ IdPPropertiesApplicationContextInitializer.class
+ },
+ inheritInitializers = false
+ )
+ at WebAppConfiguration
+public class MetadataFlowTest extends AbstractSPFlowTest {
+
+ /** Flow ID. */
+ @Nonnull public static final String FLOW_ID = "sp/metadata/saml2";
+
+ /** Issuer value. */
+ @Nonnull public static final String ISSUER = "https://testsp.example.org";
+
+
+ /** Parser pool. */
+ @Autowired
+ @Qualifier("shibboleth.ParserPool")
+ protected ParserPool parserPool;
+
+ /** Constructor. */
+ protected MetadataFlowTest() {
+ super(FLOW_ID);
+ }
+
+ /**
+ * Test flow with profile disallowed.
+ *
+ * @throws IOException
+ */
+ @Test
+ public void testProfileDisabled() throws IOException {
+ setDefaultAuth();
+
+ final DDF input = new DDF(null).structure();
+ input.addmember(RemotedHttpServletRequest.STRUCTURE_NAME).structure();
+ setApplicationRequest("no-profile", input);
+
+ final FlowExecutionResult result = flowExecutor.launchExecution(FLOW_ID, null, externalContext);
+ assertFlowExecutionResult(result, FLOW_ID);
+ assertFlowExecutionOutcome(result.getOutcome());
+ assertOutputMessageEvent(result, IdPEventIds.INVALID_PROFILE_CONFIG);
+ }
+
+ /**
+ * Test flow with verified IdP but no metadata via resolver.
+ *
+ * @throws IOException
+ */
+ @Test
+ public void testNoMetadataViaResolverVerified() throws IOException {
+ setDefaultAuth();
+
+ final DDF input = new DDF(null).structure();
+ input.addmember(RemotedHttpServletRequest.STRUCTURE_NAME).structure();
+ setApplicationRequest(APPLICATION_ID, input);
+
+ final FlowExecutionResult result = flowExecutor.launchExecution(FLOW_ID, null, externalContext);
+ assertFlowExecutionResult(result, FLOW_ID);
+ assertFlowExecutionOutcome(result.getOutcome());
+ assertOutputMessageEvent(result, EventIds.MESSAGE_PROC_ERROR);
+ }
+
+ /**
+ * Test flow with unverified IdP but no metadata via resolver.
+ *
+ * @throws IOException
+ */
+ @Test
+ public void testNoMetadataViaResolverUnverified() throws IOException {
+ setDefaultAuth();
+
+ final DDF input = new DDF(null).structure();
+ input.addmember(RemotedHttpServletRequest.STRUCTURE_NAME).structure();
+ setApplicationRequest("no-metadata", input);
+
+ final FlowExecutionResult result = flowExecutor.launchExecution(FLOW_ID, null, externalContext);
+ assertFlowExecutionResult(result, FLOW_ID);
+ assertFlowExecutionOutcome(result.getOutcome());
+ assertOutputMessageEvent(result, EventIds.MESSAGE_PROC_ERROR);
+ }
+
+ /**
+ * Test flow with absent IdP but no metadata via resolver.
+ *
+ * @throws IOException
+ */
+ @Test
+ public void testNoAuthorityViaResolverUnverified() throws IOException {
+ setDefaultAuth();
+
+ final DDF input = new DDF(null).structure();
+ input.addmember(RemotedHttpServletRequest.STRUCTURE_NAME).structure();
+ setApplicationRequest("no-authority", input);
+
+ final FlowExecutionResult result = flowExecutor.launchExecution(FLOW_ID, null, externalContext);
+ assertFlowExecutionResult(result, FLOW_ID);
+ assertFlowExecutionOutcome(result.getOutcome());
+ assertOutputMessageEvent(result, EventIds.MESSAGE_PROC_ERROR);
+ }
+
+ /**
+ * Decode returned metadata and run sanity checks against it.
+ *
+ * @param result flow execution result
+ *
+ * @return the request object
+ *
+ * @throws Exception
+ */
+ @Nonnull private EntityDescriptor validateOutputMessage(@Nonnull final FlowExecutionResult result) throws Exception {
+ final ProfileRequestContext prc = retrieveProfileRequestContext(result);
+ assert prc != null;
+ final AgentRequestContext arc = prc.ensureSubcontext(AgentRequestContext.class);
+ final DDF input = arc.getInput();
+ final DDF output = arc.getOutput();
+ assert input != null;
+ assert output != null;
+ Assert.assertTrue(output.isstruct());
+ final DDF http = output.getmember(RemotedHttpServletResponse.STRUCTURE_NAME);
+ Assert.assertTrue(http.isstruct());
+ Assert.assertEquals(http.getmember("headers.content_type").string(), "application/samlmetadata+xml");
+
+ final byte[] body = http.getmember("response.data").unsafe_string();
+ Assert.assertNotNull(body);
+
+ final EntityDescriptor entity;
+ try (final ByteArrayInputStream in = new ByteArrayInputStream(body)) {
+ final XMLObject xml = XMLObjectSupport.unmarshallFromInputStream(parserPool, in);
+ assert xml instanceof EntityDescriptor;
+ entity = (EntityDescriptor) xml;
+ }
+
+ return entity;
+ }
+
+}
\ No newline at end of file
diff --git a/sp-saml-conf-impl/src/test/resources/net/shibboleth/idp/module/conf/sp/saml-test-agents.xml b/sp-saml-conf-impl/src/test/resources/net/shibboleth/idp/module/conf/sp/saml-test-agents.xml
index de3ea87..1b49ef4 100644
--- a/sp-saml-conf-impl/src/test/resources/net/shibboleth/idp/module/conf/sp/saml-test-agents.xml
+++ b/sp-saml-conf-impl/src/test/resources/net/shibboleth/idp/module/conf/sp/saml-test-agents.xml
@@ -34,6 +34,10 @@
p:authenticatingAuthority="https://unknown.example.org"
p:profileConfigurations-ref="test.ProfileConfigurations" />
+ <bean p:id="no-authority" parent="shibboleth.sp.Application"
+ p:authenticatingAuthority="#{null}"
+ p:profileConfigurations-ref="test.ProfileConfigurations" />
+
<bean p:id="no-profile" parent="shibboleth.sp.Application.NoInheritance"
p:profileConfigurations-ref="test.NoProfileConfigurations"
p:detailedErrors="true" />
@@ -55,7 +59,8 @@
<util:list id="test.ProfileConfigurations">
<ref bean="SAML2.SSO" />
<ref bean="SAML2.ECP" />
- <ref bean="SAML2.Logout"/>
+ <ref bean="SAML2.Logout" />
+ <ref bean="SAML2.Metadata" />
</util:list>
<util:list id="test.responseBindingProfileConfigurations">
@@ -110,6 +115,7 @@
<ref bean="SAML2.ECP" />
<!-- Turn off encryption so tests are easier to validate. -->
<bean parent="SAML2.Logout" p:encryptNameIDs="false" />
+ <ref bean="SAML2.Metadata" />
</util:list>
<!--
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list