[java-opensaml] branch main updated: IDP-1748 - Allow SubjectConfirmationData Address to be disabled

Scott Cantor cantor.2 at osu.edu
Thu Mar 11 20:40:24 UTC 2021


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

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

View the commit online:
http://git.shibboleth.net/view/?p=java-opensaml.git;a=commit;h=a02253629f8d79592f9a22757c3ec486db6fccd9

The following commit(s) were added to refs/heads/main by this push:
       new  a02253629 IDP-1748 - Allow SubjectConfirmationData Address to be disabled
a02253629 is described below

commit a02253629f8d79592f9a22757c3ec486db6fccd9
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Thu Mar 11 15:39:46 2021 -0500

    IDP-1748 - Allow SubjectConfirmationData Address to be disabled
    
    https://issues.shibboleth.net/jira/browse/IDP-1748
    
    Rework address lookup strategy for optional Spring injection.
---
 .../impl/AddSubjectConfirmationToSubjects.java     | 41 +++++++++++++---------
 .../impl/AddSubjectConfirmationToSubjectsTest.java | 24 ++++++++++++-
 2 files changed, 48 insertions(+), 17 deletions(-)

diff --git a/opensaml-saml-impl/src/main/java/org/opensaml/saml/saml2/profile/impl/AddSubjectConfirmationToSubjects.java b/opensaml-saml-impl/src/main/java/org/opensaml/saml/saml2/profile/impl/AddSubjectConfirmationToSubjects.java
index 3a8c72195..82581fb82 100644
--- a/opensaml-saml-impl/src/main/java/org/opensaml/saml/saml2/profile/impl/AddSubjectConfirmationToSubjects.java
+++ b/opensaml-saml-impl/src/main/java/org/opensaml/saml/saml2/profile/impl/AddSubjectConfirmationToSubjects.java
@@ -86,8 +86,8 @@ public class AddSubjectConfirmationToSubjects extends AbstractProfileAction {
     /** Strategy used to locate the {@link Response} to operate on. */
     @Nonnull private Function<ProfileRequestContext,Response> responseLookupStrategy;
     
-    /** Optional strategy to obtain value for {@link SubjectConfirmationData#getAddress()}. */
-    @Nullable private Function<ProfileRequestContext,String> addressLookupStrategy;
+    /** Strategy to obtain value for {@link SubjectConfirmationData#getAddress()}. */
+    @NonnullAfterInit private Function<ProfileRequestContext,String> addressLookupStrategy;
 
     /** Optional strategy to obtain value for {@link SubjectConfirmationData#getInResponseTo()}. */
     @Nullable private Function<ProfileRequestContext,String> inResponseToLookupStrategy;
@@ -117,18 +117,7 @@ public class AddSubjectConfirmationToSubjects extends AbstractProfileAction {
                         SubjectConfirmationData.DEFAULT_ELEMENT_NAME);
         overwriteExisting = true;
         responseLookupStrategy = new MessageLookup<>(Response.class).compose(new OutboundMessageContextLookup());
-        
-        // Default pulls from servlet request.
-        addressLookupStrategy = new Function<>() {
-            public String apply(final ProfileRequestContext input) {
-                final String address = getHttpServletRequest() != null ?
-                        HttpServletSupport.getRemoteAddr(getHttpServletRequest()) : null;
-                log.debug("{} Setting confirmation data Address to {}", getLogPrefix(),
-                        address != null ? address : "(none)");
-                return address;
-            }
-        };
-        
+                
         // Default pulls from inbound message context and a SAMLMessageInfoContext child.
         inResponseToLookupStrategy = new Function<>() {
             public String apply(final ProfileRequestContext input) {
@@ -258,6 +247,10 @@ public class AddSubjectConfirmationToSubjects extends AbstractProfileAction {
         if (confirmationMethod == null) {
             throw new ComponentInitializationException("Confirmation method cannot be null or empty");
         }
+
+        if (addressLookupStrategy == null) {
+            addressLookupStrategy = new RemoteAddressStrategy();
+        }
     }
     
     /** {@inheritDoc} */
@@ -288,8 +281,7 @@ public class AddSubjectConfirmationToSubjects extends AbstractProfileAction {
         
         SubjectConfirmationData confirmationData = null;
         
-        final String address = addressLookupStrategy != null
-                ? addressLookupStrategy.apply(profileRequestContext) : null;
+        final String address = addressLookupStrategy.apply(profileRequestContext);
         if (address != null) {
             confirmationData = confirmationData != null ? confirmationData : confirmationDataBuilder.buildObject();
             confirmationData.setAddress(address);
@@ -380,4 +372,21 @@ public class AddSubjectConfirmationToSubjects extends AbstractProfileAction {
         return clone;
     }
     
+    /**
+     * Default strategy for obtaining client address from servlet layer.
+     * 
+     * @since 4.1.0
+     */
+    private class RemoteAddressStrategy implements Function<ProfileRequestContext,String> {
+
+        /** {@inheritDoc} */
+        @Nullable public String apply(@Nullable final ProfileRequestContext t) {
+            if (getHttpServletRequest() != null) {
+                return HttpServletSupport.getRemoteAddr(getHttpServletRequest());
+            }
+            
+            return null;
+        }
+        
+    }
 }
\ No newline at end of file
diff --git a/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/profile/impl/AddSubjectConfirmationToSubjectsTest.java b/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/profile/impl/AddSubjectConfirmationToSubjectsTest.java
index 063ad12bd..4e1556fbc 100644
--- a/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/profile/impl/AddSubjectConfirmationToSubjectsTest.java
+++ b/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/profile/impl/AddSubjectConfirmationToSubjectsTest.java
@@ -18,6 +18,7 @@
 package org.opensaml.saml.saml2.profile.impl;
 
 import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
+import net.shibboleth.utilities.java.support.logic.FunctionSupport;
 
 import org.opensaml.core.testing.OpenSAMLInitBaseTestCase;
 import org.opensaml.profile.action.EventIds;
@@ -39,6 +40,7 @@ import org.testng.annotations.Test;
 
 
 /** Test for {@link AddSubjectConfirmationToSubjects}. */
+ at SuppressWarnings("javadoc")
 public class AddSubjectConfirmationToSubjectsTest extends OpenSAMLInitBaseTestCase {
     
     private ProfileRequestContext prc;
@@ -106,7 +108,27 @@ public class AddSubjectConfirmationToSubjectsTest extends OpenSAMLInitBaseTestCa
         Assert.assertEquals(data.getAddress(), "127.0.0.1");
         Assert.assertEquals(data.getInResponseTo(), ((AuthnRequest) prc.getInboundMessageContext().getMessage()).getID());
     }
-    
+
+    @Test void testNoAddress() throws ComponentInitializationException {
+        addAssertions();
+        
+        action.setMethod(SubjectConfirmation.METHOD_BEARER);
+        action.setAddressLookupStrategy(FunctionSupport.constant(null));
+        action.initialize();
+        
+        action.execute(prc);
+        ActionTestingSupport.assertProceedEvent(prc);
+        
+        final Assertion assertion = ((Response) prc.getOutboundMessageContext().getMessage()).getAssertions().get(0);
+        final Subject subject = assertion.getSubject();
+        Assert.assertNotNull(subject);
+        Assert.assertEquals(subject.getSubjectConfirmations().size(), 1);
+        
+        final SubjectConfirmationData data = subject.getSubjectConfirmations().get(0).getSubjectConfirmationData();
+        Assert.assertNotNull(data);
+        Assert.assertNull(data.getAddress());
+    }
+
     /** Set up the test message with some assertions. */
     private void addAssertions() {
         final Response response = SAML2ActionTestingSupport.buildResponse();

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


More information about the commits mailing list