[java-metadata-aggregator] branch master updated: MDA-177 - Add entity attribute matcher for assurance certification values

Ian Young ian at iay.org.uk
Thu May 11 12:34:51 EDT 2017


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

iay pushed a commit to branch master
in repository java-metadata-aggregator.

View the commit online:
http://git.shibboleth.net/view/?p=java-metadata-aggregator.git;a=commit;h=45e2835b10df572d911b11a338a2bf284705e693

The following commit(s) were added to refs/heads/master by this push:
       new  45e2835   MDA-177 - Add entity attribute matcher for assurance certification values
45e2835 is described below

commit 45e2835b10df572d911b11a338a2bf284705e693
Author: Ian Young <ian at iay.org.uk>
AuthorDate: Thu May 11 17:34:32 2017 +0100

    MDA-177 - Add entity attribute matcher for assurance certification values
---
 .../saml/mdattr/AssuranceCertificationMatcher.java |  55 ++++++++++
 .../resources/net/shibboleth/metadata/beans.xml    |   3 +
 .../AssuranceCertificationMatcherSpringTest.java   | 111 +++++++++++++++++++++
 .../mdattr/AssuranceCertificationMatcherTest.java  |  83 +++++++++++++++
 ...uranceCertificationMatcherSpringTest-config.xml |  70 +++++++++++++
 5 files changed, 322 insertions(+)

diff --git a/aggregator-pipeline/src/main/java/net/shibboleth/metadata/dom/saml/mdattr/AssuranceCertificationMatcher.java b/aggregator-pipeline/src/main/java/net/shibboleth/metadata/dom/saml/mdattr/AssuranceCertificationMatcher.java
new file mode 100644
index 0000000..d34a83a
--- /dev/null
+++ b/aggregator-pipeline/src/main/java/net/shibboleth/metadata/dom/saml/mdattr/AssuranceCertificationMatcher.java
@@ -0,0 +1,55 @@
+/*
+ * 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.metadata.dom.saml.mdattr;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+import javax.annotation.concurrent.ThreadSafe;
+
+/**
+ * An entity attribute matcher which matches a given assurance certification value.
+ */
+ at ThreadSafe
+public class AssuranceCertificationMatcher extends AbstractExactValueMatcher {
+
+    /** Attribute Name value for assurance certifications. */
+    private static final String AC_NAME = "urn:oasis:names:tc:SAML:attribute:assurance-certification";
+
+    /** Attribute NameFormat value for assurance certifications. */
+    private static final String AC_NAME_FORMAT = "urn:oasis:names:tc:SAML:2.0:attrname-format:uri";
+
+    /**
+     * Constructor.
+     *
+     * @param certification assurance certification to match
+     * @param regAuth registration authority to match, or <code>null</code>
+     */
+    public AssuranceCertificationMatcher(@Nonnull final String certification, @Nullable final String regAuth) {
+        super(certification, AC_NAME, AC_NAME_FORMAT, regAuth);
+    }
+
+    /**
+     * Constructor.
+     *
+     * @param certification assurance certification to match
+     */
+    public AssuranceCertificationMatcher(@Nonnull final String certification) {
+        this(certification, null);
+    }
+
+}
diff --git a/aggregator-pipeline/src/main/resources/net/shibboleth/metadata/beans.xml b/aggregator-pipeline/src/main/resources/net/shibboleth/metadata/beans.xml
index ea59208..f524688 100644
--- a/aggregator-pipeline/src/main/resources/net/shibboleth/metadata/beans.xml
+++ b/aggregator-pipeline/src/main/resources/net/shibboleth/metadata/beans.xml
@@ -154,6 +154,9 @@
         net.shibboleth.metadata.dom.saml.mdattr
     -->
 
+    <bean id="mda.AssuranceCertificationMatcher" abstract="true"
+        class="net.shibboleth.metadata.dom.saml.mdattr.AssuranceCertificationMatcher"/>
+
     <bean id="mda.EntityAttributeFilteringStage" abstract="true" parent="mda.stage_parent"
         class="net.shibboleth.metadata.dom.saml.mdattr.EntityAttributeFilteringStage"/>
 
