[java-identity-provider] branch master updated: Enhance criteria RPC resolver to support metadata tags and groups

Brent Putman putmanb at georgetown.edu
Mon Sep 24 21:39:54 EDT 2018


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

putmanb pushed a commit to branch master
in repository java-identity-provider.

View the commit online:
http://git.shibboleth.net/view/?p=java-identity-provider.git;a=commit;h=532956b39b30b608c11248aded47c30b4f461a0f

The following commit(s) were added to refs/heads/master by this push:
       new  532956b   Enhance criteria RPC resolver to support metadata tags and groups
532956b is described below

commit 532956b39b30b608c11248aded47c30b4f461a0f
Author: Brent Putman <putmanb at georgetown.edu>
AuthorDate: Mon Sep 24 21:39:43 2018 -0400

    Enhance criteria RPC resolver to support metadata tags and groups
---
 ...gCriteriaRelyingPartyConfigurationResolver.java |  75 ++++-
 ...teriaRelyingPartyConfigurationResolverTest.java | 315 +++++++++++++++++++++
 ...atingRelyingPartyConfigurationResolverTest.java | 116 --------
 3 files changed, 379 insertions(+), 127 deletions(-)

diff --git a/idp-profile-impl/src/main/java/net/shibboleth/idp/relyingparty/impl/DelegatingCriteriaRelyingPartyConfigurationResolver.java b/idp-profile-impl/src/main/java/net/shibboleth/idp/relyingparty/impl/DelegatingCriteriaRelyingPartyConfigurationResolver.java
index 65aa413..22a2dae 100644
--- a/idp-profile-impl/src/main/java/net/shibboleth/idp/relyingparty/impl/DelegatingCriteriaRelyingPartyConfigurationResolver.java
+++ b/idp-profile-impl/src/main/java/net/shibboleth/idp/relyingparty/impl/DelegatingCriteriaRelyingPartyConfigurationResolver.java
@@ -25,6 +25,8 @@ import javax.annotation.Nullable;
 
 import org.opensaml.core.criterion.EntityIdCriterion;
 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.criterion.RoleDescriptorCriterion;
 import org.opensaml.saml.saml2.metadata.EntityDescriptor;
 import org.opensaml.saml.saml2.metadata.RoleDescriptor;
@@ -151,14 +153,38 @@ public class DelegatingCriteriaRelyingPartyConfigurationResolver extends Abstrac
         if (criteria == null) {
             return null;
         }
-        
+
         final String entityID = resolveEntityID(criteria);
         log.debug("Resolved effective entityID from criteria: {}", entityID);
