[java-identity-provider COMMIT] /trunk/idp-saml-impl/src/main/java/net/shibboleth/idp/saml/profile/logic/EntitiesDesc...
noreply at shibboleth.net
noreply at shibboleth.net
Thu May 29 18:53:53 EDT 2014
Author: scantor
Date: Thu May 29 18:53:52 2014
New Revision: 6000
URL: http://svn.shibboleth.net/view/java-identity-provider?rev=6000&view=rev
Log:
Predicate for EntitiesDescriptor membership.
Modified:
trunk/idp-saml-impl/src/main/java/net/shibboleth/idp/saml/profile/logic/EntitiesDescriptorPredicate.java
Modified: trunk/idp-saml-impl/src/main/java/net/shibboleth/idp/saml/profile/logic/EntitiesDescriptorPredicate.java
URL: http://svn.shibboleth.net/view/java-identity-provider/trunk/idp-saml-impl/src/main/java/net/shibboleth/idp/saml/profile/logic/EntitiesDescriptorPredicate.java?rev=6000&r1=5999&r2=6000&view=diff
==============================================================================
--- trunk/idp-saml-impl/src/main/java/net/shibboleth/idp/saml/profile/logic/EntitiesDescriptorPredicate.java (original)
+++ trunk/idp-saml-impl/src/main/java/net/shibboleth/idp/saml/profile/logic/EntitiesDescriptorPredicate.java Thu May 29 18:53:52 2014
@@ -20,12 +20,22 @@
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
+import net.shibboleth.idp.profile.context.RelyingPartyContext;
import net.shibboleth.utilities.java.support.annotation.constraint.NotEmpty;
import net.shibboleth.utilities.java.support.logic.Constraint;
import net.shibboleth.utilities.java.support.primitive.StringSupport;
+import org.opensaml.core.xml.XMLObject;
+import org.opensaml.messaging.context.BaseContext;
+import org.opensaml.messaging.context.navigate.ChildContextLookup;
+import org.opensaml.messaging.context.navigate.ContextDataLookupFunction;
import org.opensaml.profile.context.ProfileRequestContext;
+import org.opensaml.saml.common.messaging.context.SAMLMetadataContext;
+import org.opensaml.saml.common.messaging.context.SAMLPeerEntityContext;
+import org.opensaml.saml.saml2.metadata.EntitiesDescriptor;
+import com.google.common.base.Function;
+import com.google.common.base.Functions;
import com.google.common.base.Predicate;
/**
@@ -33,7 +43,10 @@
* {@link EntitiesDescriptor} groups.
*/
public class EntitiesDescriptorPredicate implements Predicate<ProfileRequestContext> {
-
+
+ /** Strategy function to lookup SAMLMetadataContext. */
+ @Nonnull private Function<ProfileRequestContext,SAMLMetadataContext> metadataContextLookupStrategy;
+
/** Group to match. */
@Nonnull @NotEmpty private final String groupName;
@@ -44,12 +57,60 @@
*/
public EntitiesDescriptorPredicate(@Nonnull @NotEmpty final String name) {
groupName = Constraint.isNotNull(StringSupport.trimOrNull(name), "Group name cannot be null or empty");
+
+ // Default is PRC -> RPC -> SAML Peer -> Metadata
+ metadataContextLookupStrategy = Functions.compose(
+ Functions.compose(new ChildContextLookup<>(SAMLMetadataContext.class), new SAMLPeerEntityLookup()),
+ new ChildContextLookup<ProfileRequestContext,RelyingPartyContext>(RelyingPartyContext.class));
+ }
+
+ /**
+ * Set the lookup strategy to use to locate the {@link SAMLMetadataContext}.
+ *
+ * @param strategy lookup function to use
+ */
+ public synchronized void setMetadataContextLookupStrategy(
+ @Nonnull final Function<ProfileRequestContext,SAMLMetadataContext> strategy) {
+
+ metadataContextLookupStrategy =
+ Constraint.isNotNull(strategy, "SAMLMetadataContext lookup strategy cannot be null");
}
/** {@inheritDoc} */
- @Override public boolean apply(@Nullable ProfileRequestContext arg0) {
- // TODO
+ @Override
+ public boolean apply(@Nullable final ProfileRequestContext input) {
+ final SAMLMetadataContext metadataCtx = metadataContextLookupStrategy.apply(input);
+ if (metadataCtx != null && metadataCtx.getEntityDescriptor() != null) {
+ XMLObject group = metadataCtx.getEntityDescriptor().getParent();
+ while (group != null && group instanceof EntitiesDescriptor) {
+ if (((EntitiesDescriptor) group).getName() != null
+ && groupName.equals(((EntitiesDescriptor) group).getName())) {
+ return true;
+ }
+ group = group.getParent();
+ }
+ }
+
return false;
+ }
+
+ /** A function to access a SAMLPeerEntityContext underlying a RelyingPartyContext. */
+ private class SAMLPeerEntityLookup implements ContextDataLookupFunction<RelyingPartyContext,SAMLPeerEntityContext> {
+
+ /** {@inheritDoc} */
+ @Override
+ @Nullable public SAMLPeerEntityContext apply(@Nullable final RelyingPartyContext input) {
+
+ if (input != null) {
+ final BaseContext peer = input.getRelyingPartyIdContextTree();
+ if (peer != null && peer instanceof SAMLPeerEntityContext) {
+ return (SAMLPeerEntityContext) peer;
+ }
+ }
+
+ return null;
+ }
[... 5 lines stripped ...]
More information about the commits
mailing list