Search in sources :

Example 86 with JackrabbitSession

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

the class AddMembersTest method beforeSuite.

@Override
public void beforeSuite() throws Exception {
    super.beforeSuite();
    Session s = loginAdministrative();
    try {
        UserManager userManager = ((JackrabbitSession) s).getUserManager();
        for (int i = 0; i <= GROUP_CNT; i++) {
            Group g = userManager.createGroup(new PrincipalImpl(GROUP + i), REL_TEST_PATH);
            groupPaths.add(g.getPath());
        }
        createUsers(userManager);
    } finally {
        s.save();
        s.logout();
    }
    System.out.println("setup done");
}
Also used : Group(org.apache.jackrabbit.api.security.user.Group) 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 87 with JackrabbitSession

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

the class AddMembersTest method runTest.

@Override
public void runTest() throws Exception {
    Session s = null;
    try {
        // use system session login to avoid measuring the login-performance here
        s = systemLogin();
        UserManager userManager = ((JackrabbitSession) s).getUserManager();
        String groupPath = groupPaths.get(random.nextInt(GROUP_CNT));
        Group g = (Group) userManager.getAuthorizableByPath(groupPath);
        addMembers(userManager, g, s);
    } catch (RepositoryException e) {
        if (s.hasPendingChanges()) {
            s.refresh(false);
        }
    } finally {
        if (s != null) {
            s.logout();
        }
    }
}
Also used : Group(org.apache.jackrabbit.api.security.user.Group) UserManager(org.apache.jackrabbit.api.security.user.UserManager) RepositoryException(javax.jcr.RepositoryException) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession) Session(javax.jcr.Session) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession)

Example 88 with JackrabbitSession

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

the class ScalabilityNodeRelationshipSuite method beforeIteration.

/**
     * Executes before each test run
     */
@Override
public void beforeIteration(ExecutionContext context) throws RepositoryException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Started beforeIteration()");
    }
    // Contextualize the node types being used
    if (nodeTypes != null && !nodeTypes.isEmpty()) {
        context.getMap().put(CTX_ACT_NODE_TYPE_PROP, nodeTypes.get(0));
        context.getMap().put(CTX_REL_NODE_TYPE_PROP, nodeTypes.get(1));
    }
    Session session = loginWriter();
    UserManager userMgr = ((JackrabbitSession) session).getUserManager();
    context.getMap().put("PREV_ITER_USERS", users.size());
    // Add users
    for (int idx = 0; idx < NUM_USERS * context.getIncrement(); idx++) {
        String name = String.valueOf((char) (random.nextInt(26) + 'a')) + CTX_USER + context.getIncrement() + "_" + idx;
        User user = userMgr.createUser(name, name);
        LOG.debug("User created : " + name);
        users.add(user);
    }
    // Add groups and include random number of members
    for (int idx = 0; idx < NUM_GROUPS * context.getIncrement(); idx++) {
        String name = String.valueOf((char) (random.nextInt(26) + 'a')) + CTX_GROUP + context.getIncrement() + idx;
        Group group = userMgr.createGroup(name);
        groups.add(group);
        int groupMembers = random.nextInt(users.size());
        for (int i = 0; i < groupMembers; i++) {
            group.addMember(users.get(random.nextInt(users.size())));
        }
    }
    session.save();
    // create the load for this iteration
    createLoad(context);
    long loadFinish = System.currentTimeMillis();
    context.getMap().put(CTX_ROOT_NODE_NAME_PROP, ROOT_NODE_NAME);
    context.getMap().put(CTX_USER, users);
    context.getMap().put(CTX_GROUP, groups);
    waitBeforeIterationFinish(loadFinish);
    if (LOG.isDebugEnabled()) {
        LOG.debug("Finished beforeIteration()");
    }
}
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) Session(javax.jcr.Session) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession)

Example 89 with JackrabbitSession

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

the class AccessControlImporterBaseTest method mockJackrabbitSession.

Session mockJackrabbitSession() throws Exception {
    JackrabbitSession s = Mockito.mock(JackrabbitSession.class);
    when(s.getPrincipalManager()).thenReturn(getPrincipalManager(root));
    when(s.getAccessControlManager()).thenReturn(getAccessControlManager(root));
    return s;
}
Also used : JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession)

Example 90 with JackrabbitSession

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

the class L7_ImpersonationTest method testAdvancedImpersonationTest.

public void testAdvancedImpersonationTest() throws RepositoryException {
    // EXERCISE: change the permission setup such that the test-user is allowed to make himself an impersonator of 'another' user.
    Session testSession = superuser.getRepository().login(ExerciseUtility.getTestCredentials(testUser.getID()));
    sessionList.add(testSession);
    UserManager uMgr = ((JackrabbitSession) testSession).getUserManager();
    User another = uMgr.getAuthorizable(anotherUser.getID(), User.class);
    assertNotNull(another);
    Principal princ = uMgr.getAuthorizable(testUser.getID()).getPrincipal();
    another.getImpersonation().grantImpersonation(princ);
    testSession.save();
    testSession.impersonate(new SimpleCredentials(anotherUser.getID(), new char[0])).logout();
    try {
        Session s = testSession.impersonate(new SimpleCredentials(anotherUser.getID(), new char[0]));
        sessionList.add(s);
        fail("Test user must no longer be able to edit the impersonation of the test user");
    } catch (LoginException e) {
    // success
    }
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) User(org.apache.jackrabbit.api.security.user.User) UserManager(org.apache.jackrabbit.api.security.user.UserManager) LoginException(javax.jcr.LoginException) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession) Principal(java.security.Principal) Session(javax.jcr.Session) 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