jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r1401793 - in /jackrabbit/oak/trunk: oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/ oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/
Date Wed, 24 Oct 2012 17:36:53 GMT
Author: angela
Date: Wed Oct 24 17:36:52 2012
New Revision: 1401793

URL: http://svn.apache.org/viewvc?rev=1401793&view=rev
Log:
OAK-50 : Implement User Management (WIP)

Added:
    jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/CreateGroupTest.java
    jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/CreateUserTest.java
    jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/NestedGroupTest.java
Modified:
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/UserManagerImplTest.java
    jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/UserManagerTest.java

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/UserManagerImplTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/UserManagerImplTest.java?rev=1401793&r1=1401792&r2=1401793&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/UserManagerImplTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/UserManagerImplTest.java
Wed Oct 24 17:36:52 2012
@@ -18,15 +18,14 @@ package org.apache.jackrabbit.oak.securi
 
 import java.util.ArrayList;
 import java.util.List;
+import javax.jcr.UnsupportedRepositoryOperationException;
 
 import org.apache.jackrabbit.api.security.user.User;
-import org.apache.jackrabbit.api.security.user.UserManager;
 import org.apache.jackrabbit.oak.api.Root;
 import org.apache.jackrabbit.oak.api.Tree;
 import org.apache.jackrabbit.oak.api.Type;
 import org.apache.jackrabbit.oak.namepath.NamePathMapper;
 import org.apache.jackrabbit.oak.security.AbstractSecurityTest;
-import org.apache.jackrabbit.oak.spi.security.user.UserConfiguration;
 import org.apache.jackrabbit.oak.spi.security.user.UserConstants;
 import org.apache.jackrabbit.oak.spi.security.user.util.PasswordUtility;
 import org.junit.Before;
