Search in sources :

Example 51 with JackrabbitSession

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

the class AbstractRandomizedTest method setupAuthorizables.

protected void setupAuthorizables() throws RepositoryException {
    for (JackrabbitSession s : writeSessions) {
        UserManager userManager = s.getUserManager();
        User user = userManager.createUser(userId, userId);
        Group group = userManager.createGroup("group1");
        group.addMember(user);
        Group group2 = userManager.createGroup("group2");
        group2.addMember(user);
        s.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 52 with JackrabbitSession

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

the class OakOSGiRepositoryFactoryTest method testCallback.

private void testCallback(Repository repository) throws RepositoryException {
    JackrabbitSession session = (JackrabbitSession) repository.login(new SimpleCredentials("admin", "admin".toCharArray()));
    String testUserId = "footest";
    User testUser = (User) session.getUserManager().getAuthorizable(testUserId);
    if (testUser == null) {
        testUser = session.getUserManager().createUser(testUserId, "password");
    }
    session.save();
    testUser.changePassword("newPassword");
    session.save();
    assertEquals("newPassword", newPassword);
    session.logout();
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) User(org.apache.jackrabbit.api.security.user.User) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession)

Example 53 with JackrabbitSession

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

the class L4_EffectivePoliciesTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    Node child = testRootNode.addNode(nodeName1);
    childPath = child.getPath();
    testUser = ExerciseUtility.createTestUser(((JackrabbitSession) superuser).getUserManager());
    testPrincipal = testUser.getPrincipal();
    superuser.save();
    acMgr = (JackrabbitAccessControlManager) superuser.getAccessControlManager();
    acl = AccessControlUtils.getAccessControlList(superuser, testRoot);
    if (acl == null) {
        throw new NotExecutableException();
    }
    testPrivileges = AccessControlUtils.privilegesFromNames(acMgr, Privilege.JCR_READ, Privilege.JCR_WRITE);
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) Node(javax.jcr.Node) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession)

Example 54 with JackrabbitSession

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

the class TcclWrappingJackrabbitRepository method login.

@Override
public Session login(Credentials credentials, String workspaceName, Map<String, Object> attributes) throws LoginException, NoSuchWorkspaceException, RepositoryException {
    Thread thread = Thread.currentThread();
    ClassLoader oldClassLoader = thread.getContextClassLoader();
    thread.setContextClassLoader(Oak.class.getClassLoader());
    try {
        Session session = wrapped.login(credentials, workspaceName, attributes);
        return new TcclWrappingJackrabbitSession((JackrabbitSession) session);
    } finally {
        thread.setContextClassLoader(oldClassLoader);
    }
}
Also used : Oak(org.apache.jackrabbit.oak.Oak) Session(javax.jcr.Session) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession)

Example 55 with JackrabbitSession

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

the class TcclWrappingJackrabbitSession method impersonate.

// calls setting the TCCL
@Override
public Session impersonate(Credentials credentials) throws LoginException, RepositoryException {
    Thread thread = Thread.currentThread();
    ClassLoader oldClassLoader = thread.getContextClassLoader();
    thread.setContextClassLoader(Oak.class.getClassLoader());
    try {
        Session session = wrapped.impersonate(credentials);
        return new TcclWrappingJackrabbitSession((JackrabbitSession) session);
    } finally {
        thread.setContextClassLoader(oldClassLoader);
    }
}
Also used : Oak(org.apache.jackrabbit.oak.Oak) 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