[java-identity-provider] 02/02: IDP-1121 Use LinkedHashSets in Attribute Filtering

Rod Widdowson rdw at steadingsoftware.com
Sat May 18 06:18:03 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=3d8f144f09a9987a6f7c4eddb1c7f8e7c86d9ef1

commit 3d8f144f09a9987a6f7c4eddb1c7f8e7c86d9ef1
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Sat May 18 11:17:14 2019 +0100

    IDP-1121 Use LinkedHashSets in Attribute Filtering
    
    https://issues.shibboleth.net/jira/browse/IDP-1121
    
    We need to use sets to make logic work, but we also want to preserve
    value order as much as we can
---
 .../idp/attribute/filter/context/AttributeFilterWorkContext.java    | 6 +++---
 .../shibboleth/idp/attribute/filter/BaseBridgingClassTester.java    | 4 ++--
 .../test/java/net/shibboleth/idp/attribute/filter/MockMatcher.java  | 4 ++--
 .../idp/attribute/filter/matcher/impl/AbstractMatcher.java          | 4 ++--
 .../idp/attribute/filter/matcher/impl/ScriptedMatcher.java          | 4 ++--
 .../idp/attribute/filter/matcher/logic/impl/AndMatcher.java         | 4 ++--
 .../idp/attribute/filter/matcher/logic/impl/NotMatcher.java         | 4 ++--
 .../idp/attribute/filter/matcher/logic/impl/OrMatcher.java          | 4 ++--
 .../filter/matcher/saml/impl/AttributeInMetadataMatcher.java        | 6 +++---
 .../policyrule/saml/impl/RegistrationAuthorityPolicyRule.java       | 4 ++--
 .../idp/attribute/filter/matcher/impl/ScriptedMatcherTest.java      | 4 ++--
 .../filtercontext/impl/NumOfAttributeValuesPolicyRuleTest.java      | 4 ++--
 12 files changed, 26 insertions(+), 26 deletions(-)

diff --git a/idp-attribute-filter-api/src/main/java/net/shibboleth/idp/attribute/filter/context/AttributeFilterWorkContext.java b/idp-attribute-filter-api/src/main/java/net/shibboleth/idp/attribute/filter/context/AttributeFilterWorkContext.java
index 17dcb87..6fcc0a5 100644
--- a/idp-attribute-filter-api/src/main/java/net/shibboleth/idp/attribute/filter/context/AttributeFilterWorkContext.java
+++ b/idp-attribute-filter-api/src/main/java/net/shibboleth/idp/attribute/filter/context/AttributeFilterWorkContext.java
@@ -20,7 +20,7 @@ package net.shibboleth.idp.attribute.filter.context;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
-import java.util.HashSet;
+import java.util.LinkedHashSet;
 import java.util.Map;
 import java.util.Set;
 
