jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r1049491 - in /jackrabbit/trunk/jackrabbit-core/src: main/java/org/apache/jackrabbit/core/security/user/ test/java/org/apache/jackrabbit/api/security/user/ test/java/org/apache/jackrabbit/core/security/user/
Date Wed, 15 Dec 2010 10:49:50 GMT
Author: angela
Date: Wed Dec 15 10:49:49 2010
New Revision: 1049491

URL: http://svn.apache.org/viewvc?rev=1049491&view=rev
Log:
JCR-2845   	 NodeBasedGroup#isMember(Principal) should have shortcut for the everyone group.

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
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/GroupImplTest.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=1049491&r1=1049490&r2=1049491&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 Dec 15 10:49:49 2010
@@ -260,7 +260,9 @@ class GroupImpl extends AuthorizableImpl
     }
 
     //------------------------------------------------------< inner classes >---
-
+    /**
+     * Principal Implementation
+     */
     private class NodeBasedGroup extends NodeBasedPrincipal implements java.security.acl.Group
{
 
         private Set<Principal> members;
@@ -287,20 +289,18 @@ class GroupImpl extends AuthorizableImpl
          * @see java.security.acl.Group#isMember(Principal)
          */
         public boolean isMember(Principal member) {
-            Collection<Principal> members = getMembers();
-            if (members.contains(member)) {
-                // shortcut.
-                return true;
-            }
-
-            // test if member of a member-group
-            for (Principal p : members) {
-                if (p instanceof java.security.acl.Group &&
-                        ((java.security.acl.Group) p).isMember(member)) {
-                    return true;
+            // shortcut for everyone group -> avoid collecting all members
+            // as all users and groups are member of everyone.
+            try {
+                if (isEveryone()) {
+                    return !getPrincipal().equals(member);
                 }
+            } catch (RepositoryException e) {
+                // continue using regular membership evaluation
             }
-            return false;
+           
+            Collection<Principal> members = getMembers();
+            return members.contains(member);
         }
 
         /**

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=1049491&r1=1049490&r2=1049491&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 Dec 15 10:49:49 2010
@@ -403,6 +403,46 @@ public class GroupTest extends AbstractU
         }
     }
 
+    public void testMembersInPrincipal() throws NotExecutableException, RepositoryException
{
+        User auth = getTestUser(superuser);
+        Group newGroup = null;
+        Group newGroup2 = null;
+        try {
+            newGroup = userMgr.createGroup(getTestPrincipal());
+            newGroup2 = userMgr.createGroup(getTestPrincipal());
+            save(superuser);
+
+            newGroup.addMember(newGroup2);
+            save(superuser);
+            newGroup2.addMember(auth);
+            save(superuser);
+
+            java.security.acl.Group ngPrincipal = (java.security.acl.Group) newGroup.getPrincipal();
+            java.security.acl.Group ng2Principal = (java.security.acl.Group) newGroup2.getPrincipal();
+
+            assertFalse(ng2Principal.isMember(ngPrincipal));
+
+            // newGroup2 must be member of newGroup's principal
+            assertTrue(ngPrincipal.isMember(newGroup2.getPrincipal()));
+
+            // testuser must be member of newGroup2's and newGroup's principal (indirect)
+            assertTrue(ng2Principal.isMember(auth.getPrincipal()));
+            assertTrue(ngPrincipal.isMember(auth.getPrincipal()));
+
+        } finally {
+            if (newGroup != null) {
+                newGroup.removeMember(newGroup2);
+                newGroup.remove();
+                save(superuser);
+            }
+            if (newGroup2 != null) {
+                newGroup2.removeMember(auth);
+                newGroup2.remove();
+                save(superuser);
+            }
+        }
+    }
+
     public void testDeeplyNestedGroups() throws NotExecutableException, RepositoryException
{
         Set<Group> groups = new HashSet<Group>();
         try {

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/GroupImplTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/GroupImplTest.java?rev=1049491&r1=1049490&r2=1049491&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/GroupImplTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/GroupImplTest.java
Wed Dec 15 10:49:49 2010
@@ -102,4 +102,28 @@ public class GroupImplTest extends Abstr
             save(superuser);            
         }
     }
+
+    public void testEveryoneGroupPrincipal() throws Exception {
+        Group g = null;
+        try {
+            g = userMgr.createGroup(EveryonePrincipal.NAME);
+            save(superuser);
+
+            java.security.acl.Group principal = (java.security.acl.Group) g.getPrincipal();
+            assertTrue(principal.isMember(new Principal() {
+
+                public String getName() {
+                    return "test";
+                }
+            }));
+
+            assertFalse(principal.isMember(principal));
+
+        } finally {
+            if (g != null) {
+                g.remove();
+                save(superuser);
+            }
+        }
+    }
 }
\ No newline at end of file



Mime
View raw message