Search in sources :

Example 66 with JackrabbitSession

use of org.apache.jackrabbit.api.JackrabbitSession in project jackrabbit by apache.

the class ConcurrentCreateUserTest method testCreateUsers.

public void testCreateUsers() throws Exception {
    log.println("ConcurrentCreateUserTest.testCreateUsers: c=" + CONCURRENCY);
    log.flush();
    runTask(new Task() {

        public void execute(Session session, Node test) throws RepositoryException {
            JackrabbitSession s = null;
            try {
                s = (JackrabbitSession) getHelper().getSuperuserSession();
                String name = "newname-" + UUID.randomUUID();
                Authorizable authorizable = null;
                int maxtries = RETRIES;
                RepositoryException lastex = null;
                while (authorizable == null && maxtries > 0) {
                    try {
                        maxtries -= 1;
                        authorizable = s.getUserManager().createUser(name, "password1", new TestPrincipal(name), INTERMEDIATE_PATH);
                        s.save();
                    } catch (InvalidItemStateException ex) {
                        lastex = ex;
                        log.println("got " + ex + ", retrying");
                    }
                }
                if (authorizable == null) {
                    throw new RepositoryException("user " + name + " not created in " + RETRIES + " attempts.", lastex);
                }
                userIDs.add(authorizable.getID());
                log.println(authorizable + " created");
            } finally {
                s.logout();
            }
        }
    }, CONCURRENCY, "/" + testPath);
}
Also used : TestPrincipal(org.apache.jackrabbit.core.security.TestPrincipal) InvalidItemStateException(javax.jcr.InvalidItemStateException) Node(javax.jcr.Node) RepositoryException(javax.jcr.RepositoryException) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession) Session(javax.jcr.Session) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession)

Example 67 with JackrabbitSession

use of org.apache.jackrabbit.api.JackrabbitSession in project jackrabbit by apache.

the class UserPerWorkspaceSecurityManagerTest method testAccessibleWorkspaceNames.

public void testAccessibleWorkspaceNames() throws Exception {
    String altWsp = getAlternativeWorkspaceName();
    if (altWsp == null) {
        throw new NotExecutableException();
    }
    Session s = getHelper().getSuperuserSession(altWsp);
    User u = null;
    Session us = null;
    try {
        // other users created in the default workspace...
        u = ((JackrabbitSession) superuser).getUserManager().createUser("testUser", "testUser");
        superuser.save();
        us = getHelper().getRepository().login(new SimpleCredentials("testUser", "testUser".toCharArray()));
        String[] wspNames = us.getWorkspace().getAccessibleWorkspaceNames();
        assertFalse(Arrays.asList(wspNames).contains(altWsp));
    } finally {
        s.logout();
        if (us != null) {
            us.logout();
        }
        if (u != null) {
            u.remove();
            superuser.save();
        }
    }
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) User(org.apache.jackrabbit.api.security.user.User) NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession) Session(javax.jcr.Session) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession)

Example 68 with JackrabbitSession

use of org.apache.jackrabbit.api.JackrabbitSession in project jackrabbit by apache.

the class UserPerWorkspaceSecurityManagerTest method testNewUsersCanLogin.

public void testNewUsersCanLogin() throws Exception {
    Session s = null;
    User u = null;
    try {
        // other users created in the default workspace...
        u = ((JackrabbitSession) superuser).getUserManager().createUser("testUser", "testUser");
        superuser.save();
        // the new user must be able to login to the repo
        s = getHelper().getRepository().login(new SimpleCredentials("testUser", "testUser".toCharArray()));
    } finally {
        if (s != null) {
            s.logout();
        }
        if (u != null) {
            u.remove();
            superuser.save();
        }
    }
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) User(org.apache.jackrabbit.api.security.user.User) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession) Session(javax.jcr.Session) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession)

Example 69 with JackrabbitSession

use of org.apache.jackrabbit.api.JackrabbitSession in project jackrabbit by apache.

the class UserPerWorkspaceSecurityManagerTest method testSystemUserCreation.

public void testSystemUserCreation() throws Exception {
    String altWsp = getAlternativeWorkspaceName();
    if (altWsp == null) {
        throw new NotExecutableException();
    }
    // system users must be automatically be created -> login with admin
    // must therefore succeed.
    Session s = getHelper().getSuperuserSession(altWsp);
    try {
        // admin/anonymous must be present
        String adminId = ((UserPerWorkspaceSecurityManager) secMgr).adminId;
        assertEquals(adminId, s.getUserID());
        UserManager umgr = ((JackrabbitSession) s).getUserManager();
        assertNotNull(umgr.getAuthorizable(adminId));
        assertNotNull(umgr.getAuthorizable(((UserPerWorkspaceSecurityManager) secMgr).anonymousId));
    } finally {
        s.logout();
    }
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) UserManager(org.apache.jackrabbit.api.security.user.UserManager) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession) Session(javax.jcr.Session) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession)

Example 70 with JackrabbitSession

use of org.apache.jackrabbit.api.JackrabbitSession in project jackrabbit by apache.

the class SkipDeniedNodesTest method getPrincipal.

private static Principal getPrincipal(Session session) throws NotExecutableException {
    UserManager userMgr;
    if (!(session instanceof JackrabbitSession)) {
        throw new NotExecutableException();
    }
    try {
        userMgr = ((JackrabbitSession) session).getUserManager();
        User user = (User) userMgr.getAuthorizable(session.getUserID());
        if (user == null) {
            throw new NotExecutableException("cannot get user for userID : " + session.getUserID());
        }
        return user.getPrincipal();
    } catch (RepositoryException e) {
        throw new NotExecutableException();
    }
}
Also used : User(org.apache.jackrabbit.api.security.user.User) NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) UserManager(org.apache.jackrabbit.api.security.user.UserManager) RepositoryException(javax.jcr.RepositoryException) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession)

Aggregations

JackrabbitSession (org.apache.jackrabbit.api.JackrabbitSession)114 UserManager (org.apache.jackrabbit.api.security.user.UserManager)51 Session (javax.jcr.Session)50 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)34 Node (javax.jcr.Node)25 Group (org.apache.jackrabbit.api.security.user.Group)25 User (org.apache.jackrabbit.api.security.user.User)24 Principal (java.security.Principal)19 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)17 Test (org.junit.Test)16 SimpleCredentials (javax.jcr.SimpleCredentials)15 PrincipalImpl (org.apache.jackrabbit.oak.spi.security.principal.PrincipalImpl)11 RepositoryException (javax.jcr.RepositoryException)10 PrincipalIterator (org.apache.jackrabbit.api.security.principal.PrincipalIterator)9 PrincipalManager (org.apache.jackrabbit.api.security.principal.PrincipalManager)9 Privilege (javax.jcr.security.Privilege)8 LoginException (javax.jcr.LoginException)6 Property (javax.jcr.Property)6 ItemBasedPrincipal (org.apache.jackrabbit.api.security.principal.ItemBasedPrincipal)6 Item (javax.jcr.Item)5