[java-metadata-aggregator] 02/03: MDA-55 add ability to filter entity attribute values

Ian Young ian at iay.org.uk
Fri Dec 4 10:52:32 EST 2015


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

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

commit 48a7707133097a6ce037ece23c06324a5fbb88b6
Author: Ian Young <ian at iay.org.uk>
AuthorDate: Fri Dec 4 15:44:45 2015 +0000

    MDA-55 add ability to filter entity attribute values
    
    Refactor so that the EntityAttributeContext is more clearly bound to
    the EntityAttributeFilteringStage by embedding the former in the latter.
    
    Also embed the SimpleEntityAttributeContext class and make it package
    visible to reduce the API surface. It still needs to be visible within
    the package for tests.
---
 .../mdattr/AbstractEntityAttributeMatcher.java     |   2 +
 .../dom/saml/mdattr/EntityAttributeContext.java    |  64 ----------
 .../saml/mdattr/EntityAttributeFilteringStage.java | 132 +++++++++++++++++++++
 .../saml/mdattr/RegistrationAuthorityMatcher.java  |   2 +
 .../saml/mdattr/SimpleEntityAttributeContext.java  | 112 -----------------
 .../mdattr/EntityAttributeFilteringStageTest.java  |   1 +
 .../mdattr/EntityCategoryMatcherSpringTest.java    |   3 +
 .../dom/saml/mdattr/EntityCategoryMatcherTest.java |   3 +
 .../mdattr/EntityCategorySupportMatcherTest.java   |   3 +
 .../dom/saml/mdattr/MultiPredicateMatcherTest.java |   3 +
 .../mdattr/RegistrationAuthorityMatcherTest.java   |   3 +
 .../mdattr/SimpleEntityAttributeContextTest.java   |   3 +
 12 files changed, 155 insertions(+), 176 deletions(-)

diff --git a/aggregator-pipeline/src/main/java/net/shibboleth/metadata/dom/saml/mdattr/AbstractEntityAttributeMatcher.java b/aggregator-pipeline/src/main/java/net/shibboleth/metadata/dom/saml/mdattr/AbstractEntityAttributeMatcher.java
index 9ae9601..3a1756e 100644
--- a/aggregator-pipeline/src/main/java/net/shibboleth/metadata/dom/saml/mdattr/AbstractEntityAttributeMatcher.java
+++ b/aggregator-pipeline/src/main/java/net/shibboleth/metadata/dom/saml/mdattr/AbstractEntityAttributeMatcher.java
@@ -23,6 +23,8 @@ import javax.annotation.concurrent.ThreadSafe;
 
 import com.google.common.base.Predicate;
 