@@ -44,20 +43,19 @@ import static org.junit.Assert.fail;
  */
 public class UserManagerImplTest extends AbstractSecurityTest {
 
-    private UserConfiguration uc;
+    private Root root;
+    private UserManagerImpl userMgr;
 
     @Before
     public void before() throws Exception {
         super.before();
 
-        uc = getSecurityProvider().getUserConfiguration();
+        root = admin.getLatestRoot();
+        userMgr = new UserManagerImpl(null, root, NamePathMapper.DEFAULT, getSecurityProvider());
     }
 
     @Test
     public void testSetPassword() throws Exception {
-        Root root = admin.getLatestRoot();
-        UserManagerImpl userMgr = (UserManagerImpl) uc.getUserManager(root, NamePathMapper.DEFAULT);
-
         User user = userMgr.createUser("a", "pw");
         root.commit();
 
@@ -89,9 +87,6 @@ public class UserManagerImplTest extends
 
     @Test
     public void setPasswordNull() throws Exception {
-        Root root = admin.getLatestRoot();
-        UserManagerImpl userMgr = (UserManagerImpl) uc.getUserManager(root, NamePathMapper.DEFAULT);
-
         User user = userMgr.createUser("a", null);
         root.commit();
 
@@ -113,13 +108,25 @@ public class UserManagerImplTest extends
 
     @Test
     public void testGetPasswordHash() throws Exception {
-        Root root = admin.getLatestRoot();
-        UserManager userMgr = uc.getUserManager(root, NamePathMapper.DEFAULT);
-
         User user = userMgr.createUser("a", null);
         root.commit();
 
         Tree userTree = root.getTree(user.getPath());
         assertNull(userTree.getProperty(UserConstants.REP_PASSWORD));
     }
+
+    @Test
+    public void testIsAutoSave() throws Exception {
+        assertFalse(userMgr.isAutoSave());
+    }
+
+    @Test
+    public void testAutoSave() throws Exception {
+        try {
+            userMgr.autoSave(true);
+            fail("should fail");
+        } catch (UnsupportedRepositoryOperationException e) {
+            // success
+        }
+    }
 }
\ No newline at end of file

Added: jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/CreateGroupTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/CreateGroupTest.java?rev=1401793&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/CreateGroupTest.java
(added)
+++ jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/CreateGroupTest.java
Wed Oct 24 17:36:52 2012
@@ -0,0 +1,126 @@
+/*
+ * 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.oak.jcr.security.user;
+
+import java.security.Principal;
+import java.util.ArrayList;
+import java.util.List;
+import javax.jcr.RepositoryException;
+
+import org.apache.jackrabbit.api.security.user.Authorizable;
+import org.apache.jackrabbit.api.security.user.AuthorizableExistsException;
+import org.apache.jackrabbit.api.security.user.Group;
+import org.apache.jackrabbit.test.NotExecutableException;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * CreateGroupTest...
+ */
+public class CreateGroupTest extends AbstractUserTest {
+
+    private static Logger log = LoggerFactory.getLogger(CreateGroupTest.class);
+
+    private List<Authorizable> createdGroups = new ArrayList();
+
+    @Override
+    protected void tearDown() throws Exception {
+        // remove all created groups again
+        for (Authorizable createdGroup : createdGroups) {
+            try {
+                createdGroup.remove();
+                superuser.save();
+            } catch (RepositoryException e) {
+                log.error("Failed to remove Group " + createdGroup.getID() + " during tearDown.");
+            }
+        }
+
+        super.tearDown();
+    }
+
+    private Group createGroup(Principal p) throws RepositoryException {
+        Group gr = userMgr.createGroup(p);
+        superuser.save();
+        return gr;
+    }
+
+    private Group createGroup(Principal p, String iPath) throws RepositoryException {
+        Group gr = userMgr.createGroup(p, iPath);
+        superuser.save();
+        return gr;
+    }
+
+    @Test
+    public void testCreateGroup() throws RepositoryException, NotExecutableException {
+        Principal p = getTestPrincipal();
+        Group gr = createGroup(p);
+        createdGroups.add(gr);
+
+        assertNotNull(gr.getID());
+        assertEquals(p.getName(), gr.getPrincipal().getName());
+        assertFalse("A new group must not have members.",gr.getMembers().hasNext());
+    }
+
+    // TODO: check again.
+//    @Test
+//    public void testCreateGroupWithPath() throws RepositoryException, NotExecutableException
{
+//        Principal p = getTestPrincipal();
+//        Group gr = createGroup(p, "/any/path/to/the/new/group");
+//        createdGroups.add(gr);
+//
+//        assertNotNull(gr.getID());
+//        assertEquals(p.getName(), gr.getPrincipal().getName());
+//        assertFalse("A new group must not have members.",gr.getMembers().hasNext());
+//    }
+
+    @Test
+    public void testCreateGroupWithNullPrincipal() throws RepositoryException {
+        try {
+            Group gr = createGroup(null);
+            createdGroups.add(gr);
+
+            fail("A Group cannot be built from 'null' Principal");
+        } catch (Exception e) {
+            // ok
+        }
+
+        try {
+            Group gr = createGroup(null, "/any/path/to/the/new/group");
+            createdGroups.add(gr);
+
+            fail("A Group cannot be built from 'null' Principal");
+        } catch (Exception e) {
+            // ok
+        }
+    }
+
+    @Test
+    public void testCreateDuplicateGroup() throws RepositoryException, NotExecutableException
{
+        Principal p = getTestPrincipal();
+        Group gr = createGroup(p);
+        createdGroups.add(gr);
+
+        try {
+            Group gr2 = createGroup(p);
+            createdGroups.add(gr2);
+            fail("Creating 2 groups with the same Principal should throw AuthorizableExistsException.");
+        } catch (AuthorizableExistsException e) {
+            // success.
+        }
+    }
+}
\ No newline at end of file

Added: jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/CreateUserTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/CreateUserTest.java?rev=1401793&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/CreateUserTest.java
(added)
+++ jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/CreateUserTest.java
Wed Oct 24 17:36:52 2012
@@ -0,0 +1,256 @@
+/*
+ * 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.oak.jcr.security.user;
+
+import java.security.Principal;
+import java.util.ArrayList;
+import java.util.List;
+import javax.jcr.RepositoryException;
+
+import org.apache.jackrabbit.api.security.user.Authorizable;
+import org.apache.jackrabbit.api.security.user.AuthorizableExistsException;
+import org.apache.jackrabbit.api.security.user.User;
+import org.apache.jackrabbit.test.NotExecutableException;
+import org.junit.After;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * CreateUserTest...
+ */
+public class CreateUserTest extends AbstractUserTest {
+
+    private static Logger log = LoggerFactory.getLogger(CreateUserTest.class);
+
+    private List<Authorizable> createdUsers = new ArrayList<Authorizable>();
+
+    @After
+    @Override
+    protected void tearDown() throws Exception {
+        superuser.refresh(false);
+        // remove all created groups again
+        for (Object createdUser : createdUsers) {
+            Authorizable auth = (Authorizable) createdUser;
+            try {
+                auth.remove();
+                superuser.save();
+            } catch (RepositoryException e) {
+                log.warn("Failed to remove User " + auth.getID() + " during tearDown.");
+            }
+        }
+        super.tearDown();
+    }
+
+    private User createUser(String uid, String pw) throws RepositoryException, NotExecutableException
{
+        User u = userMgr.createUser(uid, pw);
+        superuser.save();
+        return u;
+    }
+
+    private User createUser(String uid, String pw, Principal p, String iPath) throws RepositoryException,
NotExecutableException {
+        User u = userMgr.createUser(uid, pw, p, iPath);
+        superuser.save();
+        return u;
+    }
+
+    @Test
+    public void testCreateUser() throws RepositoryException, NotExecutableException {
+        Principal p = getTestPrincipal();
+        String uid = p.getName();
+        User user = createUser(uid, "pw");
+        createdUsers.add(user);
+
+        assertNotNull(user.getID());
+        assertEquals(p.getName(), user.getPrincipal().getName());
+    }
+
+    // TODO: check again.
+//    @Test
+//    public void testCreateUserWithPath() throws RepositoryException, NotExecutableException
{
+//        Principal p = getTestPrincipal();
+//        String uid = p.getName();
+//        User user = createUser(uid, "pw", p, "/any/path/to/the/new/user");
+//        createdUsers.add(user);
+//
+//        assertNotNull(user.getID());
+//        assertEquals(p.getName(), user.getPrincipal().getName());
+//    }
+
+    @Test
+    public void testCreateUserWithPath2() throws RepositoryException, NotExecutableException
{
+        Principal p = getTestPrincipal();
+        String uid = p.getName();
+        User user = createUser(uid, "pw", p, "any/path");
+        createdUsers.add(user);
+
+        assertNotNull(user.getID());
+        assertEquals(p.getName(), user.getPrincipal().getName());
+    }
+
+    @Test
+    public void testCreateUserWithDifferentPrincipalName() throws RepositoryException, NotExecutableException
{
+        Principal p = getTestPrincipal();
+        String uid = getTestPrincipal().getName();
+        User user = createUser(uid, "pw", p, "any/path");
+        createdUsers.add(user);
+
+        assertNotNull(user.getID());
+        assertEquals(p.getName(), user.getPrincipal().getName());
+    }
+
+    @Test
+    public void testCreateUserWithNullParamerters() throws RepositoryException {
+        try {
+            User user = createUser(null, null);
+            createdUsers.add(user);
+
+            fail("A User cannot be built from 'null' parameters");
+        } catch (Exception e) {
+            // ok
+        }
+
+        try {
+            User user = createUser(null, null, null, null);
+            createdUsers.add(user);
+
+            fail("A User cannot be built from 'null' parameters");
+        } catch (Exception e) {
+            // ok
+        }
+    }
+
+    @Test
+    public void testCreateUserWithNullUserID() throws RepositoryException {
+        try {
+            User user = createUser(null, "anyPW");
+            createdUsers.add(user);
+
+            fail("A User cannot be built with 'null' userID");
+        } catch (Exception e) {
+            // ok
+        }
+    }
+
+    @Test
+    public void testCreateUserWithEmptyUserID() throws RepositoryException {
+        try {
+            User user = createUser("", "anyPW");
+            createdUsers.add(user);
+
+            fail("A User cannot be built with \"\" userID");
+        } catch (Exception e) {
+            // ok
+        }
+        try {
+            User user = createUser("", "anyPW", getTestPrincipal(), null);
+            createdUsers.add(user);
+
+            fail("A User cannot be built with \"\" userID");
+        } catch (Exception e) {
+            // ok
+        }
+    }
+
+    @Test
+    public void testCreateUserWithEmptyPassword() throws RepositoryException, NotExecutableException
{
+        Principal p = getTestPrincipal();
+        User user = createUser(p.getName(), "");
+        createdUsers.add(user);
+    }
+
+    @Test
+    public void testCreateUserWithNullPrincipal() throws RepositoryException {
+        try {
+            Principal p = getTestPrincipal();
+            String uid = p.getName();
+            User user = createUser(uid, "pw", null, "/a/b/c");
+            createdUsers.add(user);
+
+            fail("A User cannot be built with 'null' Principal");
+        } catch (Exception e) {
+            // ok
+        }
+    }
+
+    public void testCreateUserWithEmptyPrincipal() throws RepositoryException {
+        try {
+            Principal p = getTestPrincipal("");
+            String uid = p.getName();
+            User user = createUser(uid, "pw", p, "/a/b/c");
+            createdUsers.add(user);
+
+            fail("A User cannot be built with ''-named Principal");
+        } catch (Exception e) {
+            // ok
+        }
+        try {
+            Principal p = getTestPrincipal(null);
+            String uid = p.getName();
+            User user = createUser(uid, "pw", p, "/a/b/c");
+            createdUsers.add(user);
+
+            fail("A User cannot be built with ''-named Principal");
+        } catch (Exception e) {
+            // ok
+        }
+    }
+
+    public void testCreateTwiceWithSameUserID() throws RepositoryException, NotExecutableException
{
+        String uid = getTestPrincipal().getName();
+        User user = createUser(uid, "pw");
+        createdUsers.add(user);
+
+        try {
+            User user2 = createUser(uid, "anyPW");
+            createdUsers.add(user2);
+
+            fail("Creating 2 users with the same UserID should throw AuthorizableExistsException.");
+        } catch (AuthorizableExistsException e) {
+            // success.
+        }
+    }
+
+    // TODO: RepositoryException is thrown instead of AuthorizableExistsException
+    public void testCreateTwiceWithSamePrincipal() throws RepositoryException, NotExecutableException
{
+        Principal p = getTestPrincipal();
+        String uid = p.getName();
+        User user = createUser(uid, "pw", p, "a/b/c");
+        createdUsers.add(user);
+
+        try {
+            uid = getTestPrincipal().getName();
+            User user2 = createUser(uid, "pw", p, null);
+            createdUsers.add(user2);
+
+            fail("Creating 2 users with the same Principal should throw AuthorizableExistsException.");
+        } catch (RepositoryException e) {
+            // success.
+        }
+    }
+
+    public void testGetUserAfterCreation() throws RepositoryException, NotExecutableException
{
+        Principal p = getTestPrincipal();
+        String uid = p.getName();
+
+        User user = createUser(uid, "pw");
+        createdUsers.add(user);
+
+        assertNotNull(userMgr.getAuthorizable(user.getID()));
+        assertNotNull(userMgr.getAuthorizable(p));
+    }
+}
\ No newline at end of file

Added: jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/NestedGroupTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/NestedGroupTest.java?rev=1401793&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/NestedGroupTest.java
(added)
+++ jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/NestedGroupTest.java
Wed Oct 24 17:36:52 2012
@@ -0,0 +1,188 @@
+/*
+ * 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.oak.jcr.security.user;
+
+import java.security.Principal;
+import javax.jcr.RepositoryException;
+
+import org.apache.jackrabbit.api.JackrabbitSession;
+import org.apache.jackrabbit.api.security.principal.PrincipalIterator;
+import org.apache.jackrabbit.api.security.principal.PrincipalManager;
+import org.apache.jackrabbit.api.security.user.Authorizable;
+import org.apache.jackrabbit.api.security.user.Group;
+import org.apache.jackrabbit.test.NotExecutableException;
+import org.junit.Test;
+
+/**
+ * NestedGroupTest...
+ */
+public class NestedGroupTest extends AbstractUserTest {
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+        super.tearDown();
+    }
+
+    private Group createGroup(Principal p) throws RepositoryException {
+        Group gr = userMgr.createGroup(p);
+        superuser.save();
+        return gr;
+    }
+
+    private void removeGroup(Group gr) throws RepositoryException {
+        gr.remove();
+        superuser.save();
+    }
+
+    private boolean addMember(Group gr, Authorizable member) throws RepositoryException {
+        boolean added = gr.addMember(member);
+        superuser.save();
+        return added;
+    }
+
+    private boolean removeMember(Group gr, Authorizable member) throws RepositoryException
{
+        boolean removed = gr.removeMember(member);
+        superuser.save();
+        return removed;
+    }
+
+    @Test
+    public void testAddGroupAsMember() throws NotExecutableException, RepositoryException
{
+        Group gr1 = null;
+        Group gr2 = null;
+
+        try {
+            gr1 = createGroup(getTestPrincipal());
+            gr2 = createGroup(getTestPrincipal());
+
+            assertFalse(gr1.isMember(gr2));
+
+            assertTrue(addMember(gr1, gr2));
+            assertTrue(gr1.isMember(gr2));
+
+        } finally {
+            if (gr1 != null) {
+                removeMember(gr1, gr2);
+                removeGroup(gr1);
+            }
+            if (gr2 != null) {
+                removeGroup(gr2);
+            }
+        }
+    }
+
+    @Test
+    public void testAddCircularMembers() throws NotExecutableException, RepositoryException
{
+        Group gr1 = null;
+        Group gr2 = null;
+
+        try {
+            gr1 = createGroup(getTestPrincipal());
+            gr2 = createGroup(getTestPrincipal());
+
+            assertTrue(addMember(gr1, gr2));
+            assertFalse(addMember(gr2, gr1));
+
+        } finally {
+            if (gr1 != null && gr1.isMember(gr2)) {
+                removeMember(gr1, gr2);
+            }
+            if (gr2 != null && gr2.isMember(gr1)) {
+                removeMember(gr2, gr1);
+            }
+            if (gr1 != null) removeGroup(gr1);
+            if (gr2 != null) removeGroup(gr2);
+        }
+    }
+
+    @Test
+    public void testCyclicMembers2() throws RepositoryException, NotExecutableException {
+        Group gr1 = null;
+        Group gr2 = null;
+        Group gr3 = null;
+        try {
+            gr1 = createGroup(getTestPrincipal());
+            gr2 = createGroup(getTestPrincipal());
+            gr3 = createGroup(getTestPrincipal());
+
+            assertTrue(addMember(gr1, gr2));
+            assertTrue(addMember(gr2, gr3));
+            assertFalse(addMember(gr3, gr1));
+
+        } finally {
+            if (gr1 != null) {
+                removeMember(gr1, gr2);
+            }
+            if (gr2 != null) {
+                removeMember(gr2, gr3);
+                removeGroup(gr2);
+            }
+            if (gr3 != null) {
+                removeMember(gr3, gr1);
+                removeGroup(gr3);
+            }
+            if (gr1 != null) removeGroup(gr1);
+
+        }
+    }
+
+    @Test
+    public void testInheritedMembership() throws NotExecutableException, RepositoryException
{
+        Group gr1 = null;
+        Group gr2 = null;
+        Group gr3 = null;
+
+        if (!(superuser instanceof JackrabbitSession)) {
+            throw new NotExecutableException();
+        }
+
+        try {
+            gr1 = createGroup(getTestPrincipal());
+            gr2 = createGroup(getTestPrincipal());
+            gr3 = createGroup(getTestPrincipal());
+
+            assertTrue(addMember(gr1, gr2));
+            assertTrue(addMember(gr2, gr3));
+
+            // NOTE: don't test with Group.isMember for not required to detect
+            // inherited membership -> rather with PrincipalManager.
+            boolean isMember = false;
+            PrincipalManager pmgr = ((JackrabbitSession) superuser).getPrincipalManager();
+            for (PrincipalIterator it = pmgr.getGroupMembership(gr3.getPrincipal());
+                 it.hasNext() && !isMember;) {
+                isMember = it.nextPrincipal().equals(gr1.getPrincipal());
+            }
+            assertTrue(isMember);
+
+        } finally {
+            if (gr1 != null && gr1.isMember(gr2)) {
+                removeMember(gr1, gr2);
+            }
+            if (gr2 != null && gr2.isMember(gr3)) {
+                removeMember(gr2, gr3);
+            }
+            if (gr1 != null) removeGroup(gr1);
+            if (gr2 != null) removeGroup(gr2);
+            if (gr3 != null) removeGroup(gr3);
+        }
+    }
+}
\ No newline at end of file

Modified: jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/UserManagerTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/UserManagerTest.java?rev=1401793&r1=1401792&r2=1401793&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/UserManagerTest.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/UserManagerTest.java
Wed Oct 24 17:36:52 2012
@@ -100,16 +100,20 @@ public class UserManagerTest extends Abs
     }
 
     @Test
-    public void testPrincipalNameEqualsUserID() throws RepositoryException, NotExecutableException
{
+    public void testUserIDFromSession() throws RepositoryException, NotExecutableException
{
         User u = null;
+        Session uSession = null;
         try {
             String uid = createUserId();
             u = userMgr.createUser(uid, "pw");
             superuser.save();
 
-            String msg = "User.getID() must return the userID pass to createUser.";
-            assertEquals(msg, uid, u.getID());
+            uSession = superuser.getRepository().login(new SimpleCredentials(uid, "pw".toCharArray()));
+            assertEquals(u.getID(), uSession.getUserID());
         } finally {
+            if (uSession != null) {
+                uSession.logout();
+            }
             if (u != null) {
                 u.remove();
                 superuser.save();
@@ -118,20 +122,19 @@ public class UserManagerTest extends Abs
     }
 
     @Test
-    public void testUserIDFromSession() throws RepositoryException, NotExecutableException
{
+    public void testCreateUserPrincipalNameEqualsUserID() throws RepositoryException, NotExecutableException
{
         User u = null;
-        Session uSession = null;
         try {
             String uid = createUserId();
             u = userMgr.createUser(uid, "pw");
             superuser.save();
 
-            uSession = superuser.getRepository().login(new SimpleCredentials(uid, "pw".toCharArray()));
-            assertEquals(u.getID(), uSession.getUserID());
+            String msg = "User.getID() must return the userID pass to createUser.";
+            assertEquals(msg, uid, u.getID());
+
+            msg = "Principal name must be the same as userID.";
+            assertEquals(msg, uid, u.getPrincipal().getName());
         } finally {
-            if (uSession != null) {
-                uSession.logout();
-            }
             if (u != null) {
                 u.remove();
                 superuser.save();
@@ -885,4 +888,27 @@ public class UserManagerTest extends Abs
             }
         }
     }
+
+    public void testAutoSave() throws RepositoryException, NotExecutableException {
+        if (userMgr.isAutoSave()) {
+            try {
+                userMgr.autoSave(false);
+            } catch (RepositoryException e) {
+                throw new NotExecutableException();
+            }
+        }
+
+        Principal p = getTestPrincipal();
+        String uid = p.getName();
+        User user = userMgr.createUser(uid, "pw");
+
+        String gid = createGroupId();
+        Group group = userMgr.createGroup(gid);
+        superuser.refresh(false);
+
+        // transient changes must be gone after the refresh-call.
+        assertNull(userMgr.getAuthorizable(uid));
+        assertNull(userMgr.getAuthorizable(p));
+        assertNull(userMgr.getAuthorizable(gid));
+    }
 }



Mime
View raw message