[java-opensaml COMMIT] /trunk/opensaml-saml-api/src/main/java/org/opensaml/saml/common/profile/logic/EntityAttributes...

noreply at shibboleth.net noreply at shibboleth.net
Wed Jun 10 08:54:30 EDT 2015


Author: scantor
Date: Wed Jun 10 08:54:30 2015
New Revision: 4295

URL: http://svn.shibboleth.net/view/java-opensaml?rev=4295&view=rev
Log:
IDP-739 - EntityAttributesPredicate needs more boolean flexibility

Modified:
    trunk/opensaml-saml-api/src/main/java/org/opensaml/saml/common/profile/logic/EntityAttributesPredicate.java

Modified: trunk/opensaml-saml-api/src/main/java/org/opensaml/saml/common/profile/logic/EntityAttributesPredicate.java
URL: http://svn.shibboleth.net/view/java-opensaml/trunk/opensaml-saml-api/src/main/java/org/opensaml/saml/common/profile/logic/EntityAttributesPredicate.java?rev=4295&r1=4294&r2=4295&view=diff
==============================================================================
--- trunk/opensaml-saml-api/src/main/java/org/opensaml/saml/common/profile/logic/EntityAttributesPredicate.java	(original)
+++ trunk/opensaml-saml-api/src/main/java/org/opensaml/saml/common/profile/logic/EntityAttributesPredicate.java	Wed Jun 10 08:54:30 2015
@@ -68,6 +68,9 @@
     /** Whether to trim the values in the metadata before comparison. */
     private final boolean trimTags;
     
+    /** Whether all the candidates must match. */
+    private final boolean matchAll;
+    
     /** Candidates to check for. */
     @Nonnull @NonnullElements private final Collection<Candidate> candidateSet;
     
@@ -85,7 +88,26 @@
         candidateSet = new ArrayList<>(Collections2.filter(candidates, Predicates.notNull()));
         
         trimTags = trim;
-    }
+        matchAll = false;
+    }
+    
+    /**
+     * Constructor.
+     * 
+     * @param candidates the {@link Candidate} criteria to check for
+     * @param trim true iff the values found in the metadata should be trimmed before comparison
+     * @param all true iff all the criteria must match to be a successful test
+     */
+    public EntityAttributesPredicate(@Nonnull @NonnullElements final Collection<Candidate> candidates,
+            final boolean trim, final boolean all) {
+        
+        Constraint.isNotNull(candidates, "Attribute collection cannot be null");
+        
+        candidateSet = new ArrayList<>(Collections2.filter(candidates, Predicates.notNull()));
+        
+        trimTags = trim;
+        matchAll = all;
+    }    
     
     /**
      * Get whether to trim tags for comparison.
@@ -149,8 +171,13 @@
         
         // If we find a matching tag, we win. Each tag is treated in OR fashion.
         final EntityAttributesMatcher matcher = new EntityAttributesMatcher(entityAttributes);
-        if (Iterables.tryFind(candidateSet, matcher).isPresent()) {
-            return true;
+        
+        if (matchAll) {
+            return Iterables.all(candidateSet, matcher);
+        } else {
+            if (Iterables.tryFind(candidateSet, matcher).isPresent()) {
+                return true;
+            }
         }
 
         return false;



More information about the commits mailing list