Search in sources :

Example 76 with UserManager

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

the class RepositoryGroupMemberUpgradeTest method createSourceContent.

@Override
protected void createSourceContent(Session session) throws Exception {
    UserManager userMgr = ((JackrabbitSession) session).getUserManager();
    userMgr.autoSave(false);
    User[] users = new User[getNumUsers()];
    for (int i = 0; i < users.length; i++) {
        String userId = TEST_USER_PREFIX + i;
        users[i] = userMgr.createUser(userId, userId);
    }
    for (int i = 0; i < getNumGroups(); i++) {
        Group g = userMgr.createGroup(TEST_GROUP_PREFIX + i);
        for (User user : users) {
            g.addMember(user);
        }
    }
    session.save();
}
Also used : Group(org.apache.jackrabbit.api.security.user.Group) User(org.apache.jackrabbit.api.security.user.User) UserManager(org.apache.jackrabbit.api.security.user.UserManager) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession)

Example 77 with UserManager

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

the class LoginModuleImplTest method createTestUser.

private User createTestUser() throws RepositoryException, CommitFailedException {
    if (user == null) {
        UserManager userManager = getUserManager(root);
        user = userManager.createUser(USER_ID, USER_PW);
        root.commit();
    }
    return user;
}
Also used : UserManager(org.apache.jackrabbit.api.security.user.UserManager)

Example 78 with UserManager

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

the class LoginModuleImplTest method testUserLoginIsCaseInsensitive.

@Test
public void testUserLoginIsCaseInsensitive() throws Exception {
    ContentSession cs = null;
    try {
        createTestUser();
        cs = login(new SimpleCredentials(USER_ID_CASED, USER_PW.toCharArray()));
        AuthInfo authInfo = cs.getAuthInfo();
        UserManager userMgr = getUserManager(root);
        Authorizable auth = userMgr.getAuthorizable(authInfo.getUserID());
        assertNotNull(auth);
        assertTrue(auth.getID().equalsIgnoreCase(USER_ID_CASED));
    } finally {
        if (cs != null) {
            cs.close();
        }
    }
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) AuthInfo(org.apache.jackrabbit.oak.api.AuthInfo) UserManager(org.apache.jackrabbit.api.security.user.UserManager) ContentSession(org.apache.jackrabbit.oak.api.ContentSession) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 79 with UserManager

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

the class LoginModuleImplTest method testAnonymousLogin.

@Test
public void testAnonymousLogin() throws Exception {
    String anonymousID = UserUtil.getAnonymousId(getUserConfiguration().getParameters());
    UserManager userMgr = getUserManager(root);
    // verify initial user-content looks like expected
    Authorizable anonymous = userMgr.getAuthorizable(anonymousID);
    assertNotNull(anonymous);
    assertFalse(root.getTree(anonymous.getPath()).hasProperty(UserConstants.REP_PASSWORD));
    ContentSession cs = null;
    try {
        cs = login(new SimpleCredentials(anonymousID, new char[0]));
        fail("Login with anonymousID should fail since the initial setup doesn't provide a password.");
    } catch (LoginException e) {
    // success
    } finally {
        if (cs != null) {
            cs.close();
        }
    }
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) UserManager(org.apache.jackrabbit.api.security.user.UserManager) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) ContentSession(org.apache.jackrabbit.oak.api.ContentSession) LoginException(javax.security.auth.login.LoginException) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 80 with UserManager

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

the class Jr2CompatibilityTest method testUserManagementPermissionWithJr2Flag.

@Test
public void testUserManagementPermissionWithJr2Flag() throws Exception {
    Root testRoot = getTestRoot();
    testRoot.refresh();
    UserManager testUserMgr = getUserConfiguration().getUserManager(testRoot, NamePathMapper.DEFAULT);
    try {
        User u = testUserMgr.createUser("a", "b");
        testRoot.commit();
        u.changePassword("c");
        testRoot.commit();
        u.remove();
        testRoot.commit();
    } finally {
        root.refresh();
        Authorizable user = getUserManager(root).getAuthorizable("a");
        if (user != null) {
            user.remove();
            root.commit();
        }
    }
}
Also used : User(org.apache.jackrabbit.api.security.user.User) Root(org.apache.jackrabbit.oak.api.Root) UserManager(org.apache.jackrabbit.api.security.user.UserManager) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) 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