jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r1469813 - /jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/
Date Fri, 19 Apr 2013 13:05:18 GMT
Author: angela
Date: Fri Apr 19 13:05:16 2013
New Revision: 1469813

URL: http://svn.apache.org/r1469813
Log:
OAK-50 : Implement User Management  (revert changes made to UserTest in rev. 1454544, add
some javadoc to user mgt related tests)

Modified:
    jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/AdministratorTest.java
    jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/AuthorizablePropertyTest.java
    jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/AuthorizableTest.java
    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/FindAuthorizablesTest.java
    jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/GroupTest.java
    jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/ImpersonationTest.java
    jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/NestedGroupTest.java
    jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/UserManagerTest.java
    jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/UserQueryTest.java
    jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/UserTest.java

Modified: jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/AdministratorTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/AdministratorTest.java?rev=1469813&r1=1469812&r2=1469813&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/AdministratorTest.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/AdministratorTest.java
Fri Apr 19 13:05:16 2013
@@ -26,7 +26,7 @@ import org.junit.Before;
 import org.junit.Test;
 
 /**
- * AdministratorTest...
+ * Test for the administrator user.
  */
 public class AdministratorTest extends AbstractUserTest {
 

Modified: jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/AuthorizablePropertyTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/AuthorizablePropertyTest.java?rev=1469813&r1=1469812&r2=1469813&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/AuthorizablePropertyTest.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/AuthorizablePropertyTest.java
Fri Apr 19 13:05:16 2013
@@ -39,7 +39,7 @@ import org.apache.jackrabbit.value.Strin
 import org.junit.Test;
 
 /**
- * AuthorizablePropertyTest...
+ * Tests for user property specific API.
  */
 public class AuthorizablePropertyTest extends AbstractUserTest {
 

Modified: jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/AuthorizableTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/AuthorizableTest.java?rev=1469813&r1=1469812&r2=1469813&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/AuthorizableTest.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/AuthorizableTest.java
Fri Apr 19 13:05:16 2013
@@ -31,7 +31,7 @@ import org.apache.jackrabbit.test.NotExe
 import org.junit.Test;
 
 /**
- * AuthorizableTest...
+ * Tests for the {@link Authorizable} implementation.
  */
 public class AuthorizableTest extends AbstractUserTest {
 

Modified: 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=1469813&r1=1469812&r2=1469813&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/CreateGroupTest.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/CreateGroupTest.java
Fri Apr 19 13:05:16 2013
@@ -28,7 +28,7 @@ import org.apache.jackrabbit.test.NotExe
 import org.junit.Test;
 
 /**
- * CreateGroupTest...
+ * Tests for {@code Group} creation.
  */
 public class CreateGroupTest extends AbstractUserTest {
 

Modified: 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=1469813&r1=1469812&r2=1469813&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/CreateUserTest.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/CreateUserTest.java
Fri Apr 19 13:05:16 2013
@@ -31,7 +31,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
- * CreateUserTest...
+ * Tests for {@code User} creation.
  */
 public class CreateUserTest extends AbstractUserTest {
 

Modified: jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/FindAuthorizablesTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/FindAuthorizablesTest.java?rev=1469813&r1=1469812&r2=1469813&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/FindAuthorizablesTest.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/FindAuthorizablesTest.java
Fri Apr 19 13:05:16 2013
@@ -35,7 +35,7 @@ import org.apache.jackrabbit.test.NotExe
 import org.junit.Test;
 
 /**
- * FindAuthorizablesTest...
+ * Tests for the query API exposed by {@link UserManager}.
  */
 public class FindAuthorizablesTest extends AbstractUserTest {
 

Modified: jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/GroupTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/GroupTest.java?rev=1469813&r1=1469812&r2=1469813&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/GroupTest.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/GroupTest.java
Fri Apr 19 13:05:16 2013
@@ -34,7 +34,7 @@ import org.junit.Ignore;
 import org.junit.Test;
 
 /**
- * GroupTest...
+ * Tests for the {@link Group} implementation.
  */
 public class GroupTest extends AbstractUserTest {
 

Modified: jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/ImpersonationTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/ImpersonationTest.java?rev=1469813&r1=1469812&r2=1469813&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/ImpersonationTest.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/ImpersonationTest.java
Fri Apr 19 13:05:16 2013
@@ -29,7 +29,7 @@ import org.apache.jackrabbit.test.NotExe
 import org.junit.Test;
 
 /**
- * ImpersonationTest...
+ * Tests for the {@link Impersonation} implementation.
  */
 public class ImpersonationTest extends AbstractUserTest {
 

Modified: 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=1469813&r1=1469812&r2=1469813&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/NestedGroupTest.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/NestedGroupTest.java
Fri Apr 19 13:05:16 2013
@@ -28,7 +28,7 @@ import org.apache.jackrabbit.test.NotExe
 import org.junit.Test;
 
 /**
- * NestedGroupTest...
+ * Tests for the {@link Group} implementation specific for nested group membership.
  */
 public class NestedGroupTest extends AbstractUserTest {
 

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=1469813&r1=1469812&r2=1469813&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
Fri Apr 19 13:05:16 2013
@@ -38,6 +38,9 @@ import org.apache.jackrabbit.oak.spi.sec
 import org.apache.jackrabbit.test.NotExecutableException;
 import org.junit.Test;
 
+/**
+ * Tests for the {@link UserManager} implementation.
+ */
 public class UserManagerTest extends AbstractUserTest {
 
     @Test

Modified: jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/UserQueryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/UserQueryTest.java?rev=1469813&r1=1469812&r2=1469813&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/UserQueryTest.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/UserQueryTest.java
Fri Apr 19 13:05:16 2013
@@ -36,6 +36,10 @@ import org.apache.jackrabbit.api.securit
 import org.apache.jackrabbit.api.security.user.User;
 import org.junit.Test;
 
+/**
+ * Tests for the {@link Query} interface and
+ * {@link org.apache.jackrabbit.api.security.user.UserManager#findAuthorizables(Query)}.
+ */
 public class UserQueryTest extends AbstractUserTest {
 
     private User kangaroo;

Modified: jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/UserTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/UserTest.java?rev=1469813&r1=1469812&r2=1469813&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/UserTest.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/user/UserTest.java
Fri Apr 19 13:05:16 2013
@@ -16,256 +16,267 @@
  */
 package org.apache.jackrabbit.oak.jcr.security.user;
 
+import java.security.Principal;
+import javax.jcr.Credentials;
+import javax.jcr.LoginException;
 import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.SimpleCredentials;
+import javax.jcr.UnsupportedRepositoryOperationException;
 
+import org.apache.jackrabbit.api.JackrabbitSession;
+import org.apache.jackrabbit.api.security.user.Authorizable;
+import org.apache.jackrabbit.api.security.user.User;
+import org.apache.jackrabbit.oak.spi.security.user.UserConstants;
+import org.apache.jackrabbit.test.NotExecutableException;
 import org.junit.Test;
 
 /**
- * UserTest...
+ * Tests for the {@link User} implementation.
  */
 public class UserTest extends AbstractUserTest {
 
     @Test
     public void testIsUser() throws RepositoryException {
-//        Authorizable authorizable = userMgr.getAuthorizable(user.getID());
-//        assertTrue(authorizable instanceof User);
+        Authorizable authorizable = userMgr.getAuthorizable(user.getID());
+        assertTrue(authorizable instanceof User);
     }
 
-//    @Test
-//    public void testIsGroup() throws RepositoryException {
-//        assertFalse(user.isGroup());
-//    }
-//
-//    @Test
-//    public void testGetId() throws NotExecutableException, RepositoryException {
-//        assertNotNull(user.getID());
-//        assertNotNull(userMgr.getAuthorizable(user.getID()).getID());
-//    }
-//
-//    @Test
-//    public void testGetPrincipal() throws RepositoryException, NotExecutableException {
-//        assertNotNull(user.getPrincipal());
-//        assertNotNull(userMgr.getAuthorizable(user.getID()).getPrincipal());
-//    }
-//
-//    @Test
-//    public void testGetPath() throws RepositoryException, NotExecutableException {
-//        assertNotNull(user.getPath());
-//        assertNotNull(userMgr.getAuthorizable(user.getID()).getPath());
-//        try {
-//            assertEquals(getNode(user, superuser).getPath(), user.getPath());
-//        } catch (UnsupportedRepositoryOperationException e) {
-//            // ok.
-//        }
-//    }
-//
-//    @Test
-//    public void testIsAdmin() throws NotExecutableException, RepositoryException {
-//        assertFalse(user.isAdmin());
-//    }
-//
-//    @Test
-//    public void testChangePasswordNull() throws RepositoryException, NotExecutableException
{
-//        // invalid 'null' pw string
-//        try {
-//            user.changePassword(null);
-//            superuser.save();
-//            fail("invalid pw null");
-//        } catch (Exception e) {
-//            // success
-//        }
-//    }
-//
-//    @Test
-//    public void testChangePassword() throws RepositoryException, NotExecutableException
{
-//        try {
-//            String hash = getNode(user, superuser).getProperty(UserConstants.REP_PASSWORD).getString();
-//
-//            user.changePassword("changed");
-//            superuser.save();
-//
-//            assertFalse(hash.equals(getNode(user, superuser).getProperty(UserConstants.REP_PASSWORD).getString()));
-//        } catch (Exception e) {
-//            // success
-//        }
-//    }
-//
-//    @Test
-//    public void testChangePasswordWithInvalidOldPassword() throws RepositoryException,
NotExecutableException {
-//        try {
-//            user.changePassword("changed", "wrongOldPw");
-//            superuser.save();
-//            fail("old password didn't match -> changePassword(String,String) should
fail.");
-//        } catch (RepositoryException e) {
-//            // success.
-//        }
-//    }
-//
-//    @Test
-//    public void testChangePasswordWithOldPassword() throws RepositoryException, NotExecutableException
{
-//        try {
-//            String hash = getNode(user, superuser).getProperty(UserConstants.REP_PASSWORD).getString();
-//
-//            user.changePassword("changed", testPw);
-//            superuser.save();
-//
-//            assertFalse(hash.equals(getNode(user, superuser).getProperty(UserConstants.REP_PASSWORD).getString()));
-//        } finally {
-//            user.changePassword(testPw);
-//            superuser.save();
-//        }
-//    }
-//
-//    @Test
-//    public void testLoginAfterChangePassword() throws RepositoryException {
-//        user.changePassword("changed");
-//        superuser.save();
-//
-//        // make sure the user can login with the new pw
-//        Session s = getHelper().getRepository().login(new SimpleCredentials(user.getID(),
"changed".toCharArray()));
-//        s.logout();
-//    }
-//
-//    @Test
-//    public void testLoginAfterChangePassword2() throws RepositoryException, NotExecutableException
{
-//        try {
-//
-//            user.changePassword("changed", testPw);
-//            superuser.save();
-//
-//            // make sure the user can login with the new pw
-//            Session s = getHelper().getRepository().login(new SimpleCredentials(user.getID(),
"changed".toCharArray()));
-//            s.logout();
-//        } finally {
-//            user.changePassword(testPw);
-//            superuser.save();
-//        }
-//    }
-//
-//    @Test
-//    public void testLoginWithOldPassword() throws RepositoryException, NotExecutableException
{
-//        try {
-//            user.changePassword("changed");
-//            superuser.save();
-//
-//            Session s = getHelper().getRepository().login(new SimpleCredentials(user.getID(),
testPw.toCharArray()));
-//            s.logout();
-//            fail("user pw has changed. login must fail.");
-//        } catch (LoginException e) {
-//            // success
-//        }
-//    }
-//
-//    @Test
-//    public void testLoginWithOldPassword2() throws RepositoryException, NotExecutableException
{
-//        try {
-//            user.changePassword("changed", testPw);
-//            superuser.save();
-//
-//            Session s = getHelper().getRepository().login(new SimpleCredentials(user.getID(),
testPw.toCharArray()));
-//            s.logout();
-//            fail("superuser pw has changed. login must fail.");
-//        } catch (LoginException e) {
-//            // success
-//        } finally {
-//            user.changePassword(testPw);
-//            superuser.save();
-//        }
-//    }
-//
-//    @Test
-//    public void testEnabledByDefault() throws Exception {
-//        // by default a user isn't disabled
-//        assertFalse(user.isDisabled());
-//        assertNull(user.getDisabledReason());
-//    }
-//
-//    @Test
-//    public void testDisable() throws Exception {
-//        String reason = "readonly user is disabled!";
-//        user.disable(reason);
-//        superuser.save();
-//        assertTrue(user.isDisabled());
-//        assertEquals(reason, user.getDisabledReason());
-//    }
-//
-//    @Test
-//    public void testAccessDisabledUser() throws Exception {
-//        user.disable("readonly user is disabled!");
-//        superuser.save();
-//
-//        // user must still be retrievable from user manager
-//        assertNotNull(getUserManager(superuser).getAuthorizable(user.getID()));
-//        // ... and from principal manager as well
-//        assertTrue(((JackrabbitSession) superuser).getPrincipalManager().hasPrincipal(user.getPrincipal().getName()));
-//    }
-//
-//    @Test
-//    public void testAccessPrincipalOfDisabledUser()  throws Exception {
-//        user.disable("readonly user is disabled!");
-//        superuser.save();
-//
-//        Principal principal = user.getPrincipal();
-//        assertTrue(((JackrabbitSession) superuser).getPrincipalManager().hasPrincipal(principal.getName()));
-//        assertEquals(principal, ((JackrabbitSession) superuser).getPrincipalManager().getPrincipal(principal.getName()));
-//    }
-//
-//    @Test
-//    public void testEnableUser() throws Exception {
-//        user.disable("readonly user is disabled!");
-//        superuser.save();
-//
-//        // enable user again
-//        user.disable(null);
-//        superuser.save();
-//        assertFalse(user.isDisabled());
-//        assertNull(user.getDisabledReason());
-//
-//        // -> login must succeed again
-//        getHelper().getRepository().login(new SimpleCredentials(user.getID(), "pw".toCharArray())).logout();
-//    }
-//
-//    @Test
-//    public void testLoginDisabledUser() throws Exception {
-//        user.disable("readonly user is disabled!");
-//        superuser.save();
-//
-//        // -> login must fail
-//        try {
-//            Session ss = getHelper().getRepository().login(new SimpleCredentials(user.getID(),
"pw".toCharArray()));
-//            ss.logout();
-//            fail("A disabled user must not be allowed to login any more");
-//        } catch (LoginException e) {
-//            // success
-//        }
-//    }
-//
-//    @Test
-//    public void testImpersonateDisabledUser() throws Exception {
-//        user.disable("readonly user is disabled!");
-//        superuser.save();
-//
-//        // -> impersonating this user must fail
-//        try {
-//            Session ss = superuser.impersonate(new SimpleCredentials(user.getID(), new
char[0]));
-//            ss.logout();
-//            fail("A disabled user cannot be impersonated any more.");
-//        } catch (LoginException e) {
-//            // success
-//        }
-//    }
-//
-//    @Test
-//    public void testLoginWithGetCredentials() throws RepositoryException, NotExecutableException
{
-//        try {
-//            Credentials creds = user.getCredentials();
-//            Session s = getHelper().getRepository().login(creds);
-//            s.logout();
-//            fail("Login using credentials exposed on user must fail.");
-//        } catch (UnsupportedRepositoryOperationException e) {
-//            throw new NotExecutableException(e.getMessage());
-//        } catch (LoginException e) {
-//            // success
-//        }
-//    }
+    @Test
+    public void testIsGroup() throws RepositoryException {
+        assertFalse(user.isGroup());
+    }
+
+    @Test
+    public void testGetId() throws NotExecutableException, RepositoryException {
+        assertNotNull(user.getID());
+        assertNotNull(userMgr.getAuthorizable(user.getID()).getID());
+    }
+
+    @Test
+    public void testGetPrincipal() throws RepositoryException, NotExecutableException {
+        assertNotNull(user.getPrincipal());
+        assertNotNull(userMgr.getAuthorizable(user.getID()).getPrincipal());
+    }
+
+    @Test
+    public void testGetPath() throws RepositoryException, NotExecutableException {
+        assertNotNull(user.getPath());
+        assertNotNull(userMgr.getAuthorizable(user.getID()).getPath());
+        try {
+            assertEquals(getNode(user, superuser).getPath(), user.getPath());
+        } catch (UnsupportedRepositoryOperationException e) {
+            // ok.
+        }
+    }
+
+    @Test
+    public void testIsAdmin() throws NotExecutableException, RepositoryException {
+        assertFalse(user.isAdmin());
+    }
+
+    @Test
+    public void testChangePasswordNull() throws RepositoryException, NotExecutableException
{
+        // invalid 'null' pw string
+        try {
+            user.changePassword(null);
+            superuser.save();
+            fail("invalid pw null");
+        } catch (Exception e) {
+            // success
+        }
+    }
+
+    @Test
+    public void testChangePassword() throws RepositoryException, NotExecutableException {
+        try {
+            String hash = getNode(user, superuser).getProperty(UserConstants.REP_PASSWORD).getString();
+
+            user.changePassword("changed");
+            superuser.save();
+
+            assertFalse(hash.equals(getNode(user, superuser).getProperty(UserConstants.REP_PASSWORD).getString()));
+        } catch (Exception e) {
+            // success
+        }
+    }
+
+    @Test
+    public void testChangePasswordWithInvalidOldPassword() throws RepositoryException, NotExecutableException
{
+        try {
+            user.changePassword("changed", "wrongOldPw");
+            superuser.save();
+            fail("old password didn't match -> changePassword(String,String) should fail.");
+        } catch (RepositoryException e) {
+            // success.
+        }
+    }
+
+    @Test
+    public void testChangePasswordWithOldPassword() throws RepositoryException, NotExecutableException
{
+        try {
+            String hash = getNode(user, superuser).getProperty(UserConstants.REP_PASSWORD).getString();
+
+            user.changePassword("changed", testPw);
+            superuser.save();
+
+            assertFalse(hash.equals(getNode(user, superuser).getProperty(UserConstants.REP_PASSWORD).getString()));
+        } finally {
+            user.changePassword(testPw);
+            superuser.save();
+        }
+    }
+
+    @Test
+    public void testLoginAfterChangePassword() throws RepositoryException {
+        user.changePassword("changed");
+        superuser.save();
+
+        // make sure the user can login with the new pw
+        Session s = getHelper().getRepository().login(new SimpleCredentials(user.getID(),
"changed".toCharArray()));
+        s.logout();
+    }
+
+    @Test
+    public void testLoginAfterChangePassword2() throws RepositoryException, NotExecutableException
{
+        try {
+
+            user.changePassword("changed", testPw);
+            superuser.save();
+
+            // make sure the user can login with the new pw
+            Session s = getHelper().getRepository().login(new SimpleCredentials(user.getID(),
"changed".toCharArray()));
+            s.logout();
+        } finally {
+            user.changePassword(testPw);
+            superuser.save();
+        }
+    }
+
+    @Test
+    public void testLoginWithOldPassword() throws RepositoryException, NotExecutableException
{
+        try {
+            user.changePassword("changed");
+            superuser.save();
+
+            Session s = getHelper().getRepository().login(new SimpleCredentials(user.getID(),
testPw.toCharArray()));
+            s.logout();
+            fail("user pw has changed. login must fail.");
+        } catch (LoginException e) {
+            // success
+        }
+    }
+
+    @Test
+    public void testLoginWithOldPassword2() throws RepositoryException, NotExecutableException
{
+        try {
+            user.changePassword("changed", testPw);
+            superuser.save();
+
+            Session s = getHelper().getRepository().login(new SimpleCredentials(user.getID(),
testPw.toCharArray()));
+            s.logout();
+            fail("superuser pw has changed. login must fail.");
+        } catch (LoginException e) {
+            // success
+        } finally {
+            user.changePassword(testPw);
+            superuser.save();
+        }
+    }
+
+    @Test
+    public void testEnabledByDefault() throws Exception {
+        // by default a user isn't disabled
+        assertFalse(user.isDisabled());
+        assertNull(user.getDisabledReason());
+    }
+
+    @Test
+    public void testDisable() throws Exception {
+        String reason = "readonly user is disabled!";
+        user.disable(reason);
+        superuser.save();
+        assertTrue(user.isDisabled());
+        assertEquals(reason, user.getDisabledReason());
+    }
+
+    @Test
+    public void testAccessDisabledUser() throws Exception {
+        user.disable("readonly user is disabled!");
+        superuser.save();
+
+        // user must still be retrievable from user manager
+        assertNotNull(getUserManager(superuser).getAuthorizable(user.getID()));
+        // ... and from principal manager as well
+        assertTrue(((JackrabbitSession) superuser).getPrincipalManager().hasPrincipal(user.getPrincipal().getName()));
+    }
+
+    @Test
+    public void testAccessPrincipalOfDisabledUser()  throws Exception {
+        user.disable("readonly user is disabled!");
+        superuser.save();
+
+        Principal principal = user.getPrincipal();
+        assertTrue(((JackrabbitSession) superuser).getPrincipalManager().hasPrincipal(principal.getName()));
+        assertEquals(principal, ((JackrabbitSession) superuser).getPrincipalManager().getPrincipal(principal.getName()));
+    }
+
+    @Test
+    public void testEnableUser() throws Exception {
+        user.disable("readonly user is disabled!");
+        superuser.save();
+
+        // enable user again
+        user.disable(null);
+        superuser.save();
+        assertFalse(user.isDisabled());
+        assertNull(user.getDisabledReason());
+
+        // -> login must succeed again
+        getHelper().getRepository().login(new SimpleCredentials(user.getID(), "pw".toCharArray())).logout();
+    }
+
+    @Test
+    public void testLoginDisabledUser() throws Exception {
+        user.disable("readonly user is disabled!");
+        superuser.save();
+
+        // -> login must fail
+        try {
+            Session ss = getHelper().getRepository().login(new SimpleCredentials(user.getID(),
"pw".toCharArray()));
+            ss.logout();
+            fail("A disabled user must not be allowed to login any more");
+        } catch (LoginException e) {
+            // success
+        }
+    }
+
+    @Test
+    public void testImpersonateDisabledUser() throws Exception {
+        user.disable("readonly user is disabled!");
+        superuser.save();
+
+        // -> impersonating this user must fail
+        try {
+            Session ss = superuser.impersonate(new SimpleCredentials(user.getID(), new char[0]));
+            ss.logout();
+            fail("A disabled user cannot be impersonated any more.");
+        } catch (LoginException e) {
+            // success
+        }
+    }
+
+    @Test
+    public void testLoginWithGetCredentials() throws RepositoryException, NotExecutableException
{
+        try {
+            Credentials creds = user.getCredentials();
+            Session s = getHelper().getRepository().login(creds);
+            s.logout();
+            fail("Login using credentials exposed on user must fail.");
+        } catch (UnsupportedRepositoryOperationException e) {
+            throw new NotExecutableException(e.getMessage());
+        } catch (LoginException e) {
+            // success
+        }
+    }
 }
\ No newline at end of file



Mime
View raw message