Search in sources :

Example 36 with Session

use of javax.jcr.Session in project jackrabbit-oak by apache.

the class UserManagerTest method testUserIDFromSession.

@Test
public void testUserIDFromSession() throws RepositoryException, NotExecutableException {
    User u = null;
    Session uSession = null;
    try {
        String uid = createUserId();
        u = userMgr.createUser(uid, "pw");
        superuser.save();
        uSession = superuser.getRepository().login(new SimpleCredentials(uid, "pw".toCharArray()));
        assertEquals(u.getID(), uSession.getUserID());
    } finally {
        if (uSession != null) {
            uSession.logout();
        }
        if (u != null) {
            u.remove();
            superuser.save();
        }
    }
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) User(org.apache.jackrabbit.api.security.user.User) Session(javax.jcr.Session) Test(org.junit.Test)

Example 37 with Session

use of javax.jcr.Session 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 38 with Session

use of javax.jcr.Session in project jackrabbit-oak by apache.

the class IsMemberTest method beforeSuite.

@Override
protected void beforeSuite() throws Exception {
    super.beforeSuite();
    Session s = loginAdministrative();
    try {
        UserManager userManager = ((JackrabbitSession) s).getUserManager();
        Group gr = userManager.createGroup(new PrincipalImpl(GROUP + 0), REL_TEST_PATH);
        gPaths.add(gr.getPath());
        for (int i = 1; i < GROUP_CNT; i++) {
            Group g = userManager.createGroup(new PrincipalImpl(GROUP + i), REL_TEST_PATH);
            if (nestedGroups) {
                g.addMember(gr);
            }
            gr = g;
            gPaths.add(gr.getPath());
        }
        int cnt = 0;
        for (int i = 0; i <= numberOfUsers; i++) {
            User u = userManager.createUser(USER + i, null, new PrincipalImpl(USER + i), REL_TEST_PATH);
            uPaths.add(u.getPath());
            getRandomGroup(userManager).addMember(u);
            if (++cnt == 20000) {
                s.save();
            }
        }
    } finally {
        s.save();
        s.logout();
    }
    System.out.println("setup done");
}
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) PrincipalImpl(org.apache.jackrabbit.oak.spi.security.principal.PrincipalImpl) Session(javax.jcr.Session) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession)

Example 39 with Session

use of javax.jcr.Session in project jackrabbit-oak by apache.

the class MemberBaseTest method afterSuite.

@Override
public void afterSuite() throws Exception {
    Session s = loginAdministrative();
    try {
        Authorizable authorizable = ((JackrabbitSession) s).getUserManager().getAuthorizable(GROUP + "0");
        if (authorizable != null) {
            Node n = s.getNode(Text.getRelativeParent(authorizable.getPath(), 1));
            n.remove();
        }
        authorizable = ((JackrabbitSession) s).getUserManager().getAuthorizable(USER + "0");
        if (authorizable != null) {
            Node n = s.getNode(Text.getRelativeParent(authorizable.getPath(), 1));
            n.remove();
        }
        s.save();
    } finally {
        s.logout();
    }
}
Also used : Node(javax.jcr.Node) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession) Session(javax.jcr.Session) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession)

Example 40 with Session

use of javax.jcr.Session in project jackrabbit-oak by apache.

the class ObservationTest method addRootListener.

private void addRootListener(Repository repository, List<Session> sessions, List<EventListener> listeners) throws RepositoryException {
    Session s = createSession(repository);
    sessions.add(s);
    Listener listener = new Listener(new AtomicInteger());
    ObservationManager obsMgr = s.getWorkspace().getObservationManager();
    obsMgr.addEventListener(listener, EVENT_TYPES, "/", true, null, null, false);
    listeners.add(listener);
}
Also used : EventListener(javax.jcr.observation.EventListener) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ObservationManager(javax.jcr.observation.ObservationManager) Session(javax.jcr.Session)

Aggregations

Session (javax.jcr.Session)1393 Node (javax.jcr.Node)761 Test (org.junit.Test)387 RepositoryException (javax.jcr.RepositoryException)304 JackrabbitSession (org.apache.jackrabbit.api.JackrabbitSession)162 Property (javax.jcr.Property)90 SimpleCredentials (javax.jcr.SimpleCredentials)88 Privilege (javax.jcr.security.Privilege)84 JackrabbitNode (org.apache.jackrabbit.api.JackrabbitNode)77 Value (javax.jcr.Value)71 Query (javax.jcr.query.Query)69 NodeIterator (javax.jcr.NodeIterator)68 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)65 QueryManager (javax.jcr.query.QueryManager)63 HashMap (java.util.HashMap)57 IOException (java.io.IOException)56 ArrayList (java.util.ArrayList)55 AccessControlManager (javax.jcr.security.AccessControlManager)55 AbstractRepositoryTest (org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest)52 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)49