jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r1049516 - in /jackrabbit/branches/2.2: ./ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/ jackrabbit-core/src/test/java/org/apache/jackrabbit/api/security/user/ jackrabbit-core/src/test/java/org/apache/jackrabbit/co...
Date Wed, 15 Dec 2010 12:11:04 GMT
Author: angela
Date: Wed Dec 15 12:11:03 2010
New Revision: 1049516

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

Modified:
    jackrabbit/branches/2.2/   (props changed)
    jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/GroupImpl.java
    jackrabbit/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/api/security/user/GroupTest.java
    jackrabbit/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/GroupImplTest.java

Propchange: jackrabbit/branches/2.2/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Dec 15 12:11:03 2010
@@ -2,4 +2,4 @@
 /jackrabbit/sandbox/JCR-1456:774917-886178
 /jackrabbit/sandbox/JCR-2170:812417-816332
 /jackrabbit/sandbox/tripod-JCR-2209:795441-795863
-/jackrabbit/trunk:1038201,1038203,1038205,1038657,1039064,1039347,1039408,1039422-1039423,1039888,1039946,1040033,1040090,1040459,1040601,1040606,1040661,1040958,1041379,1041439,1041761,1042643,1042647,1042978-1042982,1043084-1043086,1043088,1043343,1043357-1043358,1043430,1043554,1043616,1043618,1043637,1043656,1044312,1049473
+/jackrabbit/trunk:1038201,1038203,1038205,1038657,1039064,1039347,1039408,1039422-1039423,1039888,1039946,1040033,1040090,1040459,1040601,1040606,1040661,1040958,1041379,1041439,1041761,1042643,1042647,1042978-1042982,1043084-1043086,1043088,1043343,1043357-1043358,1043430,1043554,1043616,1043618,1043637,1043656,1044312,1049473,1049491

Modified: jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/GroupImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/GroupImpl.java?rev=1049516&r1=1049515&r2=1049516&view=diff
==============================================================================
--- jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/GroupImpl.java
(original)
+++ jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/GroupImpl.java
Wed Dec 15 12:11:03 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/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/api/security/user/GroupTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/api/security/user/GroupTest.java?rev=1049516&r1=1049515&r2=1049516&view=diff
==============================================================================
--- jackrabbit/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/api/security/user/GroupTest.java
(original)
+++ jackrabbit/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/api/security/user/GroupTest.java
Wed Dec 15 12:11:03 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/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/GroupImplTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/GroupImplTest.java?rev=1049516&r1=1049515&r2=1049516&view=diff
==============================================================================
--- jackrabbit/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/GroupImplTest.java
(original)
+++ jackrabbit/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/GroupImplTest.java
Wed Dec 15 12:11:03 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