-        if (entityID != null) {
+
+        final EntityDescriptor entityDescriptor = resolveEntityDescriptor(criteria);
+        log.debug("Resolved effective entity descriptor from criteria: {}", entityDescriptor);
+
+        final RoleDescriptor roleDescriptor = resolveRoleDescriptor(criteria);
+        log.debug("Resolved effective role descriptor from criteria: {}", roleDescriptor);
+
+        if (entityID != null || entityDescriptor != null || roleDescriptor != null) {
             final ProfileRequestContext prc = new ProfileRequestContext<>();
-            final RelyingPartyContext rp = prc.getSubcontext(RelyingPartyContext.class, true);
-            rp.setRelyingPartyId(entityID);
-            rp.setVerified(true);
+            final RelyingPartyContext rpc = prc.getSubcontext(RelyingPartyContext.class, true);
+            rpc.setVerified(true);
+
+            rpc.setRelyingPartyId(entityID);
+
+            if (entityDescriptor != null || roleDescriptor != null) {
+                final SAMLPeerEntityContext peerContext = prc.getSubcontext(SAMLPeerEntityContext.class, true);
+                rpc.setRelyingPartyIdContextTree(peerContext);
+
+                peerContext.setEntityId(entityID);
+
+                if (roleDescriptor != null) {
+                    peerContext.setRole(roleDescriptor.getSchemaType() != null
+                            ? roleDescriptor.getSchemaType() : roleDescriptor.getElementQName());
+                }
+
+                final SAMLMetadataContext metadataContext = peerContext.getSubcontext(SAMLMetadataContext.class, true);
+                metadataContext.setEntityDescriptor(entityDescriptor);
+                metadataContext.setRoleDescriptor(roleDescriptor);
+            }
             return prc;
         } else {
             return null;
@@ -175,14 +201,41 @@ public class DelegatingCriteriaRelyingPartyConfigurationResolver extends Abstrac
         if (criteria.contains(EntityIdCriterion.class)) {
             return criteria.get(EntityIdCriterion.class).getEntityId();
         }
-        
+
+        final EntityDescriptor ed = resolveEntityDescriptor(criteria);
+        if (ed != null) {
+            return ed.getEntityID();
+        }
+
+        return null;
+    }
+
+    /**
+     * Resolve the EntityDescriptor from the criteria.
+     *
+     * @param criteria the input criteria
+     * @return the input entity descriptor criterion, or null if could not be resolved
+     */
+    private EntityDescriptor resolveEntityDescriptor(@Nonnull final CriteriaSet criteria) {
+        final RoleDescriptor rd = resolveRoleDescriptor(criteria);
+        if (rd != null && rd.getParent() != null && rd.getParent() instanceof EntityDescriptor) {
+            return (EntityDescriptor)rd.getParent();
+        }
+
+        return null;
+    }
+
+    /**
+     * Resolve the RoleDescriptor from the criteria.
+     *
+     * @param criteria the input criteria
+     * @return the input role descriptor criterion or null if could not be resolved
+     */
+    private RoleDescriptor resolveRoleDescriptor(@Nonnull final CriteriaSet criteria) {
         if (criteria.contains(RoleDescriptorCriterion.class)) {
-            final RoleDescriptor rd = criteria.get(RoleDescriptorCriterion.class).getRole();
-            if (rd.getParent() != null && rd.getParent() instanceof EntityDescriptor) {
-                return ((EntityDescriptor)rd.getParent()).getEntityID();
-            }
+            return criteria.get(RoleDescriptorCriterion.class).getRole();
         }
-        
+
         return null;
     }
     
diff --git a/idp-profile-impl/src/test/java/net/shibboleth/idp/relyingparty/impl/DelegatingCriteriaRelyingPartyConfigurationResolverTest.java b/idp-profile-impl/src/test/java/net/shibboleth/idp/relyingparty/impl/DelegatingCriteriaRelyingPartyConfigurationResolverTest.java
new file mode 100644
index 0000000..b59d876
--- /dev/null
+++ b/idp-profile-impl/src/test/java/net/shibboleth/idp/relyingparty/impl/DelegatingCriteriaRelyingPartyConfigurationResolverTest.java
@@ -0,0 +1,315 @@
+/*
+ * Licensed to the University Corporation for Advanced Internet Development,
+ * Inc. (UCAID) under one or more contributor license agreements.  See the
+ * NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The UCAID licenses this file to You 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.idp.relyingparty.impl;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+
+import org.opensaml.core.criterion.EntityIdCriterion;
+import org.opensaml.core.xml.XMLObject;
+import org.opensaml.core.xml.XMLObjectBaseTestCase;
+import org.opensaml.core.xml.config.XMLObjectProviderRegistrySupport;
+import org.opensaml.core.xml.io.MarshallingException;
+import org.opensaml.core.xml.schema.XSString;
+import org.opensaml.core.xml.util.XMLObjectSupport;
+import org.opensaml.saml.common.profile.logic.EntityAttributesPredicate;
+import org.opensaml.saml.common.profile.logic.EntityAttributesPredicate.Candidate;
+import org.opensaml.saml.criterion.RoleDescriptorCriterion;
+import org.opensaml.saml.ext.saml2mdattr.EntityAttributes;
+import org.opensaml.saml.metadata.EntityGroupName;
+import org.opensaml.saml.saml2.core.Attribute;
+import org.opensaml.saml.saml2.core.AttributeValue;
+import org.opensaml.saml.saml2.metadata.EntityDescriptor;
+import org.opensaml.saml.saml2.metadata.Extensions;
+import org.opensaml.saml.saml2.metadata.RoleDescriptor;
+import org.opensaml.saml.saml2.metadata.SPSSODescriptor;
+import org.testng.Assert;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import net.shibboleth.idp.relyingparty.RelyingPartyConfiguration;
+import net.shibboleth.idp.saml.relyingparty.impl.RelyingPartyConfigurationSupport;
+import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
+import net.shibboleth.utilities.java.support.resolver.CriteriaSet;
+import net.shibboleth.utilities.java.support.resolver.ResolverException;
+
+/** Unit tests for {@link DelegatingCriteriaRelyingPartyConfigurationResolver. */
+public class DelegatingCriteriaRelyingPartyConfigurationResolverTest extends XMLObjectBaseTestCase {
+    
+    private RelyingPartyConfiguration anonRP, defaultRP; 
+    
+    private RelyingPartyConfiguration oneByName, twoByName, threeByName;
+    private RelyingPartyConfiguration oneByGroup, twoByGroup;
+    private RelyingPartyConfiguration oneByTag, twoByTag;
+    
+    private DefaultRelyingPartyConfigurationResolver delegate;
+    
+    private DelegatingCriteriaRelyingPartyConfigurationResolver resolver;
+    
+    @BeforeMethod
+    public void setup() throws ComponentInitializationException {
+        anonRP = new RelyingPartyConfiguration();
+        anonRP.setId("anonRPId");
+        anonRP.setResponderId("anonRPResp");
+        anonRP.setDetailedErrors(true);
+        anonRP.initialize();
+        
+        defaultRP = new RelyingPartyConfiguration();
+        defaultRP.setId("defaultRPId");
+        defaultRP.setResponderId("defaultRPResp");
+        defaultRP.setDetailedErrors(true);
+        defaultRP.initialize();
+        
+        oneByName = RelyingPartyConfigurationSupport.byName(Collections.singleton("rp1"));
+        oneByName.setResponderId("foo");
+        oneByName.setDetailedErrors(true);
+        oneByName.initialize();
+
+        twoByName = RelyingPartyConfigurationSupport.byName(Collections.singleton("rp2"));
+        twoByName.setResponderId("foo");
+        twoByName.setDetailedErrors(true);
+        twoByName.initialize();
+
+        threeByName = RelyingPartyConfigurationSupport.byName(Collections.singleton("rp3"));
+        threeByName.setResponderId("foo");
+        threeByName.setDetailedErrors(true);
+        threeByName.initialize();
+        
+        oneByGroup = RelyingPartyConfigurationSupport.byGroup(Collections.singleton("group1"), null);
+        oneByGroup.setResponderId("foo");
+        oneByGroup.setDetailedErrors(true);
+        oneByGroup.initialize();
+        
+        twoByGroup = RelyingPartyConfigurationSupport.byGroup(Collections.singleton("group2"), null);
+        twoByGroup.setResponderId("foo");
+        twoByGroup.setDetailedErrors(true);
+        twoByGroup.initialize();
+        
+        Candidate candidate1 = new EntityAttributesPredicate.Candidate("urn:test:attr:tag", Attribute.URI_REFERENCE);
+        candidate1.setValues(Collections.singleton("tag1"));
+        oneByTag = RelyingPartyConfigurationSupport.byTag(Collections.singleton(candidate1), true, true);
+        oneByTag.setId("byTag1");
+        oneByTag.setResponderId("foo");
+        oneByTag.setDetailedErrors(true);
+        oneByTag.initialize();
+        
+        Candidate candidate2 = new EntityAttributesPredicate.Candidate("urn:test:attr:tag", Attribute.URI_REFERENCE);
+        candidate2.setValues(Collections.singleton("tag2"));
+        twoByTag = RelyingPartyConfigurationSupport.byTag(Collections.singleton(candidate2), true, true);
+        twoByTag.setId("byTag2");
+        twoByTag.setResponderId("foo");
+        twoByTag.setDetailedErrors(true);
+        twoByTag.initialize();
+        
+        // Complete the population and init this in the individual tests.
+        delegate = new DefaultRelyingPartyConfigurationResolver();
+        delegate.setId("delegate");
+        delegate.setUnverifiedConfiguration(anonRP);
+        delegate.setDefaultConfiguration(defaultRP);
+        
+        resolver = new DelegatingCriteriaRelyingPartyConfigurationResolver();
+        resolver.setId("resolver");
+        resolver.setDelegate(delegate);
+        resolver.initialize();
+    }
+    
+    @Test
+    public void testResolveByEntityIDViaEntityIDCriterion() throws ComponentInitializationException, ResolverException {
+        Iterable<RelyingPartyConfiguration> results = null;
+        RelyingPartyConfiguration result = null;
+        
+        final List<RelyingPartyConfiguration> rpConfigs = Arrays.asList(oneByName, twoByName, threeByName);
+
+        delegate.setId("delegate");
+        delegate.setRelyingPartyConfigurations(rpConfigs);
+        delegate.initialize();
+        
+        results = resolver.resolve(new CriteriaSet(new EntityIdCriterion("rp1")));
+        Assert.assertNotNull(results);
+
+        Iterator<RelyingPartyConfiguration> resultItr = results.iterator();
+        Assert.assertTrue(resultItr.hasNext());
+        Assert.assertSame(resultItr.next(), oneByName);
+        Assert.assertFalse(resultItr.hasNext());
+
+        result = resolver.resolveSingle(new CriteriaSet(new EntityIdCriterion("rp2")));
+        Assert.assertSame(result, twoByName);
+        
+        result = resolver.resolveSingle(new CriteriaSet(new EntityIdCriterion("doesNotExist")));
+        Assert.assertSame(result, defaultRP);
+        
+        results = resolver.resolve(null);
+        Assert.assertNotNull(results);
+        Assert.assertFalse(results.iterator().hasNext());
+
+        result = resolver.resolveSingle(null);
+        Assert.assertNull(result);
+    }
+    
+    @Test
+    public void testResolveByEntityIDViaRoleDescriptor() throws ComponentInitializationException, ResolverException {
+        Iterable<RelyingPartyConfiguration> results = null;
+        RelyingPartyConfiguration result = null;
+        
+        final List<RelyingPartyConfiguration> rpConfigs = Arrays.asList(oneByName, twoByName, threeByName);
+
+        delegate.setId("delegate");
+        delegate.setRelyingPartyConfigurations(rpConfigs);
+        delegate.initialize();
+        
+        EntityDescriptor ed = (EntityDescriptor) XMLObjectSupport.buildXMLObject(EntityDescriptor.DEFAULT_ELEMENT_NAME);
+        ed.setEntityID("rp3");
+        RoleDescriptor rd = (RoleDescriptor) XMLObjectSupport.buildXMLObject(SPSSODescriptor.DEFAULT_ELEMENT_NAME);
+        ed.getRoleDescriptors().add(rd);
+        
+        results = resolver.resolve(new CriteriaSet(new RoleDescriptorCriterion(rd)));
+        Assert.assertNotNull(results);
+        
+        Iterator<RelyingPartyConfiguration> resultItr = results.iterator();
+        Assert.assertTrue(resultItr.hasNext());
+        Assert.assertSame(resultItr.next(), threeByName);
+        Assert.assertFalse(resultItr.hasNext());
+        
+        result = resolver.resolveSingle(new CriteriaSet(new RoleDescriptorCriterion(rd)));
+        Assert.assertSame(result, threeByName);
+    }
+    
+    @Test
+    public void testResolveByEntityGroupName() throws ComponentInitializationException, ResolverException {
+        Iterable<RelyingPartyConfiguration> results = null;
+        RelyingPartyConfiguration result = null;
+        
+        final List<RelyingPartyConfiguration> rpConfigs = Arrays.asList(oneByGroup, twoByGroup);
+
+        delegate.setId("delegate");
+        delegate.setRelyingPartyConfigurations(rpConfigs);
+        delegate.initialize();
+        
+        EntityDescriptor ed = (EntityDescriptor) XMLObjectSupport.buildXMLObject(EntityDescriptor.DEFAULT_ELEMENT_NAME);
+        ed.setEntityID("rp3");
+        ed.getObjectMetadata().put(new EntityGroupName("group1"));
+        RoleDescriptor rd = (RoleDescriptor) XMLObjectSupport.buildXMLObject(SPSSODescriptor.DEFAULT_ELEMENT_NAME);
+        ed.getRoleDescriptors().add(rd);
+        
+        results = resolver.resolve(new CriteriaSet(new RoleDescriptorCriterion(rd)));
+        Assert.assertNotNull(results);
+        
+        Iterator<RelyingPartyConfiguration> resultItr = results.iterator();
+        Assert.assertTrue(resultItr.hasNext());
+        Assert.assertSame(resultItr.next(), oneByGroup);
+        Assert.assertFalse(resultItr.hasNext());
+        
+        result = resolver.resolveSingle(new CriteriaSet(new RoleDescriptorCriterion(rd)));
+        Assert.assertSame(result, oneByGroup);
+        
+        // With 2 known group names and 1 unknown, should resolve 2 by group
+        ed.getObjectMetadata().put(new EntityGroupName("group2"));
+        ed.getObjectMetadata().put(new EntityGroupName("unknown"));
+        
+        results = resolver.resolve(new CriteriaSet(new RoleDescriptorCriterion(rd)));
+        Assert.assertNotNull(results);
+        
+        resultItr = results.iterator();
+        Assert.assertTrue(resultItr.hasNext());
+        Assert.assertSame(resultItr.next(), oneByGroup);
+        Assert.assertTrue(resultItr.hasNext());
+        Assert.assertSame(resultItr.next(), twoByGroup);
+        Assert.assertFalse(resultItr.hasNext());
+    }
+    
+    @Test
+    public void testResolveByEntityTag() throws ComponentInitializationException, ResolverException, MarshallingException {
+        Iterable<RelyingPartyConfiguration> results = null;
+        RelyingPartyConfiguration result = null;
+        
+        final List<RelyingPartyConfiguration> rpConfigs = Arrays.asList(oneByTag, twoByTag);
+
+        delegate.setId("delegate");
+        delegate.setRelyingPartyConfigurations(rpConfigs);
+        delegate.initialize();
+        
+        EntityDescriptor ed = (EntityDescriptor) XMLObjectSupport.buildXMLObject(EntityDescriptor.DEFAULT_ELEMENT_NAME);
+        ed.setEntityID("rp3");
+        RoleDescriptor rd = (RoleDescriptor) XMLObjectSupport.buildXMLObject(SPSSODescriptor.DEFAULT_ELEMENT_NAME);
+        ed.getRoleDescriptors().add(rd);
+        
+        addTag(ed, "tag1");
+        
+        results = resolver.resolve(new CriteriaSet(new RoleDescriptorCriterion(rd)));
+        Assert.assertNotNull(results);
+        
+        Iterator<RelyingPartyConfiguration> resultItr = results.iterator();
+        Assert.assertTrue(resultItr.hasNext());
+        Assert.assertSame(resultItr.next(), oneByTag);
+        Assert.assertFalse(resultItr.hasNext());
+        
+        result = resolver.resolveSingle(new CriteriaSet(new RoleDescriptorCriterion(rd)));
+        Assert.assertSame(result, oneByTag);
+        
+        // With 2 known tags names and 1 unknown, should resolve 2 by tag
+        addTag(ed, "tag2");
+        addTag(ed, "unknown");
+        
+        results = resolver.resolve(new CriteriaSet(new RoleDescriptorCriterion(rd)));
+        Assert.assertNotNull(results);
+        
+        resultItr = results.iterator();
+        Assert.assertTrue(resultItr.hasNext());
+        Assert.assertSame(resultItr.next(), oneByTag);
+        Assert.assertTrue(resultItr.hasNext());
+        Assert.assertSame(resultItr.next(), twoByTag);
+        Assert.assertFalse(resultItr.hasNext());
+    }
+    
+    private void addTag(EntityDescriptor ed, String value) {
+        Extensions extensions = ed.getExtensions();
+        if (extensions == null) {
+            extensions = (Extensions) XMLObjectSupport.buildXMLObject(Extensions.DEFAULT_ELEMENT_NAME);
+            ed.setExtensions(extensions);
+        }
+        
+        EntityAttributes entityAttributes = null;
+        List<XMLObject> entityAttributesList = extensions.getUnknownXMLObjects(EntityAttributes.DEFAULT_ELEMENT_NAME);
+        if (entityAttributesList.isEmpty()) {
+            entityAttributes = (EntityAttributes) XMLObjectSupport.buildXMLObject(EntityAttributes.DEFAULT_ELEMENT_NAME);
+            extensions.getUnknownXMLObjects().add(entityAttributes);
+        } else {
+            entityAttributes = (EntityAttributes) entityAttributesList.get(0);
+        }
+        
+        Attribute attr = null;
+        List<Attribute> attrs = entityAttributes.getAttributes();
+        if (attrs.isEmpty()) {
+            attr = (Attribute) XMLObjectSupport.buildXMLObject(Attribute.DEFAULT_ELEMENT_NAME);
+            attr.setNameFormat(Attribute.URI_REFERENCE);
+            attr.setName("urn:test:attr:tag");
+        } else {
+            attr = attrs.get(0);
+        }
+        
+        XSString val = (XSString) XMLObjectProviderRegistrySupport.getBuilderFactory().getBuilder(XSString.TYPE_NAME)
+                .buildObject(AttributeValue.DEFAULT_ELEMENT_NAME, XSString.TYPE_NAME);
+        val.setValue(value);
+        attr.getAttributeValues().add(val);
+        
+        attrs.add(attr);
+    }
+
+}
diff --git a/idp-profile-impl/src/test/java/net/shibboleth/idp/relyingparty/impl/DelegatingRelyingPartyConfigurationResolverTest.java b/idp-profile-impl/src/test/java/net/shibboleth/idp/relyingparty/impl/DelegatingRelyingPartyConfigurationResolverTest.java
deleted file mode 100644
index 6de535f..0000000
--- a/idp-profile-impl/src/test/java/net/shibboleth/idp/relyingparty/impl/DelegatingRelyingPartyConfigurationResolverTest.java
+++ /dev/null
@@ -1,116 +0,0 @@
-/*
- * Licensed to the University Corporation for Advanced Internet Development,
- * Inc. (UCAID) under one or more contributor license agreements.  See the
- * NOTICE file distributed with this work for additional information regarding
- * copyright ownership. The UCAID licenses this file to You 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.idp.relyingparty.impl;
-
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
-
-import org.opensaml.core.criterion.EntityIdCriterion;
-import org.opensaml.core.xml.XMLObjectBaseTestCase;
-import org.opensaml.core.xml.util.XMLObjectSupport;
-import org.opensaml.saml.criterion.RoleDescriptorCriterion;
-import org.opensaml.saml.saml2.metadata.EntityDescriptor;
-import org.opensaml.saml.saml2.metadata.RoleDescriptor;
-import org.opensaml.saml.saml2.metadata.SPSSODescriptor;
-import org.testng.Assert;
-import org.testng.annotations.Test;
-
-import net.shibboleth.idp.relyingparty.RelyingPartyConfiguration;
-import net.shibboleth.idp.saml.relyingparty.impl.RelyingPartyConfigurationSupport;
-import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
-import net.shibboleth.utilities.java.support.resolver.CriteriaSet;
-import net.shibboleth.utilities.java.support.resolver.ResolverException;
-
-/** Unit tests for {@link DelegatingCriteriaRelyingPartyConfigurationResolver. */
-public class DelegatingRelyingPartyConfigurationResolverTest extends XMLObjectBaseTestCase {
-    
-    @Test
-    public void testResolve() throws ComponentInitializationException, ResolverException {
-        final RelyingPartyConfiguration anonRP = new RelyingPartyConfiguration();
-        anonRP.setId("anonRPId");
-        anonRP.setResponderId("anonRPResp");
-        anonRP.setDetailedErrors(true);
-        anonRP.initialize();
-        
-        final RelyingPartyConfiguration defaultRP = new RelyingPartyConfiguration();
-        defaultRP.setId("defaultRPId");
-        defaultRP.setResponderId("defaultRPResp");
-        defaultRP.setDetailedErrors(true);
-        defaultRP.initialize();
-        
-        final RelyingPartyConfiguration one = RelyingPartyConfigurationSupport.byName(Collections.singleton("rp1"));
-        one.setResponderId("foo");
-        one.setDetailedErrors(true);
-        one.initialize();
-
-        final RelyingPartyConfiguration two = RelyingPartyConfigurationSupport.byName(Collections.singleton("rp2"));
-        two.setResponderId("foo");
-        two.setDetailedErrors(true);
-        two.initialize();
-
-        final RelyingPartyConfiguration three = RelyingPartyConfigurationSupport.byName(Collections.singleton("rp3"));
-        three.setResponderId("foo");
-        three.setDetailedErrors(true);
-        three.initialize();
-        
-        final List<RelyingPartyConfiguration> rpConfigs = Arrays.asList(one, two, three);
-
-        final DefaultRelyingPartyConfigurationResolver delegate = new DefaultRelyingPartyConfigurationResolver();
-        delegate.setId("delegate");
-        delegate.setRelyingPartyConfigurations(rpConfigs);
-        delegate.setUnverifiedConfiguration(anonRP);
-        delegate.setDefaultConfiguration(defaultRP);
-        delegate.initialize();
-        
-        final DelegatingCriteriaRelyingPartyConfigurationResolver resolver = new DelegatingCriteriaRelyingPartyConfigurationResolver();
-        resolver.setId("resolver");
-        resolver.setDelegate(delegate);
-        resolver.initialize();
-        
-        Iterable<RelyingPartyConfiguration> results = resolver.resolve(new CriteriaSet(new EntityIdCriterion("rp1")));
-        Assert.assertNotNull(results);
-
-        Iterator<RelyingPartyConfiguration> resultItr = results.iterator();
-        Assert.assertTrue(resultItr.hasNext());
-        Assert.assertSame(resultItr.next(), one);
-        Assert.assertFalse(resultItr.hasNext());
-
-        RelyingPartyConfiguration result = resolver.resolveSingle(new CriteriaSet(new EntityIdCriterion("rp2")));
-        Assert.assertSame(result, two);
-        
-        EntityDescriptor ed = (EntityDescriptor) XMLObjectSupport.buildXMLObject(EntityDescriptor.DEFAULT_ELEMENT_NAME);
-        ed.setEntityID("rp3");
-        RoleDescriptor rd = (RoleDescriptor) XMLObjectSupport.buildXMLObject(SPSSODescriptor.DEFAULT_ELEMENT_NAME);
-        ed.getRoleDescriptors().add(rd);
-        result = resolver.resolveSingle(new CriteriaSet(new RoleDescriptorCriterion(rd)));
-        Assert.assertSame(result, three);
-        
-        result = resolver.resolveSingle(new CriteriaSet(new EntityIdCriterion("doesNotExist")));
-        Assert.assertSame(result, defaultRP);
-        
-        results = resolver.resolve(null);
-        Assert.assertNotNull(results);
-        Assert.assertFalse(results.iterator().hasNext());
-
-        result = resolver.resolveSingle(null);
-        Assert.assertNull(result);
-    }
-
-}

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


More information about the commits mailing list