jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1031115 - in /jackrabbit/trunk: jackrabbit-api/src/main/java/org/apache/jackrabbit/api/security/user/ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/ jackrabbit-core/src/test/java/org/apache/jackrabbit/api/security/...
Date Thu, 04 Nov 2010 18:07:28 GMT
Author: mduerig
Date: Thu Nov  4 18:07:28 2010
New Revision: 1031115

URL: http://svn.apache.org/viewvc?rev=1031115&view=rev
Log:
JCR-2804: Add isDeclaredMember() method to Group

Modified:
    jackrabbit/trunk/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/security/user/Group.java
    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-api/src/main/java/org/apache/jackrabbit/api/security/user/Group.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/security/user/Group.java?rev=1031115&r1=1031114&r2=1031115&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/security/user/Group.java
(original)
+++ jackrabbit/trunk/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/security/user/Group.java
Thu Nov  4 18:07:28 2010
@@ -40,6 +40,14 @@ public interface Group extends Authoriza
     Iterator<Authorizable> getMembers() throws RepositoryException;
 
     /**
+     * Test whether an {@link Authorizable} is a declared member of this group.
+     * @param authorizable  The <code>Authorizable</code> to test.
+     * @return  <code>true</code> if the Authorizable to test is a direct member
+     * @throws RepositoryException  If an error occurs.
+     */
+    boolean isDeclaredMember(Authorizable authorizable) throws RepositoryException;
+    
+    /**
      * @param authorizable The <code>Authorizable</code> to test.
      * @return true if the Authorizable to test is a direct or indirect member
      * of this Group.

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=1031115&r1=1031114&r2=1031115&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
Thu Nov  4 18:07:28 2010
@@ -104,6 +104,16 @@ class GroupImpl extends AuthorizableImpl
         return getMembers(true, UserManager.SEARCH_TYPE_AUTHORIZABLE);
     }
 
+    public boolean isDeclaredMember(Authorizable authorizable) throws RepositoryException
{
+        if (authorizable == null || !(authorizable instanceof AuthorizableImpl)
+                || getNode().isSame(((AuthorizableImpl) authorizable).getNode())) {
+            return false;
+        }
+        else {
+            return getMembershipProvider(getNode()).hasMember((AuthorizableImpl) authorizable);
+        }
+    }
+
     /**
      * @see Group#isMember(Authorizable)
      */
@@ -330,6 +340,7 @@ class GroupImpl extends AuthorizableImpl
         boolean addMember(AuthorizableImpl authorizable) throws RepositoryException;
         boolean removeMember(AuthorizableImpl authorizable) throws RepositoryException;
         Iterator<Authorizable> getMembers(boolean includeIndirect, int type) throws
RepositoryException;
+        boolean hasMember(AuthorizableImpl authorizable) throws RepositoryException;
     }
 
     private class PropertyBasedMembershipProvider implements MembershipProvider {
@@ -413,6 +424,21 @@ class GroupImpl extends AuthorizableImpl
             }
         }
 
+        public boolean hasMember(AuthorizableImpl authorizable) throws RepositoryException
{
+            if (node.hasProperty(P_MEMBERS)) {
+                Value[] members = node.getProperty(P_MEMBERS).getValues();
+                for (Value v : members) {
+                    if (authorizable.getNode().getIdentifier().equals(v.getString())) {
+                        return true;
+                    }
+                }
+                return false;
+            }
+            else {
+                return false;
+            }
+        }
+
     }
 
     private class NodeBasedMembershipProvider implements MembershipProvider {
@@ -510,6 +536,16 @@ class GroupImpl extends AuthorizableImpl
             }
         }
 
+        public boolean hasMember(AuthorizableImpl authorizable) throws RepositoryException
{
+            if (node.hasNode(N_MEMBERS)) {
+                PropertySequence members = getPropertySequence(node.getNode(N_MEMBERS), userManager);
+                return members.hasItem(authorizable.getID());
+            }
+            else {
+                return false;
+            }
+        }
+
     }
 
     // -----------------------------------------------------< utility >---

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=1031115&r1=1031114&r2=1031115&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
Thu Nov  4 18:07:28 2010
@@ -258,6 +258,43 @@ public class GroupTest extends AbstractU
         }
     }
 
+    public void testIsDeclaredMember() throws RepositoryException, NotExecutableException
{
+        User auth = getTestUser(superuser);
+        Group newGroup1 = null;
+        Group newGroup2 = null;
+        try {
+            newGroup1 = userMgr.createGroup(getTestPrincipal());
+            newGroup2 = userMgr.createGroup(getTestPrincipal());
+            save(superuser);
+
+            assertFalse(newGroup1.isDeclaredMember(auth));
+            assertFalse(newGroup2.isDeclaredMember(auth));
+
+            assertTrue(newGroup2.addMember(auth));
+            save(superuser);
+            assertTrue(newGroup2.isDeclaredMember(auth));
+            assertTrue(newGroup2.isDeclaredMember(userMgr.getAuthorizable(auth.getID())));
+
+            assertTrue(newGroup1.addMember(newGroup2));
+            save(superuser);
+            assertTrue(newGroup1.isDeclaredMember(newGroup2));
+            assertTrue(newGroup1.isDeclaredMember(userMgr.getAuthorizable(newGroup2.getID())));
+            assertTrue(newGroup1.isMember(auth));
+            assertTrue(newGroup1.isMember(userMgr.getAuthorizable(auth.getID())));
+            assertFalse(newGroup1.isDeclaredMember(auth));
+            assertFalse(newGroup1.isDeclaredMember(userMgr.getAuthorizable(auth.getID())));
+        } finally {
+            if (newGroup1 != null) {
+                newGroup1.remove();
+                save(superuser);
+            }
+            if (newGroup2 != null) {
+                newGroup2.remove();
+                save(superuser);
+            }
+        }
+    }
+
     public void testAddMemberTwice() throws NotExecutableException, RepositoryException {
         User auth = getTestUser(superuser);
         Group newGroup = null;
@@ -532,4 +569,5 @@ public class GroupTest extends AbstractU
             assertFalse(groupId.equals(it.next().getID()));
         }
     }
+
 }
\ No newline at end of file



Mime
View raw message