@@ -96,7 +96,7 @@ public final class AttributeFilterWorkContext extends BaseContext {
 
         Set<IdPAttributeValue> permittedAttributeValues = permittedValues.get(trimmedAttributeId);
         if (permittedAttributeValues == null) {
-            permittedAttributeValues = new HashSet<>();
+            permittedAttributeValues = new LinkedHashSet<>();
             permittedValues.put(trimmedAttributeId, permittedAttributeValues);
         }
 
@@ -147,7 +147,7 @@ public final class AttributeFilterWorkContext extends BaseContext {
 
         Set<IdPAttributeValue> deniedAttributeValues = deniedValues.get(trimmedAttributeId);
         if (deniedAttributeValues == null) {
-            deniedAttributeValues = new HashSet<>();
+            deniedAttributeValues = new LinkedHashSet<>();
             deniedValues.put(trimmedAttributeId, deniedAttributeValues);
         }
 
diff --git a/idp-attribute-filter-api/src/test/java/net/shibboleth/idp/attribute/filter/BaseBridgingClassTester.java b/idp-attribute-filter-api/src/test/java/net/shibboleth/idp/attribute/filter/BaseBridgingClassTester.java
index af58b4e..e8e5264 100644
--- a/idp-attribute-filter-api/src/test/java/net/shibboleth/idp/attribute/filter/BaseBridgingClassTester.java
+++ b/idp-attribute-filter-api/src/test/java/net/shibboleth/idp/attribute/filter/BaseBridgingClassTester.java
@@ -18,7 +18,7 @@
 package net.shibboleth.idp.attribute.filter;
 
 import java.util.Arrays;
-import java.util.HashSet;
+import java.util.LinkedHashSet;
 
 import net.shibboleth.idp.attribute.IdPAttribute;
 import net.shibboleth.idp.attribute.IdPAttributeValue;
@@ -42,7 +42,7 @@ public class BaseBridgingClassTester {
     protected final String NAME2 = "bar";
     
     protected AttributeFilterContext setUpCtx() {
-        HashSet<IdPAttribute> attributes = new HashSet<>(2);
+        LinkedHashSet<IdPAttribute> attributes = new LinkedHashSet<>(2);
 
         IdPAttribute attribute = new IdPAttribute(NAME1);
         attribute.setValues(Arrays.asList(VALUE1, VALUE2));
diff --git a/idp-attribute-filter-api/src/test/java/net/shibboleth/idp/attribute/filter/MockMatcher.java b/idp-attribute-filter-api/src/test/java/net/shibboleth/idp/attribute/filter/MockMatcher.java
index 32033da..5376afd 100644
--- a/idp-attribute-filter-api/src/test/java/net/shibboleth/idp/attribute/filter/MockMatcher.java
+++ b/idp-attribute-filter-api/src/test/java/net/shibboleth/idp/attribute/filter/MockMatcher.java
@@ -19,7 +19,7 @@ package net.shibboleth.idp.attribute.filter;
 
 import java.util.Collection;
 import java.util.Collections;
-import java.util.HashSet;
+import java.util.LinkedHashSet;
 import java.util.Objects;
 import java.util.Set;
 
@@ -91,7 +91,7 @@ public class MockMatcher extends AbstractIdentifiedInitializableComponent implem
             return ImmutableSet.copyOf(attribute.getValues());
         }
 
-        HashSet<IdPAttributeValue> values = new HashSet<>();
+        LinkedHashSet<IdPAttributeValue> values = new LinkedHashSet<>();
         for (IdPAttributeValue value : attribute.getValues()) {
             if (matchingValues.contains(value)) {
                 values.add(value);
diff --git a/idp-attribute-filter-impl/src/main/java/net/shibboleth/idp/attribute/filter/matcher/impl/AbstractMatcher.java b/idp-attribute-filter-impl/src/main/java/net/shibboleth/idp/attribute/filter/matcher/impl/AbstractMatcher.java
index bf087b6..3c1574f 100644
--- a/idp-attribute-filter-impl/src/main/java/net/shibboleth/idp/attribute/filter/matcher/impl/AbstractMatcher.java
+++ b/idp-attribute-filter-impl/src/main/java/net/shibboleth/idp/attribute/filter/matcher/impl/AbstractMatcher.java
@@ -18,7 +18,7 @@
 package net.shibboleth.idp.attribute.filter.matcher.impl;
 
 import java.util.Collections;
-import java.util.HashSet;
+import java.util.LinkedHashSet;
 import java.util.Set;
 
 import javax.annotation.Nonnull;
@@ -61,7 +61,7 @@ public abstract class AbstractMatcher extends AbstractIdentifiableInitializableC
     @Override @Nonnull @NonnullElements @Unmodifiable public Set<IdPAttributeValue> getMatchingValues(
             @Nonnull final IdPAttribute attribute, @Nonnull final AttributeFilterContext filterContext) {
 
-        final HashSet matchedValues = new HashSet();
+        final Set<IdPAttributeValue> matchedValues = new LinkedHashSet<>();
 
         log.debug("{} Applying value comparison to all values of Attribute '{}'", getLogPrefix(), attribute.getId());
 
diff --git a/idp-attribute-filter-impl/src/main/java/net/shibboleth/idp/attribute/filter/matcher/impl/ScriptedMatcher.java b/idp-attribute-filter-impl/src/main/java/net/shibboleth/idp/attribute/filter/matcher/impl/ScriptedMatcher.java
index aae136a..d375065 100644
--- a/idp-attribute-filter-impl/src/main/java/net/shibboleth/idp/attribute/filter/matcher/impl/ScriptedMatcher.java
+++ b/idp-attribute-filter-impl/src/main/java/net/shibboleth/idp/attribute/filter/matcher/impl/ScriptedMatcher.java
@@ -18,7 +18,7 @@
 package net.shibboleth.idp.attribute.filter.matcher.impl;
 
 import java.util.Collections;
-import java.util.HashSet;
+import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Objects;
 import java.util.Set;
@@ -264,7 +264,7 @@ public class ScriptedMatcher extends AbstractIdentifiableInitializableComponent
                 return null;
             }
 
-            final HashSet<IdPAttributeValue> returnValues = new HashSet<>(attribute.getValues());
+            final Set<IdPAttributeValue> returnValues = new LinkedHashSet<>(attribute.getValues());
             returnValues.retainAll((Set) result);
             return Collections.unmodifiableSet(returnValues);
         }
diff --git a/idp-attribute-filter-impl/src/main/java/net/shibboleth/idp/attribute/filter/matcher/logic/impl/AndMatcher.java b/idp-attribute-filter-impl/src/main/java/net/shibboleth/idp/attribute/filter/matcher/logic/impl/AndMatcher.java
index 3f6f719..265d820 100644
--- a/idp-attribute-filter-impl/src/main/java/net/shibboleth/idp/attribute/filter/matcher/logic/impl/AndMatcher.java
+++ b/idp-attribute-filter-impl/src/main/java/net/shibboleth/idp/attribute/filter/matcher/logic/impl/AndMatcher.java
@@ -18,7 +18,7 @@
 package net.shibboleth.idp.attribute.filter.matcher.logic.impl;
 
 import java.util.Collections;
-import java.util.HashSet;
+import java.util.LinkedHashSet;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Set;
@@ -71,7 +71,7 @@ public class AndMatcher extends AbstractComposedMatcher {
         if (null == match) {
             return null;
         }
-        final Set<IdPAttributeValue> matchingValues = new HashSet(match);
+        final Set<IdPAttributeValue> matchingValues = new LinkedHashSet(match);
         while (matcherItr.hasNext()) {
             match = matcherItr.next().getMatchingValues(attribute, filterContext);
             if (null == match) {
diff --git a/idp-attribute-filter-impl/src/main/java/net/shibboleth/idp/attribute/filter/matcher/logic/impl/NotMatcher.java b/idp-attribute-filter-impl/src/main/java/net/shibboleth/idp/attribute/filter/matcher/logic/impl/NotMatcher.java
index 9693fc8..8081cd1 100644
--- a/idp-attribute-filter-impl/src/main/java/net/shibboleth/idp/attribute/filter/matcher/logic/impl/NotMatcher.java
+++ b/idp-attribute-filter-impl/src/main/java/net/shibboleth/idp/attribute/filter/matcher/logic/impl/NotMatcher.java
@@ -18,7 +18,7 @@
 package net.shibboleth.idp.attribute.filter.matcher.logic.impl;
 
 import java.util.Collections;
-import java.util.HashSet;
+import java.util.LinkedHashSet;
 import java.util.Set;
 
 import javax.annotation.Nonnull;
@@ -83,7 +83,7 @@ public final class NotMatcher extends AbstractIdentifiableInitializableComponent
         ComponentSupport.ifNotInitializedThrowUninitializedComponentException(this);
         ComponentSupport.ifDestroyedThrowDestroyedComponentException(this);
 
-        final Set<IdPAttributeValue> attributeValues = new HashSet<>(attribute.getValues());
+        final Set<IdPAttributeValue> attributeValues = new LinkedHashSet<>(attribute.getValues());
 
         final Set<IdPAttributeValue> matches = currentMatcher.getMatchingValues(attribute, filterContext);
         if (null == matches) {
diff --git a/idp-attribute-filter-impl/src/main/java/net/shibboleth/idp/attribute/filter/matcher/logic/impl/OrMatcher.java b/idp-attribute-filter-impl/src/main/java/net/shibboleth/idp/attribute/filter/matcher/logic/impl/OrMatcher.java
index 2bcde5e..faa64a5 100644
--- a/idp-attribute-filter-impl/src/main/java/net/shibboleth/idp/attribute/filter/matcher/logic/impl/OrMatcher.java
+++ b/idp-attribute-filter-impl/src/main/java/net/shibboleth/idp/attribute/filter/matcher/logic/impl/OrMatcher.java
@@ -18,6 +18,7 @@
 package net.shibboleth.idp.attribute.filter.matcher.logic.impl;
 
 import java.util.Collections;
+import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Set;
 
@@ -30,7 +31,6 @@ import net.shibboleth.idp.attribute.IdPAttributeValue;
 import net.shibboleth.idp.attribute.filter.Matcher;
 import net.shibboleth.idp.attribute.filter.context.AttributeFilterContext;
 import net.shibboleth.utilities.java.support.annotation.constraint.NonnullElements;
-import net.shibboleth.utilities.java.support.collection.LazySet;
 import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
 import net.shibboleth.utilities.java.support.component.ComponentSupport;
 import net.shibboleth.utilities.java.support.logic.Constraint;
@@ -56,7 +56,7 @@ public class OrMatcher extends AbstractComposedMatcher {
         ComponentSupport.ifNotInitializedThrowUninitializedComponentException(this);
         ComponentSupport.ifDestroyedThrowDestroyedComponentException(this);
 
-        final Set<IdPAttributeValue> matchingValues = new LazySet<>();
+        final Set<IdPAttributeValue> matchingValues = new LinkedHashSet<>();
         for (final Matcher matchFunctor : currentMatchers) {
             final Set<IdPAttributeValue> matches = matchFunctor.getMatchingValues(attribute, filterContext);
             if (null == matches) {
diff --git a/idp-attribute-filter-impl/src/main/java/net/shibboleth/idp/attribute/filter/matcher/saml/impl/AttributeInMetadataMatcher.java b/idp-attribute-filter-impl/src/main/java/net/shibboleth/idp/attribute/filter/matcher/saml/impl/AttributeInMetadataMatcher.java
index b51222a..20bc142 100644
--- a/idp-attribute-filter-impl/src/main/java/net/shibboleth/idp/attribute/filter/matcher/saml/impl/AttributeInMetadataMatcher.java
+++ b/idp-attribute-filter-impl/src/main/java/net/shibboleth/idp/attribute/filter/matcher/saml/impl/AttributeInMetadataMatcher.java
@@ -20,7 +20,7 @@ package net.shibboleth.idp.attribute.filter.matcher.saml.impl;
 import java.time.Instant;
 import java.util.Collection;
 import java.util.Collections;
-import java.util.HashSet;
+import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Set;
 
@@ -208,7 +208,7 @@ public class AttributeInMetadataMatcher extends AbstractIdentifiableInitializabl
                 return Collections.emptySet();
             }
             
-            final Set<IdPAttributeValue> values = new HashSet<>();
+            final Set<IdPAttributeValue> values = new LinkedHashSet<>();
             values.addAll(filterValues(attributeToLog, attribute, requestedAttribute.getAttributeValues()));
             return values;
         } else {
@@ -243,7 +243,7 @@ public class AttributeInMetadataMatcher extends AbstractIdentifiableInitializabl
                 return Collections.emptySet();
             }
 
-            final Set<IdPAttributeValue> values = new HashSet<>();
+            final Set<IdPAttributeValue> values = new LinkedHashSet<>();
 
             for (final IdPAttribute requestedAttribute
                     : Collections2.filter(requestedAttributeList, Predicates.notNull())) {
diff --git a/idp-attribute-filter-impl/src/main/java/net/shibboleth/idp/attribute/filter/policyrule/saml/impl/RegistrationAuthorityPolicyRule.java b/idp-attribute-filter-impl/src/main/java/net/shibboleth/idp/attribute/filter/policyrule/saml/impl/RegistrationAuthorityPolicyRule.java
index e20b253..9cb8cf3 100644
--- a/idp-attribute-filter-impl/src/main/java/net/shibboleth/idp/attribute/filter/policyrule/saml/impl/RegistrationAuthorityPolicyRule.java
+++ b/idp-attribute-filter-impl/src/main/java/net/shibboleth/idp/attribute/filter/policyrule/saml/impl/RegistrationAuthorityPolicyRule.java
@@ -18,7 +18,7 @@
 package net.shibboleth.idp.attribute.filter.policyrule.saml.impl;
 
 import java.util.Collection;
-import java.util.HashSet;
+import java.util.LinkedHashSet;
 import java.util.Set;
 
 import javax.annotation.Nonnull;
@@ -74,7 +74,7 @@ public class RegistrationAuthorityPolicyRule extends AbstractPolicyRule {
     public void setIssuers(@Nonnull @NonnullElements final Collection<String> theIssuers) {
         Constraint.isNotNull(theIssuers, "Issuer collection cannot be null");
         
-        issuers = new HashSet<>(theIssuers.size());
+        issuers = new LinkedHashSet<>(theIssuers.size());
         for (final String s : theIssuers) {
             final String trimmed = StringSupport.trimOrNull(s);
             if (trimmed != null) {
diff --git a/idp-attribute-filter-impl/src/test/java/net/shibboleth/idp/attribute/filter/matcher/impl/ScriptedMatcherTest.java b/idp-attribute-filter-impl/src/test/java/net/shibboleth/idp/attribute/filter/matcher/impl/ScriptedMatcherTest.java
index 0533ea9..c3a7838 100644
--- a/idp-attribute-filter-impl/src/test/java/net/shibboleth/idp/attribute/filter/matcher/impl/ScriptedMatcherTest.java
+++ b/idp-attribute-filter-impl/src/test/java/net/shibboleth/idp/attribute/filter/matcher/impl/ScriptedMatcherTest.java
@@ -26,7 +26,7 @@ import static org.testng.Assert.assertTrue;
 import static org.testng.Assert.fail;
 
 import java.util.Collections;
-import java.util.HashSet;
+import java.util.LinkedHashSet;
 import java.util.Set;
 
 import javax.annotation.concurrent.ThreadSafe;
@@ -319,7 +319,7 @@ public class ScriptedMatcherTest extends AbstractMatcherPolicyRuleTest {
 
         final IdPAttribute newAttr = attribute.clone();
 
-        final Set<IdPAttributeValue> s = new HashSet(2);
+        final Set<IdPAttributeValue> s = new LinkedHashSet(2);
         s.add(new StringAttributeValue(ProfileRequestContext.class.getName()));
         s.add(new StringAttributeValue("BAR"));
         s.add(new StringAttributeValue("FOO"));
diff --git a/idp-attribute-filter-impl/src/test/java/net/shibboleth/idp/attribute/filter/policyrule/filtercontext/impl/NumOfAttributeValuesPolicyRuleTest.java b/idp-attribute-filter-impl/src/test/java/net/shibboleth/idp/attribute/filter/policyrule/filtercontext/impl/NumOfAttributeValuesPolicyRuleTest.java
index af7b8e4..038b970 100644
--- a/idp-attribute-filter-impl/src/test/java/net/shibboleth/idp/attribute/filter/policyrule/filtercontext/impl/NumOfAttributeValuesPolicyRuleTest.java
+++ b/idp-attribute-filter-impl/src/test/java/net/shibboleth/idp/attribute/filter/policyrule/filtercontext/impl/NumOfAttributeValuesPolicyRuleTest.java
@@ -21,7 +21,7 @@ import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.assertNull;
 
 import java.util.Collections;
-import java.util.HashSet;
+import java.util.LinkedHashSet;
 
 import org.testng.annotations.Test;
 
@@ -110,7 +110,7 @@ public class NumOfAttributeValuesPolicyRuleTest {
 
     private AttributeFilterContext manufactureWith(String name, int howMany) {
         final IdPAttribute attr = new IdPAttribute(name);
-        final HashSet<IdPAttributeValue> hs = new HashSet<>(howMany);
+        final LinkedHashSet<IdPAttributeValue> hs = new LinkedHashSet<>(howMany);
         
         for (int i = 0; i < howMany; i++) {
             hs.add(new StringAttributeValue(Integer.toString(i)));

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


More information about the commits mailing list