Search in sources :

Example 31 with UserManager

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

the class AbstractLoginModuleTest method testGetUserManagerFromCallback.

@Test
public void testGetUserManagerFromCallback() {
    AbstractLoginModule loginModule = initLoginModule(TestCredentials.class, new TestCallbackHandler(Mockito.mock(UserManager.class)));
    UserManager userManager = loginModule.getUserManager();
    assertNotNull(userManager);
    // usermanager is stored as field -> second access returns the same object
    assertSame(userManager, loginModule.getUserManager());
}
Also used : UserManager(org.apache.jackrabbit.api.security.user.UserManager) Test(org.junit.Test)

Example 32 with UserManager

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

the class QueryTest method xpathEscapeTest.

@SuppressWarnings("deprecation")
@Test
public void xpathEscapeTest() throws RepositoryException {
    Session writer = createAdminSession();
    Session reader = createAdminSession();
    UserManager uMgr = ((JackrabbitSession) writer).getUserManager();
    String uid = "testUser";
    try {
        User user = uMgr.createUser("testUser", "pw");
        writer.getNode(user.getPath()).addNode(".tokens", "rep:Unstructured");
        writer.save();
        QueryManager qm = reader.getWorkspace().getQueryManager();
        Query q = qm.createQuery("/jcr:root//*[_x002e_tokens/@jcr:primaryType]", Query.XPATH);
        NodeIterator res = q.execute().getNodes();
        assertEquals(1, res.getSize());
    } finally {
        Authorizable a = uMgr.getAuthorizable(uid);
        if (a != null) {
            a.remove();
            writer.save();
        }
        if (reader != null) {
            reader.logout();
        }
        if (writer != null) {
            writer.logout();
        }
    }
}
Also used : NodeIterator(javax.jcr.NodeIterator) User(org.apache.jackrabbit.api.security.user.User) Query(javax.jcr.query.Query) UserManager(org.apache.jackrabbit.api.security.user.UserManager) QueryManager(javax.jcr.query.QueryManager) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession) Session(javax.jcr.Session) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession) Test(org.junit.Test) AbstractRepositoryTest(org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest)

Example 33 with UserManager

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

the class UserManagerTest method testCleanup.

@Test
public void testCleanup() throws RepositoryException, NotExecutableException {
    Session s = getHelper().getSuperuserSession();
    try {
        UserManager umgr = getUserManager(s);
        s.logout();
        // any more -> accessing users must fail.
        try {
            umgr.getAuthorizable("any userid");
            fail("After having logged out the original session, the user manager must not be live any more.");
        } catch (RepositoryException e) {
        // success
        }
    } finally {
        if (s.isLive()) {
            s.logout();
        }
    }
}
Also used : UserManager(org.apache.jackrabbit.api.security.user.UserManager) RepositoryException(javax.jcr.RepositoryException) Session(javax.jcr.Session) Test(org.junit.Test)

Example 34 with UserManager

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

the class UserManagerTest method testCleanupForAllWorkspaces.

@Test
public void testCleanupForAllWorkspaces() throws RepositoryException, NotExecutableException {
    String[] workspaceNames = superuser.getWorkspace().getAccessibleWorkspaceNames();
    for (String workspaceName1 : workspaceNames) {
        Session s = getHelper().getSuperuserSession(workspaceName1);
        try {
            UserManager umgr = getUserManager(s);
            s.logout();
            // any more -> accessing users must fail.
            try {
                umgr.getAuthorizable("any userid");
                fail("After having logged out the original session, the user manager must not be live any more.");
            } catch (RepositoryException e) {
            // success
            }
        } finally {
            if (s.isLive()) {
                s.logout();
            }
        }
    }
}
Also used : UserManager(org.apache.jackrabbit.api.security.user.UserManager) RepositoryException(javax.jcr.RepositoryException) Session(javax.jcr.Session) Test(org.junit.Test)

Example 35 with UserManager

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

the class AbstractPrincipalProviderTest method testFindUserPrincipal.

@Test
public void testFindUserPrincipal() throws Exception {
    User testUser = null;
    try {
        UserManager userMgr = getUserManager(root);
        testUser = userMgr.createUser("TestUser", "pw");
        root.commit();
        String principalName = testUser.getPrincipal().getName();
        assertNotNull(principalProvider.getPrincipal(principalName));
        List<String> nameHints = new ArrayList<String>();
        nameHints.add("TestUser");
        nameHints.add("Test");
        nameHints.add("User");
        nameHints.add("stUs");
        assertResult(principalProvider, nameHints, principalName, PrincipalManager.SEARCH_TYPE_NOT_GROUP, true);
        assertResult(principalProvider, nameHints, principalName, PrincipalManager.SEARCH_TYPE_ALL, true);
        assertResult(principalProvider, nameHints, principalName, PrincipalManager.SEARCH_TYPE_GROUP, false);
    } finally {
        if (testUser != null) {
            testUser.remove();
            root.commit();
        }
    }
}
Also used : User(org.apache.jackrabbit.api.security.user.User) UserManager(org.apache.jackrabbit.api.security.user.UserManager) ArrayList(java.util.ArrayList) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) 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