[java-identity-provider] 02/03: IDP-1434 Tests for Filtering by queried attributes (SAML2)
Rod Widdowson
rdw at steadingsoftware.com
Wed May 1 05:02:17 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=2006717c3e685958bb95e1611b565710e6c0eae4
commit 2006717c3e685958bb95e1611b565710e6c0eae4
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Tue Apr 30 15:36:57 2019 +0100
IDP-1434 Tests for Filtering by queried attributes (SAML2)
https://issues.shibboleth.net/jira/browse/IDP-1434
Test for FilterByQueriedAttributes
---
.../impl/FilterByQueriedAttributesTest.java | 134 +++++++++++++++++++++
.../idp/saml/impl/profile/AttributeQuery.xml | 14 +++
.../idp/saml/impl/profile/saml2Mapper.xml | 96 +++++++++++++++
3 files changed, 244 insertions(+)
diff --git a/idp-saml-impl/src/test/java/net/shibboleth/idp/saml/saml2/profile/impl/FilterByQueriedAttributesTest.java b/idp-saml-impl/src/test/java/net/shibboleth/idp/saml/saml2/profile/impl/FilterByQueriedAttributesTest.java
new file mode 100644
index 0000000..4c6d0c5
--- /dev/null
+++ b/idp-saml-impl/src/test/java/net/shibboleth/idp/saml/saml2/profile/impl/FilterByQueriedAttributesTest.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.saml2.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.saml2.core.Attribute;
+import org.opensaml.saml.saml2.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.SAML2AttributesMapper;
+import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
+import net.shibboleth.utilities.java.support.xml.XMLParserException;
+
+/** Tests for {@link FilterByQueriedAttributes} */
+public class FilterByQueriedAttributesTest extends XMLObjectBaseTestCase {
+
+ static final String PATH = "/net/shibboleth/idp/saml/impl/profile/";
+
+ private AttributeQuery query;
+
+ private AttributesMapper<Attribute, IdPAttribute> mapper;
+
+ private FilterByQueriedAttributes 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 + "AttributeQuery.xml", true);
+ mapper = getBean(PATH + "saml2Mapper.xml", SAML2AttributesMapper.class);
+ }
+
+ @BeforeMethod public void setUpMethod() throws ComponentInitializationException {
+ action = new FilterByQueriedAttributes(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(), 0);
+ }
+
+ @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(), 2);
+ }
+
+}
diff --git a/idp-saml-impl/src/test/resources/net/shibboleth/idp/saml/impl/profile/AttributeQuery.xml b/idp-saml-impl/src/test/resources/net/shibboleth/idp/saml/impl/profile/AttributeQuery.xml
new file mode 100644
index 0000000..960a449
--- /dev/null
+++ b/idp-saml-impl/src/test/resources/net/shibboleth/idp/saml/impl/profile/AttributeQuery.xml
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<saml2p:AttributeQuery xmlns:saml2p="urn:oasis:names:tc:SAML:2.0:protocol"
+ xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns="urn:oasis:names:tc:SAML:2.0:assertion"
+ Version="2.0" ID="AQ" IssueInstant="2018-03-14T17:31:00Z">
+ <Attribute Name="urn:oid:1.3.6.1.4.1.5923.1.1.1.11" FriendlyName="eduPersonAssurance">
+ <AttributeValue xsi:type="xs:string">turquoise</AttributeValue>
+ </Attribute>
+ <Attribute Name="urn:oid:1.3.6.1.4.1.5923.1.1.1.9" FriendlyName="eduPersonScopedAffiliation">
+ <AttributeValue xsi:type="xs:string">blue#yellow</AttributeValue>
+ </Attribute>
+ <Attribute Name="urn:oid:1.3.6.1.4.1.5923.1.1.1.10" FriendlyName="eduPersonTargetedID"/>
+</saml2p:AttributeQuery>
diff --git a/idp-saml-impl/src/test/resources/net/shibboleth/idp/saml/impl/profile/saml2Mapper.xml b/idp-saml-impl/src/test/resources/net/shibboleth/idp/saml/impl/profile/saml2Mapper.xml
new file mode 100644
index 0000000..0dc5069
--- /dev/null
+++ b/idp-saml-impl/src/test/resources/net/shibboleth/idp/saml/impl/profile/saml2Mapper.xml
@@ -0,0 +1,96 @@
+<?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="SAML2String" name="urn:oid:1.3.6.1.4.1.5923.1.1.1.11" friendlyName="eduPersonAssurance" />
+ <AttributeEncoder xsi:type="SAML2String" nameFormat="http://example.org/Format" name="http://example.org/name/for/Attribute" friendlyName="otherSAMLName" />
+ </AttributeDefinition>
+
+ <AttributeDefinition xsi:type="ad:Simple" id="otherPersonAssurance" >
+ <AttributeEncoder xsi:type="SAML2String" name="urn:oid:1.3.6.1.4.1.5923.1.1.1.11" friendlyName="eduPersonAssurance" />
+ </AttributeDefinition>
+
+ <AttributeDefinition xsi:type="ad:Scoped" id="eduPersonScopedAffiliation" scope="example.org" >
+ <AttributeEncoder xsi:type="SAML2ScopedString" name="urn:oid:1.3.6.1.4.1.5923.1.1.1.9" friendlyName="eduPersonScopedAffiliation"
+ scopeDelimiter='#'/>
+ </AttributeDefinition>
+
+ <AttributeDefinition xsi:type="ad:SAML2NameID" id="eduPersonTargetedID"
+ nameIdFormat="urn:oasis:names:tc:SAML:2.0:nameid-format:persistent">
+ <AttributeEncoder xsi:type="SAML2XMLObject" name="urn:oid:1.3.6.1.4.1.5923.1.1.1.10" friendlyName="eduPersonTargetedID" />
+ </AttributeDefinition>
+
+
+
+ -->
+
+ <bean id="abstractStringMapper" init-method="initialize" abstract="true"
+ class="net.shibboleth.idp.saml.attribute.mapping.impl.SAML2AttributeMapper">
+ <property name="valueMapper">
+ <bean
+ class="net.shibboleth.idp.saml.attribute.mapping.impl.StringAttributeValueMapper" />
+ </property>
+ </bean>
+
+ <bean id="AttributesMapper"
+ class="net.shibboleth.idp.saml.attribute.mapping.impl.SAML2AttributesMapper"
+ init-method="initialize" p:id="SAML2AttributesMapper">
+ <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="attributeFormat" value="http://example.org/Format " />
+ <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="attributeFormat" value=" format " />
+ <property name="valueMapper">
+ <bean
+ class="net.shibboleth.idp.saml.attribute.mapping.impl.ScopedStringAttributeValueMapper"
+ p:delimiter="#" />
+ </property>
+ <property name="attributeIds">
+ <list>
+ <value>eduPersonScopedAffiliation</value>
+ </list>
+ </property>
+ </bean>
+ <bean parent="abstractStringMapper">
+ <property name="attributeFormat" value="format"/>
+ <property name="sAMLName" value="urn:oid:1.3.6.1.4.1.5923.1.1.1.10"/>
+ <property name="id" value="eduPersonTargetedID"/>
+ <property name="valueMapper">
+ <bean
+ class="net.shibboleth.idp.saml.attribute.mapping.impl.XMLObjectAttributeValueMapper" />
+ </property>
+ <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