jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1205400 - in /jackrabbit/trunk/jackrabbit-core/src: main/java/org/apache/jackrabbit/core/security/user/GroupImpl.java test/java/org/apache/jackrabbit/api/security/user/GroupTest.java
Date Wed, 23 Nov 2011 14:06:03 GMT
Author: mduerig
Date: Wed Nov 23 14:06:03 2011
New Revision: 1205400

URL: http://svn.apache.org/viewvc?rev=1205400&view=rev
Log:
JCR-3156: Group#getMembers may list inherited members multiple times

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/GroupImpl.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/api/security/user/GroupTest.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/GroupImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/GroupImpl.java?rev=1205400&r1=1205399&r2=1205400&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/GroupImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/GroupImpl.java
Wed Nov 23 14:06:03 2011
@@ -646,7 +646,31 @@ class GroupImpl extends AuthorizableImpl
             }
         };
 
-        return new LazyIteratorChain<Authorizable>(indirectMembers);
+        return unique(new LazyIteratorChain<Authorizable>(indirectMembers));
+    }
+
+    /**
+     * Filter the passed {@code authorizables} in order to ensure uniqueness.
+     * @param authorizables
+     * @return  all members of {@code authorizable} with duplicates removed
+     *
+     * @see <a href="https://issues.apache.org/jira/browse/JCR-3156">JCR-3156</a>
+     */
+    private Iterator<Authorizable> unique(Iterator<Authorizable> authorizables)
{
+        final HashSet<String> seenAuthorizables = new HashSet<String>();
+        return Iterators.filterIterator(authorizables,
+                new org.apache.jackrabbit.spi.commons.iterator.Predicate<Authorizable>()
{
+
+            public boolean evaluate(Authorizable authorizable) {
+                try {
+                    return seenAuthorizables.add(authorizable.getID());
+                }
+                catch (RepositoryException e) {
+                    log.warn("Could not determine id of " + authorizable, e);
+                    return true;
+                }
+            }
+        });
     }
 
     /**

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/api/security/user/GroupTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/api/security/user/GroupTest.java?rev=1205400&r1=1205399&r2=1205400&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/api/security/user/GroupTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/api/security/user/GroupTest.java
Wed Nov 23 14:06:03 2011
@@ -474,14 +474,44 @@ public class GroupTest extends AbstractU
                 assertTrue(a.equals(auth) || allGroups.remove(a));
             }
             assertTrue(allGroups.isEmpty());
-        }
-        finally {
+        } finally {
             for (Group g : groups) {
                 g.remove();
             }
         }
     }
 
+    public void testInheritedMembers() throws Exception {
+        Set<Authorizable> authorizables = new HashSet<Authorizable>();
+        try {
+            User testUser = userMgr.createUser(getTestPrincipal().getName(), "pw");
+            authorizables.add(testUser);
+            Group group1 = userMgr.createGroup(getTestPrincipal());
+            authorizables.add(group1);
+            Group group2 = userMgr.createGroup(getTestPrincipal());
+            authorizables.add(group2);
+            Group group3 = userMgr.createGroup(getTestPrincipal());
+
+            group1.addMember(testUser);
+            group2.addMember(testUser);
+            group3.addMember(group1);
+            group3.addMember(group2);
+
+            Iterator<Authorizable> members = group3.getMembers();
+            while (members.hasNext()) {
+                Authorizable a = members.next();
+                assertTrue(authorizables.contains(a));
+                assertTrue(authorizables.remove(a));
+            }
+
+            assertTrue(authorizables.isEmpty());
+        } finally {
+            for (Authorizable a : authorizables) {
+                a.remove();
+            }
+        }
+    }
+
     public void testCyclicGroups() throws AuthorizableExistsException, RepositoryException,
NotExecutableException {
         Group group1 = null;
         Group group2 = null;
@@ -610,4 +640,4 @@ public class GroupTest extends AbstractU
         }
     }
 
-}
\ No newline at end of file
+}



Mime
View raw message