[java-identity-provider COMMIT] /trunk/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/FilterAttribute...

noreply at shibboleth.net noreply at shibboleth.net
Wed Feb 19 21:53:02 EST 2014


Author: scantor
Date: Wed Feb 19 21:53:02 2014
New Revision: 5409

URL: http://svn.shibboleth.net/view/java-identity-provider?rev=5409&view=rev
Log:
Save some code using function composition.

Modified:
    trunk/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/FilterAttributes.java

Modified: trunk/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/FilterAttributes.java
URL: http://svn.shibboleth.net/view/java-identity-provider/trunk/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/FilterAttributes.java?rev=5409&r1=5408&r2=5409&view=diff
==============================================================================
--- trunk/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/FilterAttributes.java (original)
+++ trunk/idp-profile-impl/src/main/java/net/shibboleth/idp/profile/impl/FilterAttributes.java Wed Feb 19 21:53:02 2014
@@ -37,18 +37,19 @@
 import net.shibboleth.utilities.java.support.logic.Constraint;
 
 import org.opensaml.messaging.context.BaseContext;
-import org.opensaml.messaging.context.MessageContext;
 import org.opensaml.messaging.context.navigate.ChildContextLookup;
 import org.opensaml.messaging.context.navigate.ContextDataLookupFunction;
 import org.opensaml.profile.ProfileException;
 import org.opensaml.profile.action.ActionSupport;
 import org.opensaml.profile.context.ProfileRequestContext;
+import org.opensaml.profile.context.navigate.InboundMessageContextLookup;
 import org.opensaml.saml.common.messaging.context.SAMLMetadataContext;
 import org.opensaml.saml.common.messaging.context.SAMLPeerEntityContext;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import com.google.common.base.Function;
+import com.google.common.base.Functions;
 
 /**
  * Action that invokes the {@link AttributeFilter} for the current request.
@@ -118,7 +119,12 @@
         relyingPartyContextLookupStrategy = new ChildContextLookup<>(RelyingPartyContext.class, false);
         subjectContextLookupStrategy = new ChildContextLookup<>(SubjectContext.class, false);
         authnContextLookupStrategy = new ChildContextLookup<>(AuthenticationContext.class, false);
-        metadataContextLookupStrategy = new DefaultMetadataLookup();
+        
+        // Default: inbound msg context -> SAMLPeerEntityContext -> SAMLMetadataContext
+        metadataContextLookupStrategy = Functions.compose(
+                new ChildContextLookup<>(SAMLMetadataContext.class),
+                Functions.compose(new ChildContextLookup<>(SAMLPeerEntityContext.class),
+                        new InboundMessageContextLookup()));
         metadataFromFilterLookupStrategy = new MetadataLookupFromFilterContext(metadataContextLookupStrategy);
     }
 
@@ -283,37 +289,6 @@
     }
 
     /**
-     * Default implementation of the lookup from Profile Request to SAML Metadata.
-     * 
-     */
-    protected static class DefaultMetadataLookup implements
-            ContextDataLookupFunction<ProfileRequestContext, SAMLMetadataContext> {
-
-        /**
-         * By default the SAML Metadata Context is the child of the incoming MessageContext's SAMLPeerEntityContext
-         * child.
-         * 
-         * TODO(rdw) This navigation is subject to change
-         * 
-         * {@inheritDoc}
-         */
-        @Override @Nullable public SAMLMetadataContext apply(@Nullable final ProfileRequestContext input) {
-            if (null == input) {
-                return null;
-            }
-            final MessageContext<?> messageContext = input.getInboundMessageContext();
-            if (null == messageContext) {
-                return null;
-            }
-            SAMLPeerEntityContext peerContext = messageContext.getSubcontext(SAMLPeerEntityContext.class, false);
-            if (null == peerContext) {
-                return null;
-            }
-            return peerContext.getSubcontext(SAMLMetadataContext.class, false);
-        }
-    }
-
-    /**
      * Class to go from a {@link AttributeFilterContext} to a {@link SAMLMetadataContext). We know how to get to a
      * 
      * @link ProfileRequestContext) from a {@link AttributeFilterContext} because we set it up, and we are told how to



More information about the commits mailing list