diff --git a/aggregator-pipeline/src/test/java/net/shibboleth/metadata/dom/saml/mdattr/AssuranceCertificationMatcherSpringTest.java b/aggregator-pipeline/src/test/java/net/shibboleth/metadata/dom/saml/mdattr/AssuranceCertificationMatcherSpringTest.java
new file mode 100644
index 0000000..03e9c38
--- /dev/null
+++ b/aggregator-pipeline/src/test/java/net/shibboleth/metadata/dom/saml/mdattr/AssuranceCertificationMatcherSpringTest.java
@@ -0,0 +1,111 @@
+/*
+ * 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.metadata.dom.saml.mdattr;
+
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+import com.google.common.base.Predicate;
+
+import net.shibboleth.metadata.dom.saml.mdattr.EntityAttributeFilteringStage.EntityAttributeContext;
+import net.shibboleth.metadata.dom.saml.mdattr.EntityAttributeFilteringStage.ContextImpl;
+
+/**
+ * This is the same as {@link AssuranceCertificationMatcherTest}, but pulls the matcher beans
+ * from a configured application context. This is just to make sure that Spring can
+ * distinguish between the two constructor signatures properly, so we don't need an
+ * equivalent for every class under test.
+ *
+ * In addition, each matcher is tested against an expanded implementation typical of what
+ * was required before this new matcher class was introduced.
+ */
+ at ContextConfiguration("AssuranceCertificationMatcherSpringTest-config.xml")
+public class AssuranceCertificationMatcherSpringTest extends AbstractTestNGSpringContextTests {
+
+    private void test(final boolean expected,
+            final Predicate<EntityAttributeContext> matcher,
+            final Predicate<EntityAttributeContext> oldMatcher,
+            final EntityAttributeContext context) {
+        Assert.assertEquals(matcher.apply(context), expected, context.toString());
+        Assert.assertEquals(oldMatcher.apply(context), expected, context.toString());
+    }
+
+    @Test
+    public void testNoRA() {
+        final Predicate<EntityAttributeContext> matcher =
+                (Predicate<EntityAttributeContext>)applicationContext.getBean("certificationMatcherNoRA", Predicate.class);
+        final Predicate<EntityAttributeContext> oldMatcher =
+                (Predicate<EntityAttributeContext>)applicationContext.getBean("oldMatcherNoRA", Predicate.class);
+
+        // all four components match
+        test(true, matcher, oldMatcher,
+                new ContextImpl("category", "urn:oasis:names:tc:SAML:attribute:assurance-certification",
+                "urn:oasis:names:tc:SAML:2.0:attrname-format:uri", "whatever"));
+
+        // context has no RA
+        test(true, matcher, oldMatcher,
+                new ContextImpl("category", "urn:oasis:names:tc:SAML:attribute:assurance-certification",
+                "urn:oasis:names:tc:SAML:2.0:attrname-format:uri", null));
+
+        // these matches should fail because one component differs
+        test(false, matcher, oldMatcher,
+                new ContextImpl("category2", "urn:oasis:names:tc:SAML:attribute:assurance-certification",
+                "urn:oasis:names:tc:SAML:2.0:attrname-format:uri", null));
+        test(false, matcher, oldMatcher,
+                new ContextImpl("category", "http://macedir.org/entity-category-support",
+                "urn:oasis:names:tc:SAML:2.0:attrname-format:uri", null));
+        test(false, matcher, oldMatcher,
+                new ContextImpl("category", "urn:oasis:names:tc:SAML:attribute:assurance-certification",
+                "urn:oasis:names:tc:SAML:2.0:attrname-format:unspecified", null));
+    }
+
+    @Test
+    public void testWithRA() {
+        final Predicate<EntityAttributeContext> matcher =
+                (Predicate<EntityAttributeContext>)applicationContext.getBean("certificationMatcherWithRA", Predicate.class);
+        final Predicate<EntityAttributeContext> oldMatcher =
+                (Predicate<EntityAttributeContext>)applicationContext.getBean("oldMatcherWithRA", Predicate.class);
+
+        // all four components match
+        test(true, matcher, oldMatcher,
+                new ContextImpl("category", "urn:oasis:names:tc:SAML:attribute:assurance-certification",
+                "urn:oasis:names:tc:SAML:2.0:attrname-format:uri", "registrar"));
+
+        // context has no RA
+        test(false, matcher, oldMatcher,
+                new ContextImpl("category", "http://macedir.org/entity-category",
+                "urn:oasis:names:tc:SAML:2.0:attrname-format:uri", null));
+
+        // these matches should fail because one component differs
+        test(false, matcher, oldMatcher,
+                new ContextImpl("category2", "urn:oasis:names:tc:SAML:attribute:assurance-certification",
+                "urn:oasis:names:tc:SAML:2.0:attrname-format:uri", "registrar"));
+        test(false, matcher, oldMatcher,
+                new ContextImpl("category", "http://macedir.org/entity-category-support",
+                "urn:oasis:names:tc:SAML:2.0:attrname-format:uri", "registrar"));
+        test(false, matcher, oldMatcher,
+                new ContextImpl("category", "urn:oasis:names:tc:SAML:attribute:assurance-certification",
+                "urn:oasis:names:tc:SAML:2.0:attrname-format:unspecified", "registrar"));
+        test(false, matcher, oldMatcher,
+                new ContextImpl("category", "urn:oasis:names:tc:SAML:attribute:assurance-certification",
+                "urn:oasis:names:tc:SAML:2.0:attrname-format:uri", "registrar2"));
+    }
+
+}
diff --git a/aggregator-pipeline/src/test/java/net/shibboleth/metadata/dom/saml/mdattr/AssuranceCertificationMatcherTest.java b/aggregator-pipeline/src/test/java/net/shibboleth/metadata/dom/saml/mdattr/AssuranceCertificationMatcherTest.java
new file mode 100644
index 0000000..1a87a0a
--- /dev/null
+++ b/aggregator-pipeline/src/test/java/net/shibboleth/metadata/dom/saml/mdattr/AssuranceCertificationMatcherTest.java
@@ -0,0 +1,83 @@
+/*
+ * 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.metadata.dom.saml.mdattr;
+
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+import com.google.common.base.Predicate;
+
+import net.shibboleth.metadata.dom.saml.mdattr.EntityAttributeFilteringStage.EntityAttributeContext;
+import net.shibboleth.metadata.dom.saml.mdattr.EntityAttributeFilteringStage.ContextImpl;
+
+public class AssuranceCertificationMatcherTest {
+
+    private void test(final boolean expected, final Predicate<EntityAttributeContext> matcher,
+            final EntityAttributeContext context) {
+        Assert.assertEquals(matcher.apply(context), expected, context.toString());
+    }
+
+    @Test
+    public void testNoRA() {
+        final Predicate<EntityAttributeContext> matcher = new AssuranceCertificationMatcher("category");
+
+        // all four components match
+        test(true, matcher, new ContextImpl("category",
+                "urn:oasis:names:tc:SAML:attribute:assurance-certification",
+                "urn:oasis:names:tc:SAML:2.0:attrname-format:uri", "whatever"));
+
+        // context has no RA
+        test(true, matcher, new ContextImpl("category",
+                "urn:oasis:names:tc:SAML:attribute:assurance-certification",
+                "urn:oasis:names:tc:SAML:2.0:attrname-format:uri", null));
+
+        // these matches should fail because one component differs
+        test(false, matcher, new ContextImpl("category2", "urn:oasis:names:tc:SAML:attribute:assurance-certification",
+                "urn:oasis:names:tc:SAML:2.0:attrname-format:uri", null));
+        test(false, matcher, new ContextImpl("category", "http://macedir.org/entity-category-support",
+                "urn:oasis:names:tc:SAML:2.0:attrname-format:uri", null));
+        test(false, matcher, new ContextImpl("category", "urn:oasis:names:tc:SAML:attribute:assurance-certification",
+                "urn:oasis:names:tc:SAML:2.0:attrname-format:unspecified", null));
+    }
+
+    @Test
+    public void testWithRA() {
+        final Predicate<EntityAttributeContext> matcher = new AssuranceCertificationMatcher("category", "registrar");
+
+        // all four components match
+        test(true, matcher, new ContextImpl("category",
+                "urn:oasis:names:tc:SAML:attribute:assurance-certification",
+                "urn:oasis:names:tc:SAML:2.0:attrname-format:uri", "registrar"));
+
+        // context has no RA
+        test(false, matcher, new ContextImpl("category",
+                "urn:oasis:names:tc:SAML:attribute:assurance-certification",
+                "urn:oasis:names:tc:SAML:2.0:attrname-format:uri", null));
+
+        // these matches should fail because one component differs
+        test(false, matcher, new ContextImpl("category2", "urn:oasis:names:tc:SAML:attribute:assurance-certification",
+                "urn:oasis:names:tc:SAML:2.0:attrname-format:uri", "registrar"));
+        test(false, matcher, new ContextImpl("category", "http://macedir.org/entity-category-support",
+                "urn:oasis:names:tc:SAML:2.0:attrname-format:uri", "registrar"));
+        test(false, matcher, new ContextImpl("category", "urn:oasis:names:tc:SAML:attribute:assurance-certification",
+                "urn:oasis:names:tc:SAML:2.0:attrname-format:unspecified", "registrar"));
+        test(false, matcher, new ContextImpl("category", "urn:oasis:names:tc:SAML:attribute:assurance-certification",
+                "urn:oasis:names:tc:SAML:2.0:attrname-format:uri", "registrar2"));
+    }
+
+}
diff --git a/aggregator-pipeline/src/test/resources/net/shibboleth/metadata/dom/saml/mdattr/AssuranceCertificationMatcherSpringTest-config.xml b/aggregator-pipeline/src/test/resources/net/shibboleth/metadata/dom/saml/mdattr/AssuranceCertificationMatcherSpringTest-config.xml
new file mode 100644
index 0000000..7eb3d84
--- /dev/null
+++ b/aggregator-pipeline/src/test/resources/net/shibboleth/metadata/dom/saml/mdattr/AssuranceCertificationMatcherSpringTest-config.xml
@@ -0,0 +1,70 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans"
+    xmlns:c="http://www.springframework.org/schema/c"
+    xmlns:p="http://www.springframework.org/schema/p"
+    xmlns:util="http://www.springframework.org/schema/util"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="
+        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">
+
+    <import resource="classpath:net/shibboleth/metadata/beans.xml"/>
+
+    <bean id="certificationMatcherNoRA" parent="mda.AssuranceCertificationMatcher">
+        <constructor-arg value="category"/>
+    </bean>
+
+    <bean id="certificationMatcherWithRA" parent="mda.AssuranceCertificationMatcher">
+        <constructor-arg value="category"/>
+        <constructor-arg value="registrar"/>
+    </bean>
+
+    <bean id="oldMatcherNoRA" parent="mda.MultiPredicateMatcher">
+        <property name="nameFormatPredicate">
+            <bean class="com.google.common.base.Predicates"
+                factory-method="equalTo"
+                c:_="urn:oasis:names:tc:SAML:2.0:attrname-format:uri"
+            />
+        </property>
+        <property name="namePredicate">
+            <bean class="com.google.common.base.Predicates"
+                factory-method="equalTo"
+                c:_="urn:oasis:names:tc:SAML:attribute:assurance-certification"
+            />
+        </property>
+        <property name="valuePredicate">
+            <bean class="com.google.common.base.Predicates"
+                factory-method="equalTo"
+                c:_="category"
+            />
+        </property>
+    </bean>
+
+    <bean id="oldMatcherWithRA" parent="mda.MultiPredicateMatcher">
+        <property name="nameFormatPredicate">
+            <bean class="com.google.common.base.Predicates"
+                factory-method="equalTo"
+                c:_="urn:oasis:names:tc:SAML:2.0:attrname-format:uri"
+            />
+        </property>
+        <property name="namePredicate">
+            <bean class="com.google.common.base.Predicates"
+                factory-method="equalTo"
+                c:_="urn:oasis:names:tc:SAML:attribute:assurance-certification"
+            />
+        </property>
+        <property name="valuePredicate">
+            <bean class="com.google.common.base.Predicates"
+                factory-method="equalTo"
+                c:_="category"
+            />
+        </property>
+        <property name="registrationAuthorityPredicate">
+            <bean class="com.google.common.base.Predicates"
+                factory-method="equalTo"
+                c:_="registrar"
+            />
+        </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