jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alexparvule...@apache.org
Subject svn commit: r1479812 - in /jackrabbit/branches/2.6: ./ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/GroupImpl.java jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/DefaultPrincipalProviderTest.java
Date Tue, 07 May 2013 08:46:56 GMT
Author: alexparvulescu
Date: Tue May  7 08:46:55 2013
New Revision: 1479812

URL: http://svn.apache.org/r1479812
Log:
JCR-3552 Principal associated with Group does not update members (backport to 2.6)

Modified:
    jackrabbit/branches/2.6/   (props changed)
    jackrabbit/branches/2.6/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/GroupImpl.java
    jackrabbit/branches/2.6/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/DefaultPrincipalProviderTest.java

Propchange: jackrabbit/branches/2.6/
------------------------------------------------------------------------------
  Merged /jackrabbit/trunk:r1462205

Modified: jackrabbit/branches/2.6/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/GroupImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.6/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/GroupImpl.java?rev=1479812&r1=1479811&r2=1479812&view=diff
==============================================================================
--- jackrabbit/branches/2.6/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/GroupImpl.java
(original)
+++ jackrabbit/branches/2.6/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/GroupImpl.java
Tue May  7 08:46:55 2013
@@ -16,6 +16,27 @@
  */
 package org.apache.jackrabbit.core.security.user;
 
+import java.io.IOException;
+import java.io.ObjectOutputStream;
+import java.security.Principal;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.NoSuchElementException;
+import java.util.Set;
+import javax.jcr.ItemNotFoundException;
+import javax.jcr.Node;
+import javax.jcr.Property;
+import javax.jcr.PropertyType;
+import javax.jcr.RepositoryException;
+import javax.jcr.Value;
+
 import org.apache.jackrabbit.api.security.user.Authorizable;
 import org.apache.jackrabbit.api.security.user.Group;
 import org.apache.jackrabbit.api.security.user.UserManager;
@@ -35,28 +56,6 @@ import org.apache.jackrabbit.util.Text;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import javax.jcr.ItemNotFoundException;
-import javax.jcr.Node;
-import javax.jcr.Property;
-import javax.jcr.PropertyType;
-import javax.jcr.RepositoryException;
-import javax.jcr.Value;
-
-import java.io.IOException;
-import java.io.ObjectOutputStream;
-import java.security.Principal;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.Enumeration;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.NoSuchElementException;
-import java.util.Set;
-
 /**
  * GroupImpl...
  */
@@ -282,8 +281,6 @@ class GroupImpl extends AuthorizableImpl
      */
     private class NodeBasedGroup extends NodeBasedPrincipal implements java.security.acl.Group
{
 
-        private Set<Principal> members;
-
         private NodeBasedGroup(String name) {
             super(name);
         }
@@ -359,16 +356,14 @@ class GroupImpl extends AuthorizableImpl
          * @return the members of this group principal.
          */
         private Collection<Principal> getMembers() {
-            if (members == null) {
-                members = new HashSet<Principal>();
-                try {
-                    for (Iterator<Authorizable> it = GroupImpl.this.getMembers(); it.hasNext();
) {
-                        members.add(it.next().getPrincipal());
-                    }
-                } catch (RepositoryException e) {
-                    // should not occur.
-                    log.error("Unable to retrieve Group members.");
+            Set<Principal> members = new HashSet<Principal>();
+            try {
+                for (Iterator<Authorizable> it = GroupImpl.this.getMembers(); it.hasNext();
) {
+                    members.add(it.next().getPrincipal());
                 }
+            } catch (RepositoryException e) {
+                // should not occur.
+                log.error("Unable to retrieve Group members.");
             }
             return members;
         }

Modified: jackrabbit/branches/2.6/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/DefaultPrincipalProviderTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.6/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/DefaultPrincipalProviderTest.java?rev=1479812&r1=1479811&r2=1479812&view=diff
==============================================================================
--- jackrabbit/branches/2.6/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/DefaultPrincipalProviderTest.java
(original)
+++ jackrabbit/branches/2.6/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/DefaultPrincipalProviderTest.java
Tue May  7 08:46:55 2013
@@ -16,6 +16,12 @@
  */
 package org.apache.jackrabbit.core.security.user;
 
+import java.security.Principal;
+import java.util.Properties;
+import java.util.Set;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+
 import org.apache.jackrabbit.api.security.principal.PrincipalIterator;
 import org.apache.jackrabbit.api.security.user.AbstractUserTest;
 import org.apache.jackrabbit.api.security.user.Authorizable;
@@ -27,12 +33,6 @@ import org.apache.jackrabbit.core.securi
 import org.apache.jackrabbit.core.security.principal.PrincipalProvider;
 import org.apache.jackrabbit.test.NotExecutableException;
 
-import javax.jcr.RepositoryException;
-import javax.jcr.Session;
-import java.security.Principal;
-import java.util.Properties;
-import java.util.Set;
-
 /**
  * <code>DefaultPrincipalProviderTest</code>...
  */
@@ -227,4 +227,37 @@ public class DefaultPrincipalProviderTes
             }
         }
     }
+
+    /**
+     * Test for: Principal assiocated with Group does not update members
+     * @see <a href=https://issues.apache.org/jira/browse/JCR-3552>JCR-3552</a>
+     */
+    public void testGroupMembership() throws Exception {
+        Group g = null;
+        User u = null;
+        Principal up = getTestPrincipal();
+        try {
+            // create a group and user, add the user to the group and assert membership
+            g = userMgr.createGroup(getTestPrincipal());
+            u = userMgr.createUser(up.getName(), buildPassword(up));
+            save(superuser);
+            g.addMember(u);
+            save(superuser);
+
+            Principal groupPrincipal = principalProvider.getPrincipal(g.getPrincipal().getName());
+            assertTrue(groupPrincipal instanceof java.security.acl.Group);
+            assertTrue(((java.security.acl.Group) groupPrincipal).isMember(u.getPrincipal()));
+
+            // remove the user from the group and assert the user is no longer a member of
the group
+            g.removeMember(u);
+            save(superuser);
+
+            groupPrincipal = principalProvider.getPrincipal(g.getPrincipal().getName());
+            assertFalse(((java.security.acl.Group) groupPrincipal).isMember(u.getPrincipal()));
+        } finally {
+            if (null != g) { g.remove(); }
+            if (null != u) { u.remove(); }
+            save(superuser);
+        }
+    }
 }
\ No newline at end of file



Mime
View raw message