+import net.shibboleth.metadata.dom.saml.mdattr.EntityAttributeFilteringStage.EntityAttributeContext;
+
 /**
  * Abstract implementation of {@link Predicate} over {@link EntityAttributeContext} using
  * the template method pattern. The {@link #apply} method is broken down into matches
diff --git a/aggregator-pipeline/src/main/java/net/shibboleth/metadata/dom/saml/mdattr/EntityAttributeContext.java b/aggregator-pipeline/src/main/java/net/shibboleth/metadata/dom/saml/mdattr/EntityAttributeContext.java
deleted file mode 100644
index 1ff96e7..0000000
--- a/aggregator-pipeline/src/main/java/net/shibboleth/metadata/dom/saml/mdattr/EntityAttributeContext.java
+++ /dev/null
@@ -1,64 +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.metadata.dom.saml.mdattr;
-
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
-
-/**
- * An entity attribute context against which matches can take place. It consists
- * of the attribute's value, <code>Name</code> and <code>NameFormat</code> attributes,
- * and the entity's <code>registrationAuthority</code>, if any.
- * 
- * A matcher is a {@link com.google.common.base.Predicate} over such a context.
- */
-public interface EntityAttributeContext {
-
-    /**
-     * Returns the registration authority component, or <code>null</code>.
-     * 
-     * @return the registration authority, or <code>null</code>
-     */
-    @Nullable
-    String getRegistrationAuthority();
-    
-    /**
-     * Returns the attribute's <code>NameFormat</code>.
-     * 
-     * @return the attribute's <code>NameFormat</code>.
-     */
-    @Nonnull
-    String getNameFormat();
-    
-    /**
-     * Returns the attribute's <code>Name</code>.
-     * 
-     * @return the attribute's <code>Name</code>
-     */
-    @Nonnull
-    String getName();
-    
-    /**
-     * Returns the attribute's value.
-     * 
-     * @return the attribute's value
-     */
-    @Nonnull
-    String getValue();
-    
-}
diff --git a/aggregator-pipeline/src/main/java/net/shibboleth/metadata/dom/saml/mdattr/EntityAttributeFilteringStage.java b/aggregator-pipeline/src/main/java/net/shibboleth/metadata/dom/saml/mdattr/EntityAttributeFilteringStage.java
index 978a2b2..825fd59 100644
--- a/aggregator-pipeline/src/main/java/net/shibboleth/metadata/dom/saml/mdattr/EntityAttributeFilteringStage.java
+++ b/aggregator-pipeline/src/main/java/net/shibboleth/metadata/dom/saml/mdattr/EntityAttributeFilteringStage.java
@@ -61,6 +61,138 @@ public class EntityAttributeFilteringStage extends BaseStage<Element> {
     private final Logger log = LoggerFactory.getLogger(EntityAttributeFilteringStage.class);
 
     /**
+     * An entity attribute context against which matches can take place. It consists
+     * of the attribute's value, <code>Name</code> and <code>NameFormat</code> attributes,
+     * and the entity's <code>registrationAuthority</code>, if any.
+     * 
+     * A matcher is a {@link Predicate} over such a context.
+     */
+    public interface EntityAttributeContext {
+
+        /**
+         * Returns the registration authority component, or <code>null</code>.
+         * 
+         * @return the registration authority, or <code>null</code>
+         */
+        @Nullable
+        String getRegistrationAuthority();
+        
+        /**
+         * Returns the attribute's <code>NameFormat</code>.
+         * 
+         * @return the attribute's <code>NameFormat</code>.
+         */
+        @Nonnull
+        String getNameFormat();
+        
+        /**
+         * Returns the attribute's <code>Name</code>.
+         * 
+         * @return the attribute's <code>Name</code>
+         */
+        @Nonnull
+        String getName();
+        
+        /**
+         * Returns the attribute's value.
+         * 
+         * @return the attribute's value
+         */
+        @Nonnull
+        String getValue();
+        
+    }
+
+    /**
+     * A simple immutable implementation of {@link EntityAttributeContext}.
+     */
+    static class SimpleEntityAttributeContext implements EntityAttributeContext {
+
+        /** The attribute's value. */
+        @Nonnull
+        private final String value;
+        
+        /** The attribute's <code>Name</code>. */
+        @Nonnull
+        private final String name;
+        
+        /** The attribute's <code>NameFormat</code>. */
+        @Nonnull
+        private final String nameFormat;
+        
+        /** The entity's registration authority, or <code>null</code>. */
+        @Nullable
+        private final String registrationAuthority;
+        
+        /**
+         * Constructor.
+         * 
+         * @param attributeValue attribute value
+         * @param attributeName attribute <code>Name</code>
+         * @param attributeNameFormat attribute <code>NameFormat</code>
+         * @param registrar entity's registration authority, or <code>null</code>
+         */
+        public SimpleEntityAttributeContext(@Nonnull final String attributeValue,
+                @Nonnull final String attributeName,
+                @Nonnull final String attributeNameFormat,
+                @Nullable final String registrar) {
+            value = Constraint.isNotNull(attributeValue, "value may not be null");
+            name = Constraint.isNotNull(attributeName, "name may not be null");
+            nameFormat = Constraint.isNotNull(attributeNameFormat, "name format may not be null");
+            registrationAuthority = registrar;
+        }
+        
+        /**
+         * Shorthand three-argument constructor.
+         * 
+         * @param attributeValue attribute value
+         * @param attributeName attribute <code>Name</code>
+         * @param attributeNameFormat attribute <code>NameFormat</code>
+         */
+        public SimpleEntityAttributeContext(@Nonnull final String attributeValue,
+                @Nonnull final String attributeName,
+                @Nonnull final String attributeNameFormat) {
+            this(attributeValue, attributeName, attributeNameFormat, null);
+        }    
+
+        @Override
+        public String getRegistrationAuthority() {
+            return registrationAuthority;
+        }
+
+        @Override
+        public String getNameFormat() {
+            return nameFormat;
+        }
+
+        @Override
+        public String getName() {
+            return name;
+        }
+
+        @Override
+        public String getValue() {
+            return value;
+        }
+
+        @Override
+        public String toString() {
+            final StringBuilder b = new StringBuilder();
+            b.append("{v=").append(getValue());
+            b.append(", n=").append(getName());
+            b.append(", f=").append(getNameFormat());
+            b.append(", r=");
+            if (getRegistrationAuthority() == null) {
+                b.append("(none)");
+            } else {
+                b.append(getRegistrationAuthority());
+            }
+            b.append('}');
+            return b.toString();
+        }
+    }
+
+    /**
      * List of matching rules to apply to each attribute value. The list is applied in
      * order, with the first rule returning <code>true</code> terminating the evaluation.
      * This amounts to an implicit ORing of the individual rules, with early
diff --git a/aggregator-pipeline/src/main/java/net/shibboleth/metadata/dom/saml/mdattr/RegistrationAuthorityMatcher.java b/aggregator-pipeline/src/main/java/net/shibboleth/metadata/dom/saml/mdattr/RegistrationAuthorityMatcher.java
index dd19680..cf86e25 100644
--- a/aggregator-pipeline/src/main/java/net/shibboleth/metadata/dom/saml/mdattr/RegistrationAuthorityMatcher.java
+++ b/aggregator-pipeline/src/main/java/net/shibboleth/metadata/dom/saml/mdattr/RegistrationAuthorityMatcher.java
@@ -23,6 +23,8 @@ import javax.annotation.concurrent.ThreadSafe;
 
 import com.google.common.base.Predicate;
 
+import net.shibboleth.metadata.dom.saml.mdattr.EntityAttributeFilteringStage.EntityAttributeContext;
+
 /**
  * An entity attribute matcher which matches a given registration authority.
  * 
diff --git a/aggregator-pipeline/src/main/java/net/shibboleth/metadata/dom/saml/mdattr/SimpleEntityAttributeContext.java b/aggregator-pipeline/src/main/java/net/shibboleth/metadata/dom/saml/mdattr/SimpleEntityAttributeContext.java
deleted file mode 100644
index 545f56d..0000000
--- a/aggregator-pipeline/src/main/java/net/shibboleth/metadata/dom/saml/mdattr/SimpleEntityAttributeContext.java
+++ /dev/null
@@ -1,112 +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.metadata.dom.saml.mdattr;
-
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
-
-import net.shibboleth.utilities.java.support.logic.Constraint;
-
-/**
- * A simple immutable implementation of {@link EntityAttributeContext}.
- */
-public class SimpleEntityAttributeContext implements EntityAttributeContext {
-
-    /** The attribute's value. */
-    @Nonnull
-    private final String value;
-    
-    /** The attribute's <code>Name</code>. */
-    @Nonnull
-    private final String name;
-    
-    /** The attribute's <code>NameFormat</code>. */
-    @Nonnull
-    private final String nameFormat;
-    
-    /** The entity's registration authority, or <code>null</code>. */
-    @Nullable
-    private final String registrationAuthority;
-    
-    /**
-     * Constructor.
-     * 
-     * @param attributeValue attribute value
-     * @param attributeName attribute <code>Name</code>
-     * @param attributeNameFormat attribute <code>NameFormat</code>
-     * @param registrar entity's registration authority, or <code>null</code>
-     */
-    public SimpleEntityAttributeContext(@Nonnull final String attributeValue,
-            @Nonnull final String attributeName,
-            @Nonnull final String attributeNameFormat,
-            @Nullable final String registrar) {
-        value = Constraint.isNotNull(attributeValue, "value may not be null");
-        name = Constraint.isNotNull(attributeName, "name may not be null");
-        nameFormat = Constraint.isNotNull(attributeNameFormat, "name format may not be null");
-        registrationAuthority = registrar;
-    }
-    
-    /**
-     * Shorthand three-argument constructor.
-     * 
-     * @param attributeValue attribute value
-     * @param attributeName attribute <code>Name</code>
-     * @param attributeNameFormat attribute <code>NameFormat</code>
-     */
-    public SimpleEntityAttributeContext(@Nonnull final String attributeValue,
-            @Nonnull final String attributeName,
-            @Nonnull final String attributeNameFormat) {
-        this(attributeValue, attributeName, attributeNameFormat, null);
-    }    
-
-    @Override
-    public String getRegistrationAuthority() {
-        return registrationAuthority;
-    }
-
-    @Override
-    public String getNameFormat() {
-        return nameFormat;
-    }
-
-    @Override
-    public String getName() {
-        return name;
-    }
-
-    @Override
-    public String getValue() {
-        return value;
-    }
-
-    @Override
-    public String toString() {
-        final StringBuilder b = new StringBuilder();
-        b.append("{v=").append(getValue());
-        b.append(", n=").append(getName());
-        b.append(", f=").append(getNameFormat());
-        b.append(", r=");
-        if (getRegistrationAuthority() == null) {
-            b.append("(none)");
-        } else {
-            b.append(getRegistrationAuthority());
-        }
-        b.append('}');
-        return b.toString();
-    }
-}
diff --git a/aggregator-pipeline/src/test/java/net/shibboleth/metadata/dom/saml/mdattr/EntityAttributeFilteringStageTest.java b/aggregator-pipeline/src/test/java/net/shibboleth/metadata/dom/saml/mdattr/EntityAttributeFilteringStageTest.java
index 6a71d6e..3989fa9 100644
--- a/aggregator-pipeline/src/test/java/net/shibboleth/metadata/dom/saml/mdattr/EntityAttributeFilteringStageTest.java
+++ b/aggregator-pipeline/src/test/java/net/shibboleth/metadata/dom/saml/mdattr/EntityAttributeFilteringStageTest.java
@@ -7,6 +7,7 @@ import java.util.List;
 import net.shibboleth.metadata.Item;
 import net.shibboleth.metadata.dom.BaseDOMTest;
 import net.shibboleth.metadata.dom.DOMElementItem;
+import net.shibboleth.metadata.dom.saml.mdattr.EntityAttributeFilteringStage.EntityAttributeContext;
 import net.shibboleth.metadata.dom.saml.mdrpi.RegistrationAuthorityPopulationStage;
 
 import org.testng.annotations.Test;
diff --git a/aggregator-pipeline/src/test/java/net/shibboleth/metadata/dom/saml/mdattr/EntityCategoryMatcherSpringTest.java b/aggregator-pipeline/src/test/java/net/shibboleth/metadata/dom/saml/mdattr/EntityCategoryMatcherSpringTest.java
index 4b6fb9e..b03afc2 100644
--- a/aggregator-pipeline/src/test/java/net/shibboleth/metadata/dom/saml/mdattr/EntityCategoryMatcherSpringTest.java
+++ b/aggregator-pipeline/src/test/java/net/shibboleth/metadata/dom/saml/mdattr/EntityCategoryMatcherSpringTest.java
@@ -8,6 +8,9 @@ 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.SimpleEntityAttributeContext;
+
 /**
  * This is the same as {@link EntityCategoryMatcherTest}, but pulls the matcher beans
  * from a configured application context. This is just to make sure that Spring can
diff --git a/aggregator-pipeline/src/test/java/net/shibboleth/metadata/dom/saml/mdattr/EntityCategoryMatcherTest.java b/aggregator-pipeline/src/test/java/net/shibboleth/metadata/dom/saml/mdattr/EntityCategoryMatcherTest.java
index e55dba0..76b67d4 100644
--- a/aggregator-pipeline/src/test/java/net/shibboleth/metadata/dom/saml/mdattr/EntityCategoryMatcherTest.java
+++ b/aggregator-pipeline/src/test/java/net/shibboleth/metadata/dom/saml/mdattr/EntityCategoryMatcherTest.java
@@ -6,6 +6,9 @@ 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.SimpleEntityAttributeContext;
+
 public class EntityCategoryMatcherTest {
 
     private void test(final boolean expected, final Predicate<EntityAttributeContext> matcher,
diff --git a/aggregator-pipeline/src/test/java/net/shibboleth/metadata/dom/saml/mdattr/EntityCategorySupportMatcherTest.java b/aggregator-pipeline/src/test/java/net/shibboleth/metadata/dom/saml/mdattr/EntityCategorySupportMatcherTest.java
index e89e5db..dcfbc56 100644
--- a/aggregator-pipeline/src/test/java/net/shibboleth/metadata/dom/saml/mdattr/EntityCategorySupportMatcherTest.java
+++ b/aggregator-pipeline/src/test/java/net/shibboleth/metadata/dom/saml/mdattr/EntityCategorySupportMatcherTest.java
@@ -6,6 +6,9 @@ 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.SimpleEntityAttributeContext;
+
 public class EntityCategorySupportMatcherTest {
 
     private void test(final boolean expected, final Predicate<EntityAttributeContext> matcher,
diff --git a/aggregator-pipeline/src/test/java/net/shibboleth/metadata/dom/saml/mdattr/MultiPredicateMatcherTest.java b/aggregator-pipeline/src/test/java/net/shibboleth/metadata/dom/saml/mdattr/MultiPredicateMatcherTest.java
index 6e0d72d..3672a18 100644
--- a/aggregator-pipeline/src/test/java/net/shibboleth/metadata/dom/saml/mdattr/MultiPredicateMatcherTest.java
+++ b/aggregator-pipeline/src/test/java/net/shibboleth/metadata/dom/saml/mdattr/MultiPredicateMatcherTest.java
@@ -7,6 +7,9 @@ import org.testng.annotations.Test;
 import com.google.common.base.Predicate;
 import com.google.common.base.Predicates;
 
+import net.shibboleth.metadata.dom.saml.mdattr.EntityAttributeFilteringStage.EntityAttributeContext;
+import net.shibboleth.metadata.dom.saml.mdattr.EntityAttributeFilteringStage.SimpleEntityAttributeContext;
+
 public class MultiPredicateMatcherTest {
 
     private final EntityAttributeContext context =
diff --git a/aggregator-pipeline/src/test/java/net/shibboleth/metadata/dom/saml/mdattr/RegistrationAuthorityMatcherTest.java b/aggregator-pipeline/src/test/java/net/shibboleth/metadata/dom/saml/mdattr/RegistrationAuthorityMatcherTest.java
index f4abeee..a6902fc 100644
--- a/aggregator-pipeline/src/test/java/net/shibboleth/metadata/dom/saml/mdattr/RegistrationAuthorityMatcherTest.java
+++ b/aggregator-pipeline/src/test/java/net/shibboleth/metadata/dom/saml/mdattr/RegistrationAuthorityMatcherTest.java
@@ -6,6 +6,9 @@ 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.SimpleEntityAttributeContext;
+
 public class RegistrationAuthorityMatcherTest {
 
     private void test(final boolean expected, final Predicate<EntityAttributeContext> matcher,
diff --git a/aggregator-pipeline/src/test/java/net/shibboleth/metadata/dom/saml/mdattr/SimpleEntityAttributeContextTest.java b/aggregator-pipeline/src/test/java/net/shibboleth/metadata/dom/saml/mdattr/SimpleEntityAttributeContextTest.java
index e4fe919..d53ea1a 100644
--- a/aggregator-pipeline/src/test/java/net/shibboleth/metadata/dom/saml/mdattr/SimpleEntityAttributeContextTest.java
+++ b/aggregator-pipeline/src/test/java/net/shibboleth/metadata/dom/saml/mdattr/SimpleEntityAttributeContextTest.java
@@ -5,6 +5,9 @@ package net.shibboleth.metadata.dom.saml.mdattr;
 import org.testng.Assert;
 import org.testng.annotations.Test;
 
+import net.shibboleth.metadata.dom.saml.mdattr.EntityAttributeFilteringStage.EntityAttributeContext;
+import net.shibboleth.metadata.dom.saml.mdattr.EntityAttributeFilteringStage.SimpleEntityAttributeContext;
+
 public class SimpleEntityAttributeContextTest {
 
     @Test

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


More information about the commits mailing list