Search in sources :

Example 86 with UserManager

use of org.apache.jackrabbit.api.security.user.UserManager in project jackrabbit-oak by apache.

the class UserManagementTest method testDisableUserWithoutPermission2.

@Test
public void testDisableUserWithoutPermission2() throws Exception {
    createUser(userId);
    modify("/", PrivilegeConstants.REP_WRITE, true);
    UserManager testUserMgr = getUserManager(testSession);
    User user = (User) testUserMgr.getAuthorizable(userId);
    try {
        user.disable("disabled!");
        testSession.save();
        fail();
    } catch (AccessDeniedException e) {
    // success
    }
}
Also used : AccessDeniedException(javax.jcr.AccessDeniedException) User(org.apache.jackrabbit.api.security.user.User) UserManager(org.apache.jackrabbit.api.security.user.UserManager) Test(org.junit.Test)

Example 87 with UserManager

use of org.apache.jackrabbit.api.security.user.UserManager in project jackrabbit-oak by apache.

the class UserManagementTest method testChangeUserPropertiesWithoutPermission.

@Test
public void testChangeUserPropertiesWithoutPermission() throws Exception {
    createUser(userId);
    // testSession has read-only access
    UserManager testUserMgr = getUserManager(testSession);
    try {
        Authorizable a = testUserMgr.getAuthorizable(userId);
        a.setProperty("someProp", testSession.getValueFactory().createValue("value"));
        testSession.save();
        fail("Test session doesn't have sufficient permission to alter user properties.");
    } catch (AccessDeniedException e) {
    // success
    }
}
Also used : AccessDeniedException(javax.jcr.AccessDeniedException) UserManager(org.apache.jackrabbit.api.security.user.UserManager) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) Test(org.junit.Test)

Example 88 with UserManager

use of org.apache.jackrabbit.api.security.user.UserManager in project jackrabbit-oak by apache.

the class UserManagementTest method testCreateUser.

@Test
public void testCreateUser() throws Exception {
    UserManager testUserMgr = getUserManager(testSession);
    modify("/", PrivilegeConstants.REP_USER_MANAGEMENT, true);
    // creating user should succeed
    testUserMgr.createUser(userId, "pw");
    testSession.save();
}
Also used : UserManager(org.apache.jackrabbit.api.security.user.UserManager) Test(org.junit.Test)

Example 89 with UserManager

use of org.apache.jackrabbit.api.security.user.UserManager in project jackrabbit-oak by apache.

the class UserManagementTest method testChangePassword.

@Test
public void testChangePassword() throws Exception {
    createUser(userId);
    // after granting user-mgt privilege changing the pw must succeed.
    modify("/", PrivilegeConstants.REP_USER_MANAGEMENT, true);
    UserManager testUserMgr = getUserManager(testSession);
    User user = (User) testUserMgr.getAuthorizable(userId);
    user.changePassword("pw2");
    testSession.save();
}
Also used : User(org.apache.jackrabbit.api.security.user.User) UserManager(org.apache.jackrabbit.api.security.user.UserManager) Test(org.junit.Test)

Example 90 with UserManager

use of org.apache.jackrabbit.api.security.user.UserManager in project jackrabbit-oak by apache.

the class UserManagementTest method testChangePasswordWithoutPermission2.

@Test
public void testChangePasswordWithoutPermission2() throws Exception {
    createUser(userId);
    modify("/", PrivilegeConstants.REP_WRITE, true);
    UserManager testUserMgr = getUserManager(testSession);
    User user = (User) testUserMgr.getAuthorizable(userId);
    try {
        user.changePassword("pw2");
        testSession.save();
        fail();
    } catch (AccessDeniedException e) {
    // success
    }
}
Also used : AccessDeniedException(javax.jcr.AccessDeniedException) User(org.apache.jackrabbit.api.security.user.User) UserManager(org.apache.jackrabbit.api.security.user.UserManager) Test(org.junit.Test)

Aggregations

UserManager (org.apache.jackrabbit.api.security.user.UserManager)234 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)93 Test (org.junit.Test)90 Group (org.apache.jackrabbit.api.security.user.Group)81 User (org.apache.jackrabbit.api.security.user.User)72 JackrabbitSession (org.apache.jackrabbit.api.JackrabbitSession)52 Session (javax.jcr.Session)45 RepositoryException (javax.jcr.RepositoryException)40 Principal (java.security.Principal)38 SimpleCredentials (javax.jcr.SimpleCredentials)34 AccessDeniedException (javax.jcr.AccessDeniedException)19 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)19 ContentSession (org.apache.jackrabbit.oak.api.ContentSession)19 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)17 Node (javax.jcr.Node)15 PrincipalImpl (org.apache.jackrabbit.oak.spi.security.principal.PrincipalImpl)14 Value (javax.jcr.Value)11 Root (org.apache.jackrabbit.oak.api.Root)11 AccessControlManager (javax.jcr.security.AccessControlManager)9 ItemBasedPrincipal (org.apache.jackrabbit.api.security.principal.ItemBasedPrincipal)9