[java-identity-provider] branch main updated: Add option to allow absent SAMLPeerEntityContext.

Codeberg noreply at shibboleth.net
Wed Nov 11 22:09:07 UTC 2026


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

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

View the commit online:
https://codeberg.org/Shibboleth/java-identity-provider/commit/c8f6e9654911e8ada0deaa338bc09687e26e7812

The following commit(s) were added to refs/heads/main by this push:
     new c8f6e9654 Add option to allow absent SAMLPeerEntityContext.
c8f6e9654 is described below

commit c8f6e9654911e8ada0deaa338bc09687e26e7812
Author: Scott Cantor <scott at restingparrotsoftware.com>
AuthorDate: Wed Nov 11 17:08:46 2026 -0500

    Add option to allow absent SAMLPeerEntityContext.
---
 .../impl/InitializeOutboundMessageContext.java     | 75 ++++++++++++++--------
 .../impl/InitializeOutboundMessageContextTest.java | 32 +++++++--
 2 files changed, 75 insertions(+), 32 deletions(-)

diff --git a/idp-saml-impl/src/main/java/net/shibboleth/idp/saml/profile/impl/InitializeOutboundMessageContext.java b/idp-saml-impl/src/main/java/net/shibboleth/idp/saml/profile/impl/InitializeOutboundMessageContext.java
index 049e4dbb1..0448041ab 100644
--- a/idp-saml-impl/src/main/java/net/shibboleth/idp/saml/profile/impl/InitializeOutboundMessageContext.java
+++ b/idp-saml-impl/src/main/java/net/shibboleth/idp/saml/profile/impl/InitializeOutboundMessageContext.java
@@ -38,7 +38,7 @@ import net.shibboleth.shared.logic.Constraint;
 import net.shibboleth.shared.primitive.LoggerFactory;
 
 /**
- * Action that adds an outbound {@link MessageContext} and related SAML contexts to the {@link ProfileRequestContext}
+ * Action that adds an outbound {@link MessageContext} and SAML entity contexts to the {@link ProfileRequestContext}
  * based on the identity of a relying party accessed via a lookup strategy, by default an immediate child of the profile
  * request context.
  * 
@@ -48,6 +48,8 @@ import net.shibboleth.shared.primitive.LoggerFactory;
  * that underlies the {@link RelyingPartyContext}.
  * </p>
  * 
+ * <p>The requirement for a peer context may be relaxed with a flag.</p>
+ * 
  * @event {@link org.opensaml.profile.action.EventIds#PROCEED_EVENT_ID}
  * @event {@link IdPEventIds#INVALID_RELYING_PARTY_CTX}
  */
