jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r1404050 - in /jackrabbit/oak/trunk: oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/UserManagerImplTest.java oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/UserManagerTest.java
Date Wed, 31 Oct 2012 09:27:08 GMT
Author: angela
Date: Wed Oct 31 09:27:08 2012
New Revision: 1404050

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

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=1404050&r1=1404049&r2=1404050&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 31 09:27:08 2012
@@ -16,11 +16,16 @@
  */
 package org.apache.jackrabbit.oak.security.user;
 
+import java.security.Principal;
 import java.util.ArrayList;
 import java.util.List;
+import javax.jcr.RepositoryException;
 import javax.jcr.UnsupportedRepositoryOperationException;
 
+import org.apache.jackrabbit.JcrConstants;
+import org.apache.jackrabbit.api.security.user.Authorizable;
 import org.apache.jackrabbit.api.security.user.User;
+import org.apache.jackrabbit.oak.api.CommitFailedException;
 import org.apache.jackrabbit.oak.api.Root;
 import org.apache.jackrabbit.oak.api.Tree;
 import org.apache.jackrabbit.oak.api.Type;
@@ -28,8 +33,10 @@ import org.apache.jackrabbit.oak.namepat
 import org.apache.jackrabbit.oak.security.AbstractSecurityTest;
 import org.apache.jackrabbit.oak.spi.security.user.UserConstants;
 import org.apache.jackrabbit.oak.spi.security.user.util.PasswordUtility;
+import org.apache.jackrabbit.oak.util.NodeUtil;
 import org.junit.Before;
 import org.junit.Test;
+import sun.security.acl.PrincipalImpl;
 
 import static junit.framework.Assert.assertEquals;
 import static junit.framework.Assert.assertFalse;
@@ -129,4 +136,87 @@ public class UserManagerImplTest extends
             // success
         }
     }
+
+    @Test
+    public void testEnforceAuthorizableFolderHierarchy() throws RepositoryException, CommitFailedException
{
+        User user = userMgr.createUser("testUser", null);
+        root.commit();
+
+        NodeUtil userNode = new NodeUtil(root.getTree(user.getPath()));
+
+        NodeUtil folder = userNode.addChild("folder", UserConstants.NT_REP_AUTHORIZABLE_FOLDER);
+        String path = folder.getTree().getPath();
+        try {
+            // authNode - authFolder -> create User
+            try {
+                Principal p = new PrincipalImpl("test2");
+                Authorizable a = userMgr.createUser(p.getName(), p.getName(), p, path);
+                root.commit();
+
+                fail("Users may not be nested.");
+            } catch (CommitFailedException e) {
+                // success
+            } finally {
+                root.refresh();
+                Authorizable a = userMgr.getAuthorizable("test2");
+                if (a != null) {
+                    a.remove();
+                    root.commit();
+                }
+            }
+        } finally {
+            root.refresh();
+            folder.getTree().remove();
+            root.commit();
+        }
+
+        NodeUtil someContent = userNode.addChild("mystuff", JcrConstants.NT_UNSTRUCTURED);
+        path = someContent.getTree().getPath();
+        try {
+            // authNode - anyNode -> create User
+            try {
+                Principal p = new PrincipalImpl("test3");
+                userMgr.createUser(p.getName(), p.getName(), p, path);
+                root.commit();
+
+                fail("Users may not be nested.");
+            } catch (CommitFailedException e) {
+                // success
+            } finally {
+                root.refresh();
+                Authorizable a = userMgr.getAuthorizable("test3");
+                if (a != null) {
+                    a.remove();
+                    root.commit();
+                }
+            }
+
+            // authNode - anyNode - authFolder -> create User
+            folder = someContent.addChild("folder", UserConstants.NT_REP_AUTHORIZABLE_FOLDER);
+            root.commit(); // this time save node structure
+            try {
+                Principal p = new PrincipalImpl("test4");
+                userMgr.createUser(p.getName(), p.getName(), p, folder.getTree().getPath());
+                root.commit();
+
+                fail("Users may not be nested.");
+            } catch (CommitFailedException e) {
+                // success
+            } finally {
+                root.refresh();
+                Authorizable a = userMgr.getAuthorizable("test4");
+                if (a != null) {
+                    a.remove();
+                    root.commit();
+                }
+            }
+        } finally {
+            root.refresh();
+            Tree t = root.getTree(path);
+            if (t != null) {
+                t.remove();
+                root.commit();
+            }
+        }
+    }
 }
\ 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=1404050&r1=1404049&r2=1404050&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 31 09:27:08 2012
@@ -766,84 +766,6 @@ public class UserManagerTest extends Abs
     }
 
     @Test
-    public void testEnforceAuthorizableFolderHierarchy() throws RepositoryException, NotExecutableException
{
-        Authorizable auth = userMgr.getAuthorizable(user.getID());
-        Node userNode = getNode(auth, superuser);
-
-        Node folder = userNode.addNode("folder", UserConstants.NT_REP_AUTHORIZABLE_FOLDER);
-        String path = folder.getPath();
-        try {
-            // authNode - authFolder -> create User
-            Authorizable a = null;
-            try {
-                Principal p = getTestPrincipal();
-                a = userMgr.createUser(p.getName(), p.getName(), p, path);
-                superuser.save();
-
-                fail("Users may not be nested.");
-            } catch (RepositoryException e) {
-                // success
-            } finally {
-                if (a != null) {
-                    a.remove();
-                }
-            }
-        } finally {
-            superuser.refresh(false);
-            if (superuser.nodeExists(path)) {
-                folder.remove();
-                superuser.save();
-            }
-        }
-
-        Node someContent = userNode.addNode("mystuff", "nt:unstructured");
-        path = someContent.getPath();
-        try {
-            // authNode - anyNode -> create User
-            Authorizable a = null;
-            try {
-                Principal p = getTestPrincipal();
-                a = userMgr.createUser(p.getName(), p.getName(), p, someContent.getPath());
-                superuser.save();
-
-                fail("Users may not be nested.");
-            } catch (RepositoryException e) {
-                // success
-            } finally {
-                if (a != null) {
-                    a.remove();
-                    a = null;
-                }
-            }
-
-            // authNode - anyNode - authFolder -> create User
-            if (!superuser.nodeExists(path)) {
-                someContent = userNode.addNode("mystuff", "nt:unstructured");
-            }
-            folder = someContent.addNode("folder", UserConstants.NT_REP_AUTHORIZABLE_FOLDER);
-            superuser.save(); // this time save node structure
-            try {
-                Principal p = getTestPrincipal();
-                a = userMgr.createUser(p.getName(), p.getName(), p, folder.getPath());
-                superuser.save();
-
-                fail("Users may not be nested.");
-            } catch (RepositoryException e) {
-                // success
-            } finally {
-                if (a != null) {
-                    a.remove();
-                }
-            }
-        } finally {
-            if (superuser.nodeExists(path)) {
-                someContent.remove();
-                superuser.save();
-            }
-        }
-    }
-
-    @Test
     public void testCreateWithRelativePath() throws Exception {
         Principal p = getTestPrincipal();
         String uid = p.getName();



Mime
View raw message