[java-identity-provider] 03/03: IDP-1434 Tests for Filtering by queried attributes (SAML1)

Rod Widdowson rdw at steadingsoftware.com
Wed May 1 05:02:18 EDT 2019


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

rdw 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=2f39c034631777e689dc7550c9e5d19a5297904c

commit 2f39c034631777e689dc7550c9e5d19a5297904c
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Wed May 1 09:55:19 2019 +0100

    IDP-1434 Tests for Filtering by queried attributes (SAML1)
    
    https://issues.shibboleth.net/jira/browse/IDP-1434
    
    Test for FilterByQueriedAttributeDesignators
---
 .../FilterByQueriedAttributeDesignatorsTest.java   | 134 +++++++++++++++++++++
 .../idp/saml/impl/profile/AttributeQuerySaml1.xml  |  15 +++
 .../idp/saml/impl/profile/saml1Mapper.xml          |  78 ++++++++++++
 3 files changed, 227 insertions(+)

diff --git a/idp-saml-impl/src/test/java/net/shibboleth/idp/saml/saml1/profile/impl/FilterByQueriedAttributeDesignatorsTest.java b/idp-saml-impl/src/test/java/net/shibboleth/idp/saml/saml1/profile/impl/FilterByQueriedAttributeDesignatorsTest.java
new file mode 100644
index 0000000..9c56761
--- /dev/null
+++ b/idp-saml-impl/src/test/java/net/shibboleth/idp/saml/saml1/profile/impl/FilterByQueriedAttributeDesignatorsTest.java
@@ -0,0 +1,134 @@
+/*
+ * 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.saml.saml1.profile.impl;
+
+import static org.testng.Assert.assertEquals;
+
+import java.util.Collection;
+import java.util.List;
+
+import org.opensaml.core.xml.XMLObjectBaseTestCase;
+import org.opensaml.core.xml.io.UnmarshallingException;
+import org.opensaml.profile.context.ProfileRequestContext;
+import org.opensaml.saml.saml1.core.AttributeDesignator;
+import org.opensaml.saml.saml1.core.AttributeQuery;
+import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
+import org.springframework.context.support.GenericApplicationContext;
+import org.springframework.webflow.execution.Event;
+import org.springframework.webflow.execution.RequestContext;
+import org.testng.Assert;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import net.shibboleth.ext.spring.util.SchemaTypeAwareXMLBeanDefinitionReader;
+import net.shibboleth.idp.attribute.IdPAttribute;
+import net.shibboleth.idp.attribute.ScopedStringAttributeValue;
+import net.shibboleth.idp.attribute.StringAttributeValue;
+import net.shibboleth.idp.attribute.context.AttributeContext;
+import net.shibboleth.idp.profile.ActionTestingSupport;
+import net.shibboleth.idp.profile.RequestContextBuilder;
+import net.shibboleth.idp.profile.context.RelyingPartyContext;
+import net.shibboleth.idp.profile.context.navigate.WebflowRequestContextProfileRequestContextLookup;
+import net.shibboleth.idp.saml.attribute.mapping.AttributesMapper;
+import net.shibboleth.idp.saml.attribute.mapping.impl.SAML1AttributeDesignatorsMapper;
+import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
+import net.shibboleth.utilities.java.support.xml.XMLParserException;
+
+/** Tests for {@link FilterByQueriedAttributeDesignators} */
+public class FilterByQueriedAttributeDesignatorsTest extends XMLObjectBaseTestCase {
+
+    static final String PATH = "/net/shibboleth/idp/saml/impl/profile/";
+    
+    private AttributeQuery query;
+    
+    private AttributesMapper<AttributeDesignator, IdPAttribute> mapper;
+    
+    private FilterByQueriedAttributeDesignators action;
+    
+    private RequestContext rc;
+    
+    private ProfileRequestContext prc;
+
+    protected <Type> Type getBean(String fileName, Class<Type> claz) {
+
+        GenericApplicationContext context = new GenericApplicationContext();
+        try {
+            SchemaTypeAwareXMLBeanDefinitionReader beanDefinitionReader =
+                    new SchemaTypeAwareXMLBeanDefinitionReader(context);
+    
+            beanDefinitionReader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_XSD);
+            beanDefinitionReader.loadBeanDefinitions(fileName);
+            
+            context.refresh();
+    
+            Collection<Type> beans = context.getBeansOfType(claz).values();
+            Assert.assertEquals(beans.size(), 1);
+    
+            return beans.iterator().next();
+        } finally {
+            context.close();
+        }
+    }
+        
+    @BeforeClass public void setup() throws XMLParserException, UnmarshallingException {
+        query = unmarshallElement(PATH + "AttributeQuerySaml1.xml", true);        
+        mapper = getBean(PATH + "saml1Mapper.xml", SAML1AttributeDesignatorsMapper.class);
+    }
+    
+    @BeforeMethod public void setUpMethod() throws ComponentInitializationException {
+        action = new FilterByQueriedAttributeDesignators(mapper);
+        rc = new RequestContextBuilder().setInboundMessage(query).buildRequestContext();
+        prc = new WebflowRequestContextProfileRequestContextLookup().apply(rc);
+        action.initialize();
+    }
+
+    @Test public void noAttributes() {
+        prc.getSubcontext(RelyingPartyContext.class,true);
+        final Event event = action.execute(rc);
+        ActionTestingSupport.assertProceedEvent(event);
+    }
+
+    @Test public void noValues() {
+        final RelyingPartyContext rpc = prc.getSubcontext(RelyingPartyContext.class,true);
+        final AttributeContext ac = rpc.getSubcontext(AttributeContext.class,true);
+        final List<IdPAttribute> attributes = List.of(new IdPAttribute("eduPersonAssurance"), new IdPAttribute("flooby"), new IdPAttribute("eduPersonScopedAffiliation"),  new IdPAttribute("eduPersonTargetedID"));
+        ac.setIdPAttributes(attributes);
+        final Event event = action.execute(rc);
+        ActionTestingSupport.assertProceedEvent(event);
+        assertEquals(ac.getIdPAttributes().size(), 4);
+    }
+    
+    @Test public void values() {
+        final RelyingPartyContext rpc = prc.getSubcontext(RelyingPartyContext.class,true);
+        final AttributeContext ac = rpc.getSubcontext(AttributeContext.class,true);
+        final IdPAttribute eduPersonAssurance = new IdPAttribute("eduPersonAssurance");
+        eduPersonAssurance.setValues(List.of(new StringAttributeValue("green-blue"))); // not turquoise
+        final IdPAttribute flooby = new IdPAttribute("flooby");
+        final IdPAttribute eduPersonScopedAffiliation = new IdPAttribute("eduPersonScopedAffiliation");
+        eduPersonScopedAffiliation.setValues(List.of(new ScopedStringAttributeValue("blue", "yellow")));
+        final IdPAttribute eduPersonTargetedID = new IdPAttribute("eduPersonTargetedID");
+        eduPersonTargetedID.setValues(List.of(new StringAttributeValue("green-blue")));
+        final List<IdPAttribute> attributes = List.of(eduPersonAssurance, flooby,eduPersonScopedAffiliation, eduPersonTargetedID);
+        ac.setIdPAttributes(attributes);
+        final Event event = action.execute(rc);
+        ActionTestingSupport.assertProceedEvent(event);
+        assertEquals(ac.getIdPAttributes().size(), 4);
+    }
+
+}
diff --git a/idp-saml-impl/src/test/resources/net/shibboleth/idp/saml/impl/profile/AttributeQuerySaml1.xml b/idp-saml-impl/src/test/resources/net/shibboleth/idp/saml/impl/profile/AttributeQuerySaml1.xml
new file mode 100644
index 0000000..33ccaf8
--- /dev/null
+++ b/idp-saml-impl/src/test/resources/net/shibboleth/idp/saml/impl/profile/AttributeQuerySaml1.xml
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<saml1p:AttributeQuery xmlns:saml1p="urn:oasis:names:tc:SAML:1.0:protocol" xmlns="urn:oasis:names:tc:SAML:1.0:assertion"
+   xmlns:xs="http://www.w3.org/2001/XMLSchema"
+   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+   Version="2.0"  ID="AQ" IssueInstant="2018-03-14T17:31:00Z">
+   <Subject/>
+   <Attribute  AttributeName="urn:oid:1.3.6.1.4.1.5923.1.1.1.11" >
+    <AttributeValue  xsi:type="xs:string">turquoise</AttributeValue>
+   </Attribute>
+   <Attribute  AttributeName="urn:oid:1.3.6.1.4.1.5923.1.1.1.9" >
+    <AttributeValue  xsi:type="xs:string" >blue at yellow</AttributeValue>
+   </Attribute>
+   <Attribute  AttributeName="urn:oid:1.3.6.1.4.1.5923.1.1.1.10"/>
+</saml1p:AttributeQuery>
diff --git a/idp-saml-impl/src/test/resources/net/shibboleth/idp/saml/impl/profile/saml1Mapper.xml b/idp-saml-impl/src/test/resources/net/shibboleth/idp/saml/impl/profile/saml1Mapper.xml
new file mode 100644
index 0000000..a167735
--- /dev/null
+++ b/idp-saml-impl/src/test/resources/net/shibboleth/idp/saml/impl/profile/saml1Mapper.xml
@@ -0,0 +1,78 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans"
+	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
+	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
+
+    <!--  This is what we are trying to reverse map (note bi-directional aliasing, just to confuse things.  And me.
+    
+            <AttributeDefinition xsi:type="ad:Simple" id="eduPersonAssurance" >
+                <AttributeEncoder xsi:type="SAML1String" name="urn:mace:dir:attribute-def:eduPersonAssurance" />
+            </AttributeDefinition>
+
+            <AttributeDefinition xsi:type="ad:Simple" id="otherPersonAssurance" >
+                <AttributeEncoder xsi:type="SAML1String" name="urn:mace:dir:attribute-def:eduPersonAssurance" />
+            </AttributeDefinition>
+                
+            <AttributeDefinition xsi:type="ad:Scoped" id="eduPersonScopedAffiliation" scope="example.org" >
+                <AttributeEncoder xsi:type="SAML1ScopedString" name="urn:mace:dir:attribute-def:eduPersonScopedAffiliation" />
+            </AttributeDefinition>
+            
+            <AttributeDefinition xsi:type="ad:SAML2NameID" id="eduPersonTargetedID" 
+                                          nameIdFormat="urn:oasis:names:tc:SAML:2.0:nameid-format:persistent">
+                <AttributeEncoder xsi:type="SAML1XMLObject" name="urn:oid:1.3.6.1.4.1.5923.1.1.1.10" />
+            </AttributeDefinition> 
+    
+    
+    
+     -->
+     
+	<bean id="abstractStringMapper" init-method="initialize" abstract="true" 
+		class="net.shibboleth.idp.saml.attribute.mapping.impl.SAML1AttributeDesignatorMapper">
+	</bean>
+
+	<bean id="AttributesMapper"
+		class="net.shibboleth.idp.saml.attribute.mapping.impl.SAML1AttributeDesignatorsMapper"
+		init-method="initialize" p:id="SAML1AttributesMapper">
+		<property name="mappers">
+			<list>
+				<bean parent="abstractStringMapper">
+					<property name="id" value="eduPersonAssurance" />
+					<property name="SAMLName" value="urn:oid:1.3.6.1.4.1.5923.1.1.1.11" />
+					<property name="attributeIds">
+						<list>
+							<value>eduPersonAssurance</value>
+							<value>otherPersonAssurance</value>
+						</list>
+					</property>
+				</bean>
+				<bean parent="abstractStringMapper">
+					<property name="SAMLName" value="http://example.org/name/for/Attribute" />
+					<property name="id" value="otherSAMLName" />
+					<property name="attributeIds">
+						<list>
+							<value>eduPersonAssurance</value>
+						</list>
+					</property>
+				</bean>
+				<bean parent="abstractStringMapper">
+					<property name="sAMLName" value="urn:oid:1.3.6.1.4.1.5923.1.1.1.9" />
+					<property name="id" value="eduPersonScopedAffiliation" />
+					<property name="attributeIds">
+						<list>
+							<value>eduPersonScopedAffiliation</value>
+						</list>
+					</property>
+				</bean>
+				<bean parent="abstractStringMapper">
+					<property name="sAMLName" value="urn:oid:1.3.6.1.4.1.5923.1.1.1.10"/>
+					<property name="id" value="eduPersonTargetedID"/>
+					<property name="attributeIds">
+						<list>
+							<value>eduPersonTargetedID</value>
+						</list>
+					</property>
+				</bean>
+			</list>
+		</property>
+	</bean>
+</beans>

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


More information about the commits mailing list