@@ -62,6 +64,9 @@ public class InitializeOutboundMessageContext extends AbstractProfileAction {
     /** Strategy used to obtain the self identity value. */
     @Nonnull private Function<ProfileRequestContext, String> selfIdentityLookupStrategy;
 
+    /** Flag controlling behavior if a {@link SAMLPeerEntityContext} is absent. */
+    private boolean requirePeerContext;
+    
     /** The {@link SAMLPeerEntityContext} to base the outbound context on. */
     @NonnullBeforeExec private SAMLPeerEntityContext peerEntityCtx;
 
@@ -69,6 +74,8 @@ public class InitializeOutboundMessageContext extends AbstractProfileAction {
     public InitializeOutboundMessageContext() {
         relyingPartyContextLookupStrategy = new ChildContextLookup<>(RelyingPartyContext.class);
         selfIdentityLookupStrategy = new IssuerLookupFunction();
+        
+        requirePeerContext = true;
     }
 
     /**
@@ -92,35 +99,45 @@ public class InitializeOutboundMessageContext extends AbstractProfileAction {
         checkSetterPreconditions();
         selfIdentityLookupStrategy = Constraint.isNotNull(strategy, "Self identity lookup strategy cannot be null");
     }
+    
+    /**
+     * Sets whether to require the existence of a {@link SAMLPeerEntityContext}.
+     * 
+     * <p>Defaults to true.</p>
+     * 
+     * @since 5.3.0
+     * 
+     * @param flag flag to set
+     */
+    public void setRequirePeerContext(final boolean flag) {
+        checkSetterPreconditions();
+        requirePeerContext = flag;
+    }
 
     /** {@inheritDoc} */
-    @Override protected boolean doPreExecute(@Nonnull final ProfileRequestContext profileRequestContext) {
+    @Override
+    protected boolean doPreExecute(@Nonnull final ProfileRequestContext profileRequestContext) {
 
         if (!super.doPreExecute(profileRequestContext)) {
             return false;
         }
         
         final RelyingPartyContext relyingPartyCtx = relyingPartyContextLookupStrategy.apply(profileRequestContext);
-        if (relyingPartyCtx == null) {
-            log.debug("{} No relying party context", getLogPrefix());
-            ActionSupport.buildEvent(profileRequestContext, IdPEventIds.INVALID_RELYING_PARTY_CTX);
-            return false;
-        }
-
-        final BaseContext identifyingCtx = relyingPartyCtx.getRelyingPartyIdContextTree();
-        if (identifyingCtx == null || !(identifyingCtx instanceof SAMLPeerEntityContext)) {
+        final BaseContext identifyingCtx = relyingPartyCtx != null ? relyingPartyCtx.getRelyingPartyIdContextTree() : null;
+        if (identifyingCtx instanceof SAMLPeerEntityContext peer) {
+            peerEntityCtx = peer;
+        } else if (requirePeerContext) {
             log.debug("{} No SAML peer entity context found via relying party context", getLogPrefix());
             ActionSupport.buildEvent(profileRequestContext, IdPEventIds.INVALID_RELYING_PARTY_CTX);
             return false;
         }
-
-        peerEntityCtx = (SAMLPeerEntityContext) identifyingCtx;
-
+        
         return true;
     }
 
     /** {@inheritDoc} */
-    @Override protected void doExecute(@Nonnull final ProfileRequestContext profileRequestContext) {
+    @Override
+    protected void doExecute(@Nonnull final ProfileRequestContext profileRequestContext) {
 
         final MessageContext msgCtx = new MessageContext();
         profileRequestContext.setOutboundMessageContext(msgCtx);
@@ -128,22 +145,24 @@ public class InitializeOutboundMessageContext extends AbstractProfileAction {
         final SAMLSelfEntityContext selfContext = msgCtx.ensureSubcontext(SAMLSelfEntityContext.class);
         selfContext.setEntityId(selfIdentityLookupStrategy.apply(profileRequestContext));
 
-        final SAMLPeerEntityContext peerContext = msgCtx.ensureSubcontext(SAMLPeerEntityContext.class);
-        peerContext.setEntityId(peerEntityCtx.getEntityId());
-
-        final SAMLMetadataContext inboundMetadataCtx = peerEntityCtx.getSubcontext(SAMLMetadataContext.class);
-        if (inboundMetadataCtx != null) {
-            final SAMLMetadataContext outboundMetadataCtx = peerContext.ensureSubcontext(SAMLMetadataContext.class);
-            outboundMetadataCtx.setEntityDescriptor(inboundMetadataCtx.getEntityDescriptor());
-            outboundMetadataCtx.setRoleDescriptor(inboundMetadataCtx.getRoleDescriptor());
-            final AttributeConsumingServiceContext acsCtx =
-                    inboundMetadataCtx.getSubcontext(AttributeConsumingServiceContext.class);
-            if (null != acsCtx) {
-                outboundMetadataCtx.ensureSubcontext(AttributeConsumingServiceContext.class)
-                        .setAttributeConsumingService(acsCtx.getAttributeConsumingService());
+        if (peerEntityCtx != null) {
+            final SAMLPeerEntityContext peerContext = msgCtx.ensureSubcontext(SAMLPeerEntityContext.class);
+            peerContext.setEntityId(peerEntityCtx.getEntityId());
+    
+            final SAMLMetadataContext inboundMetadataCtx = peerEntityCtx.getSubcontext(SAMLMetadataContext.class);
+            if (inboundMetadataCtx != null) {
+                final SAMLMetadataContext outboundMetadataCtx = peerContext.ensureSubcontext(SAMLMetadataContext.class);
+                outboundMetadataCtx.setEntityDescriptor(inboundMetadataCtx.getEntityDescriptor());
+                outboundMetadataCtx.setRoleDescriptor(inboundMetadataCtx.getRoleDescriptor());
+                final AttributeConsumingServiceContext acsCtx =
+                        inboundMetadataCtx.getSubcontext(AttributeConsumingServiceContext.class);
+                if (null != acsCtx) {
+                    outboundMetadataCtx.ensureSubcontext(AttributeConsumingServiceContext.class)
+                            .setAttributeConsumingService(acsCtx.getAttributeConsumingService());
+                }
             }
         }
-
+        
         log.debug("{} Initialized outbound message context", getLogPrefix());
     }
 }
\ No newline at end of file
diff --git a/idp-saml-impl/src/test/java/net/shibboleth/idp/saml/profile/impl/InitializeOutboundMessageContextTest.java b/idp-saml-impl/src/test/java/net/shibboleth/idp/saml/profile/impl/InitializeOutboundMessageContextTest.java
index cbfd06ea8..6a1158acf 100644
--- a/idp-saml-impl/src/test/java/net/shibboleth/idp/saml/profile/impl/InitializeOutboundMessageContextTest.java
+++ b/idp-saml-impl/src/test/java/net/shibboleth/idp/saml/profile/impl/InitializeOutboundMessageContextTest.java
@@ -56,18 +56,42 @@ public class InitializeOutboundMessageContextTest extends OpenSAMLInitBaseTestCa
         action.initialize();
     }
 
-    @Test public void testNoRelyingPartyContext() {
+    @Test public void testNoRelyingPartyContext() throws ComponentInitializationException {
         prc.removeSubcontext(RelyingPartyContext.class);
 
-        final Event event = action.execute(src);
+        Event event = action.execute(src);
         ActionTestingSupport.assertEvent(event, IdPEventIds.INVALID_RELYING_PARTY_CTX);
         Assert.assertNull(prc.getOutboundMessageContext());
+        
+        // Now with flag turned off.
+        
+        action = new InitializeOutboundMessageContext();
+        action.setRequirePeerContext(false);
+        action.initialize();
+
+        event = action.execute(src);
+        ActionTestingSupport.assertProceedEvent(event);
+        final MessageContext omc = prc.getOutboundMessageContext();
+        assert omc!=null;
+        Assert.assertNull(omc.getSubcontext(SAMLPeerEntityContext.class));
     }
 
-    @Test public void testNoPeerEntityContext() {
-        final Event event = action.execute(src);
+    @Test public void testNoPeerEntityContext() throws ComponentInitializationException {
+        Event event = action.execute(src);
         ActionTestingSupport.assertEvent(event, IdPEventIds.INVALID_RELYING_PARTY_CTX);
         Assert.assertNull(prc.getOutboundMessageContext());
+        
+        // Now with flag turned off.
+        
+        action = new InitializeOutboundMessageContext();
+        action.setRequirePeerContext(false);
+        action.initialize();
+
+        event = action.execute(src);
+        ActionTestingSupport.assertProceedEvent(event);
+        final MessageContext omc = prc.getOutboundMessageContext();
+        assert omc!=null;
+        Assert.assertNull(omc.getSubcontext(SAMLPeerEntityContext.class));
     }
 
     @Test public void testPeerEntityContextNoIssuer() {

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


More information about the commits mailing list