jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r1044312 - in /jackrabbit/trunk/jackrabbit-core/src: main/java/org/apache/jackrabbit/core/security/principal/ main/java/org/apache/jackrabbit/core/security/user/ test/java/org/apache/jackrabbit/core/security/principal/ test/java/org/apache/...
Date Fri, 10 Dec 2010 11:49:39 GMT
Author: angela
Date: Fri Dec 10 11:49:39 2010
New Revision: 1044312

URL: http://svn.apache.org/viewvc?rev=1044312&view=rev
Log:
JCR-2840 -  Inconsistencies if "everyone" Group is created by User Management

Added:
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/principal/EveryonePrincipalTest.java
  (with props)
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/GroupImplTest.java
  (with props)
Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/principal/DefaultPrincipalProvider.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/principal/EveryonePrincipal.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/principal/PrincipalImpl.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/principal/PrincipalManagerImpl.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/AuthorizableImpl.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/GroupImpl.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/UserManagerImpl.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/principal/TestAll.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/DefaultPrincipalProviderTest.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/TestAll.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/UserManagerImplTest.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/principal/DefaultPrincipalProvider.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/principal/DefaultPrincipalProvider.java?rev=1044312&r1=1044311&r2=1044312&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/principal/DefaultPrincipalProvider.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/principal/DefaultPrincipalProvider.java
Fri Dec 10 11:49:39 2010
@@ -121,15 +121,13 @@ public class DefaultPrincipalProvider ex
      */
     @Override
     protected Principal providePrincipal(String principalName) {
-        // check for 'everyone'
-        if (everyonePrincipal.getName().equals(principalName)) {
-            return everyonePrincipal;
-        }
         try {
             Principal principal = new PrincipalImpl(principalName);
             Authorizable ath = userManager.getAuthorizable(principal);
             if (ath != null) {
                 return ath.getPrincipal();
+            } else if (EveryonePrincipal.NAME.equals(principalName)) {
+                return everyonePrincipal;
             }
         } catch (RepositoryException e) {
             log.error("Failed to access Authorizable for Principal " + principalName, e);
@@ -351,6 +349,9 @@ public class DefaultPrincipalProvider ex
             while (authorizableItr.hasNext()) {
                 try {
                     Principal p = authorizableItr.next().getPrincipal();
+                    if (everyonePrincipal.equals(p)) {
+                        addEveryone = false;
+                    }
                     addToCache(p);
                     return p;
                 } catch (RepositoryException e) {

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/principal/EveryonePrincipal.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/principal/EveryonePrincipal.java?rev=1044312&r1=1044311&r2=1044312&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/principal/EveryonePrincipal.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/principal/EveryonePrincipal.java
Fri Dec 10 11:49:39 2010
@@ -16,15 +16,17 @@
  */
 package org.apache.jackrabbit.core.security.principal;
 
+import org.apache.jackrabbit.api.security.principal.JackrabbitPrincipal;
+
 import java.security.Principal;
 import java.util.Enumeration;
 
 /**
  * The EveryonePrincipal contains all principals (excluding itself).
  */
-public final class EveryonePrincipal implements java.security.acl.Group {
+public final class EveryonePrincipal implements java.security.acl.Group, JackrabbitPrincipal
{
 
-    private static final String NAME = "everyone";
+    public static final String NAME = "everyone";
     private static final EveryonePrincipal INSTANCE = new EveryonePrincipal();
 
     private EveryonePrincipal() { }
@@ -64,6 +66,11 @@ public final class EveryonePrincipal imp
 
     @Override
     public boolean equals(Object obj) {
-        return obj == this || obj instanceof EveryonePrincipal;
+        if (obj == this || obj instanceof EveryonePrincipal) {
+            return true;
+        } else if (obj instanceof JackrabbitPrincipal) {
+            return NAME.equals(((JackrabbitPrincipal) obj).getName());
+        }
+        return false;
     }
 }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/principal/PrincipalImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/principal/PrincipalImpl.java?rev=1044312&r1=1044311&r2=1044312&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/principal/PrincipalImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/principal/PrincipalImpl.java
Fri Dec 10 11:49:39 2010
@@ -66,7 +66,6 @@ public class PrincipalImpl implements Ja
             return true;
         }
         if (obj instanceof JackrabbitPrincipal) {
-            // TODO: check if correct
             return name.equals(((Principal) obj).getName());
         }
         return false;

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/principal/PrincipalManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/principal/PrincipalManagerImpl.java?rev=1044312&r1=1044311&r2=1044312&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/principal/PrincipalManagerImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/principal/PrincipalManagerImpl.java
Fri Dec 10 11:49:39 2010
@@ -144,7 +144,11 @@ public class PrincipalManagerImpl implem
      */
     public Principal getEveryone() {
         checkIsValid();
-        return EveryonePrincipal.getInstance();
+        Principal everyone = getPrincipal(EveryonePrincipal.NAME);
+        if (everyone == null) {
+            everyone = EveryonePrincipal.getInstance();
+        }
+        return everyone;
     }
 
     //--------------------------------------------------------------------------

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/AuthorizableImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/AuthorizableImpl.java?rev=1044312&r1=1044311&r2=1044312&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/AuthorizableImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/AuthorizableImpl.java
Fri Dec 10 11:49:39 2010
@@ -24,6 +24,7 @@ import org.apache.jackrabbit.core.NodeIm
 import org.apache.jackrabbit.core.SessionImpl;
 import org.apache.jackrabbit.core.id.NodeId;
 import org.apache.jackrabbit.core.nodetype.NodeTypeImpl;
+import org.apache.jackrabbit.core.security.principal.EveryonePrincipal;
 import org.apache.jackrabbit.core.security.principal.PrincipalImpl;
 import org.apache.jackrabbit.spi.Name;
 import org.apache.jackrabbit.util.Text;
@@ -328,6 +329,10 @@ abstract class AuthorizableImpl implemen
         return node.getProperty(P_PRINCIPAL_NAME).getString();
     }
 
+    boolean isEveryone() throws RepositoryException {
+        return isGroup() && EveryonePrincipal.NAME.equals(getPrincipalName());
+    }
+
     private Iterator<Group> collectMembership(boolean includeIndirect) throws RepositoryException
{
         Collection<String> groupNodeIds;
         MembershipCache cache = userManager.getMembershipCache();

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=1044312&r1=1044311&r2=1044312&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
Fri Dec 10 11:49:39 2010
@@ -27,6 +27,7 @@ import org.apache.jackrabbit.commons.fla
 import org.apache.jackrabbit.commons.iterator.LazyIteratorChain;
 import org.apache.jackrabbit.core.NodeImpl;
 import org.apache.jackrabbit.core.PropertyImpl;
+import org.apache.jackrabbit.core.security.principal.EveryonePrincipal;
 import org.apache.jackrabbit.core.session.SessionContext;
 import org.apache.jackrabbit.core.session.SessionWriteOperation;
 import org.apache.jackrabbit.spi.commons.iterator.Iterators;
@@ -94,22 +95,31 @@ class GroupImpl extends AuthorizableImpl
      * @see Group#getDeclaredMembers()
      */
     public Iterator<Authorizable> getDeclaredMembers() throws RepositoryException {
-        return getMembers(false, UserManager.SEARCH_TYPE_AUTHORIZABLE);
+        if (isEveryone()) {
+            return userManager.findAuthorizables(getSession().getJCRName(P_PRINCIPAL_NAME),
null, UserManager.SEARCH_TYPE_AUTHORIZABLE);
+        } else {
+            return getMembers(false, UserManager.SEARCH_TYPE_AUTHORIZABLE);
+        }
     }
 
     /**
      * @see Group#getMembers()
      */
     public Iterator<Authorizable> getMembers() throws RepositoryException {
-        return getMembers(true, UserManager.SEARCH_TYPE_AUTHORIZABLE);
+        if (isEveryone()) {
+            return getDeclaredMembers();
+        } else {
+            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 {
+        } else if (isEveryone()) {
+            return true;
+        } else {
             return getMembershipProvider(getNode()).hasMember((AuthorizableImpl) authorizable);
         }
     }
@@ -121,6 +131,8 @@ class GroupImpl extends AuthorizableImpl
         if (authorizable == null || !(authorizable instanceof AuthorizableImpl)
                 || getNode().isSame(((AuthorizableImpl) authorizable).getNode())) {
             return false;
+        } else if (isEveryone()) {
+            return true;
         } else {
             String thisID = getID();
             AuthorizableImpl impl = (AuthorizableImpl) authorizable;
@@ -141,6 +153,9 @@ class GroupImpl extends AuthorizableImpl
             log.warn("Invalid Authorizable: {}", authorizable);
             return false;
         }
+        if (isEveryone() || ((AuthorizableImpl) authorizable).isEveryone()) {
+            return false;
+        }
 
         AuthorizableImpl authImpl = ((AuthorizableImpl) authorizable);
         Node memberNode = authImpl.getNode();
@@ -167,6 +182,9 @@ class GroupImpl extends AuthorizableImpl
             log.warn("Invalid Authorizable: {}", authorizable);
             return false;
         }
+        if (isEveryone()) {
+            return false;
+        }
 
         return getMembershipProvider(getNode()).removeMember((AuthorizableImpl) authorizable);
     }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/UserManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/UserManagerImpl.java?rev=1044312&r1=1044311&r2=1044312&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/UserManagerImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/security/user/UserManagerImpl.java
Fri Dec 10 11:49:39 2010
@@ -30,6 +30,7 @@ import org.apache.jackrabbit.core.Sessio
 import org.apache.jackrabbit.core.SessionListener;
 import org.apache.jackrabbit.core.id.NodeId;
 import org.apache.jackrabbit.core.security.SystemPrincipal;
+import org.apache.jackrabbit.core.security.principal.EveryonePrincipal;
 import org.apache.jackrabbit.core.security.principal.PrincipalImpl;
 import org.apache.jackrabbit.core.session.SessionOperation;
 import org.apache.jackrabbit.spi.Name;
@@ -580,7 +581,7 @@ public class UserManagerImpl extends Pro
      * @see UserManager#createGroup(java.security.Principal, String)
      */
     public Group createGroup(Principal principal, String intermediatePath) throws AuthorizableExistsException,
RepositoryException {
-        checkValidPrincipal(principal);
+        checkValidPrincipal(principal, true);
         
         String groupID = getGroupId(principal.getName());
         return createGroup(groupID, principal, intermediatePath);
@@ -658,7 +659,7 @@ public class UserManagerImpl extends Pro
      * @throws RepositoryException If another error occurs.
      */
     void setPrincipal(NodeImpl node, Principal principal) throws AuthorizableExistsException,
RepositoryException {
-        checkValidPrincipal(principal);        
+        checkValidPrincipal(principal, node.isNodeType(NT_REP_GROUP));        
         /*
          Check if there is *another* authorizable with the same principal.
          The additional validation (nodes not be same) is required in order to
@@ -953,11 +954,15 @@ public class UserManagerImpl extends Pro
      * Throws <code>IllegalArgumentException</code> if the specified principal
      * is <code>null</code> or if it's name is <code>null</code>
or empty string.
      * @param principal
+     * @param isGroup
      */
-    private static void checkValidPrincipal(Principal principal) {
+    private static void checkValidPrincipal(Principal principal, boolean isGroup) {
         if (principal == null || principal.getName() == null || "".equals(principal.getName()))
{
             throw new IllegalArgumentException("Principal may not be null and must have a
valid name.");
         }
+        if (!isGroup && EveryonePrincipal.NAME.equals(principal.getName())) {
+            throw new IllegalArgumentException("'everyone' is a reserved group principal
name.");
+        }
     }
 
     private static int parseMembershipSplitSize(Object param) {

Added: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/principal/EveryonePrincipalTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/principal/EveryonePrincipalTest.java?rev=1044312&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/principal/EveryonePrincipalTest.java
(added)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/principal/EveryonePrincipalTest.java
Fri Dec 10 11:49:39 2010
@@ -0,0 +1,110 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.core.security.principal;
+
+import org.apache.jackrabbit.api.JackrabbitSession;
+import org.apache.jackrabbit.api.security.principal.JackrabbitPrincipal;
+import org.apache.jackrabbit.api.security.user.Group;
+import org.apache.jackrabbit.api.security.user.UserManager;
+import org.apache.jackrabbit.test.AbstractJCRTest;
+import org.apache.jackrabbit.test.NotExecutableException;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.UnsupportedRepositoryOperationException;
+import java.security.Principal;
+
+/**
+ * <code>EveryonePrincipalTest</code>...
+ */
+public class EveryonePrincipalTest extends AbstractJCRTest {
+
+    public void testEveryonePrincipal() {
+        Principal everyone = EveryonePrincipal.getInstance();
+
+        assertEquals(EveryonePrincipal.NAME, everyone.getName());
+        assertEquals(everyone, EveryonePrincipal.getInstance());
+    }
+    
+    public void testEveryonePrincipal2() {
+        Principal everyone = EveryonePrincipal.getInstance();
+
+        Principal someotherEveryone = new Principal() {
+            public String getName() {
+                return EveryonePrincipal.NAME;
+            }
+        };
+
+        assertFalse(everyone.equals(someotherEveryone));
+    }
+
+    public void testEveryonePrincipal3() {
+        Principal everyone = EveryonePrincipal.getInstance();
+
+        Principal someotherEveryone = new JackrabbitPrincipal() {
+            public String getName() {
+                return EveryonePrincipal.NAME;
+            }
+            @Override
+            public boolean equals(Object o) {
+                if (o instanceof JackrabbitPrincipal) {
+                    return getName().equals(((JackrabbitPrincipal) o).getName());
+                }
+                return false;
+            }
+            @Override
+            public int hashCode() {
+                return getName().hashCode();
+            }
+        };
+
+        assertEquals(someotherEveryone, everyone);
+        assertEquals(everyone, someotherEveryone);
+    }
+
+    public void testEveryonePrincipal4() throws NotExecutableException, RepositoryException
{
+        Principal everyone = EveryonePrincipal.getInstance();
+
+        Group everyoneGroup = null;
+        try {
+            everyoneGroup = getUserManager(superuser).createGroup(EveryonePrincipal.NAME);
+            superuser.save();
+
+            assertEquals(everyoneGroup.getPrincipal(), everyone);
+            assertEquals(everyone, everyoneGroup.getPrincipal());
+
+        } finally {
+            if (everyoneGroup != null) {
+                everyoneGroup.remove();
+                superuser.save();
+            }
+        }
+    }
+
+    private static UserManager getUserManager(Session session) throws RepositoryException,
NotExecutableException {
+        if (!(session instanceof JackrabbitSession)) {
+            throw new NotExecutableException();
+        }
+        try {
+            return ((JackrabbitSession) session).getUserManager();
+        } catch (UnsupportedRepositoryOperationException e) {
+            throw new NotExecutableException(e.getMessage());
+        } catch (UnsupportedOperationException e) {
+            throw new NotExecutableException(e.getMessage());
+        }
+    }
+}
\ No newline at end of file

Propchange: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/principal/EveryonePrincipalTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/principal/EveryonePrincipalTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/principal/TestAll.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/principal/TestAll.java?rev=1044312&r1=1044311&r2=1044312&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/principal/TestAll.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/principal/TestAll.java
Fri Dec 10 11:49:39 2010
@@ -36,6 +36,7 @@ public class TestAll extends TestCase {
         TestSuite suite = new TestSuite("core.security.principal tests");
 
         suite.addTestSuite(AbstractPrincipalProviderTest.class);
+        suite.addTestSuite(EveryonePrincipalTest.class);
         
         return suite;
     }

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/DefaultPrincipalProviderTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/DefaultPrincipalProviderTest.java?rev=1044312&r1=1044311&r2=1044312&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/DefaultPrincipalProviderTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/DefaultPrincipalProviderTest.java
Fri Dec 10 11:49:39 2010
@@ -181,4 +181,50 @@ public class DefaultPrincipalProviderTes
             save(superuser);
         }
     }
+
+    public void testEveryonePrincipal() throws Exception {
+        Principal p = principalProvider.getPrincipal(EveryonePrincipal.NAME);
+        assertNotNull(p);
+        assertEquals(EveryonePrincipal.getInstance(), p);
+
+        PrincipalIterator pit = principalProvider.findPrincipals(EveryonePrincipal.NAME);
+        assertNotNull(pit);
+        if (pit.getSize() == -1) {
+            assertTrue(pit.hasNext());
+            assertEquals(EveryonePrincipal.getInstance(), pit.nextPrincipal());
+            assertFalse(pit.hasNext());
+        } else {
+            assertEquals(1, pit.getSize());
+            assertEquals(EveryonePrincipal.getInstance(), pit.nextPrincipal());
+        }
+    }
+
+    public void testEveryonePrincipal2() throws Exception {
+        Group g = null;
+        try {
+            g = userMgr.createGroup(EveryonePrincipal.NAME);
+            save(superuser);
+
+            Principal p = principalProvider.getPrincipal(EveryonePrincipal.NAME);
+            assertNotNull(p);
+            assertEquals(EveryonePrincipal.getInstance(), p);
+
+            PrincipalIterator pit = principalProvider.findPrincipals(EveryonePrincipal.NAME);
+            assertNotNull(pit);
+            if (pit.getSize() == -1) {
+                assertTrue(pit.hasNext());
+                assertEquals(EveryonePrincipal.getInstance(), pit.nextPrincipal());
+                assertFalse(pit.hasNext());
+            } else {
+                assertEquals(1, pit.getSize());
+                assertEquals(EveryonePrincipal.getInstance(), pit.nextPrincipal());
+            }
+
+        } finally {
+            if (g != null) {
+                g.remove();
+                save(superuser);
+            }
+        }
+    }
 }
\ No newline at end of file

Added: 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=1044312&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/GroupImplTest.java
(added)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/GroupImplTest.java
Fri Dec 10 11:49:39 2010
@@ -0,0 +1,105 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.core.security.user;
+
+import org.apache.jackrabbit.api.JackrabbitSession;
+import org.apache.jackrabbit.api.security.principal.ItemBasedPrincipal;
+import org.apache.jackrabbit.api.security.principal.PrincipalManager;
+import org.apache.jackrabbit.api.security.user.AbstractUserTest;
+import org.apache.jackrabbit.api.security.user.Authorizable;
+import org.apache.jackrabbit.api.security.user.Group;
+import org.apache.jackrabbit.core.security.principal.EveryonePrincipal;
+import org.apache.jackrabbit.test.NotExecutableException;
+
+import javax.jcr.RepositoryException;
+import java.security.Principal;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+/**
+ * <code>GroupImplTest</code>...
+ */
+public class GroupImplTest extends AbstractUserTest {
+
+    public void testEveryoneGroup() throws RepositoryException, NotExecutableException {
+        Group g = null;
+        try {
+            g = userMgr.createGroup(EveryonePrincipal.NAME);
+            save(superuser);
+
+            assertEquals(EveryonePrincipal.NAME, g.getPrincipal().getName());
+            assertEquals(EveryonePrincipal.getInstance(), g.getPrincipal());
+
+            assertTrue(g.isDeclaredMember(getTestUser(superuser)));
+            assertTrue(g.isMember(getTestUser(superuser)));
+
+            Iterator<Authorizable> it = g.getDeclaredMembers();
+            assertTrue(it.hasNext());
+            Set<Authorizable> members = new HashSet<Authorizable>();
+            while (it.hasNext()) {
+                members.add(it.next());
+            }
+
+            it = g.getMembers();
+            assertTrue(it.hasNext());
+            while (it.hasNext()) {
+                assertTrue(members.contains(it.next()));
+            }
+
+            assertFalse(g.addMember(getTestUser(superuser)));
+            assertFalse(g.removeMember(getTestUser(superuser)));
+
+            PrincipalManager pMgr = ((JackrabbitSession) superuser).getPrincipalManager();
+            Principal everyone = pMgr.getEveryone();
+
+            assertTrue(everyone instanceof ItemBasedPrincipal);
+            assertEquals(everyone, EveryonePrincipal.getInstance());
+
+        } finally {
+            if (g != null) {
+                g.remove();
+                save(superuser);
+            }
+        }
+    }
+
+    public void testEveryoneGroup2() throws RepositoryException, NotExecutableException {
+        Group g = null;
+        Group g2 = null;
+        try {
+            g = userMgr.createGroup(EveryonePrincipal.NAME);
+            g2 = userMgr.createGroup("testGroup");
+            save(superuser);
+
+            assertFalse(g.addMember(g2));
+            assertFalse(g.removeMember(g2));
+
+            assertFalse(g2.addMember(g));
+            assertFalse(g2.removeMember(g));
+            
+        } finally {
+            if (g != null) {
+                g.remove();
+            }
+            if (g2 != null) {
+                g2.remove();
+            }
+            save(superuser);            
+        }
+    }
+}
\ No newline at end of file

Propchange: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/GroupImplTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/GroupImplTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/TestAll.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/TestAll.java?rev=1044312&r1=1044311&r2=1044312&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/TestAll.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/TestAll.java
Fri Dec 10 11:49:39 2010
@@ -35,6 +35,7 @@ public class TestAll extends TestCase {
         suite.addTestSuite(UserManagerImplTest.class);
         suite.addTestSuite(AuthorizableImplTest.class);
         suite.addTestSuite(UserImplTest.class);
+        suite.addTestSuite(GroupImplTest.class);
         suite.addTestSuite(ImpersonationImplTest.class);
 
         suite.addTestSuite(UserAdministratorTest.class);

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/UserManagerImplTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/UserManagerImplTest.java?rev=1044312&r1=1044311&r2=1044312&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/UserManagerImplTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/security/user/UserManagerImplTest.java
Fri Dec 10 11:49:39 2010
@@ -24,6 +24,7 @@ import org.apache.jackrabbit.api.securit
 import org.apache.jackrabbit.api.security.user.UserManager;
 import org.apache.jackrabbit.core.SessionImpl;
 import org.apache.jackrabbit.core.security.TestPrincipal;
+import org.apache.jackrabbit.core.security.principal.EveryonePrincipal;
 import org.apache.jackrabbit.test.NotExecutableException;
 import org.apache.jackrabbit.spi.commons.conversion.NameResolver;
 
@@ -166,6 +167,21 @@ public class UserManagerImplTest extends
         }
     }
 
+    public void testCreateEveryoneUser() throws Exception {
+        User u = null;
+        try {
+            u = userMgr.createUser(EveryonePrincipal.NAME, "pw");
+            fail("everyone is a reserved group name");
+        } catch (IllegalArgumentException e) {
+            // success
+        } finally {
+            if (u != null) {
+                u.remove();
+            }
+        }
+
+    }
+
     public void testCreateGroupWithId() throws RepositoryException, NotExecutableException
{
         Principal p = getTestPrincipal();
         String uid = p.getName();



Mime
View raw message