Search in sources :

Example 6 with JackrabbitSession

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

the class GetPrincipalTest method runTest.

@Override
protected void runTest() throws Exception {
    Session s = loginWriter();
    PrincipalManager principalManager = ((JackrabbitSession) s).getPrincipalManager();
    for (int i = 0; i < 1000; i++) {
        Principal p = principalManager.getPrincipal(getUserId());
    }
}
Also used : PrincipalManager(org.apache.jackrabbit.api.security.principal.PrincipalManager) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession) Principal(java.security.Principal) Session(javax.jcr.Session) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession)

Example 7 with JackrabbitSession

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

the class RemoveMembersTest 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);
        removeMembers(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 8 with JackrabbitSession

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

the class RemoveMembersTest 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();
        }
        // remove test-users if they have been created
        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 9 with JackrabbitSession

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

the class NestedGroupTest method testInheritedMembership.

public void testInheritedMembership() throws NotExecutableException, RepositoryException {
    Group gr1 = null;
    Group gr2 = null;
    Group gr3 = null;
    if (!(superuser instanceof JackrabbitSession)) {
        throw new NotExecutableException();
    }
    try {
        gr1 = createGroup(getTestPrincipal());
        gr2 = createGroup(getTestPrincipal());
        gr3 = createGroup(getTestPrincipal());
        assertTrue(addMember(gr1, gr2));
        assertTrue(addMember(gr2, gr3));
        // NOTE: don't test with Group.isMember for not required to detect
        // inherited membership -> rather with PrincipalManager.
        boolean isMember = false;
        PrincipalManager pmgr = ((JackrabbitSession) superuser).getPrincipalManager();
        for (PrincipalIterator it = pmgr.getGroupMembership(gr3.getPrincipal()); it.hasNext() && !isMember; ) {
            isMember = it.nextPrincipal().equals(gr1.getPrincipal());
        }
        assertTrue(isMember);
    } finally {
        if (gr1 != null && gr1.isMember(gr2)) {
            removeMember(gr1, gr2);
        }
        if (gr2 != null && gr2.isMember(gr3)) {
            removeMember(gr2, gr3);
        }
        if (gr1 != null)
            removeGroup(gr1);
        if (gr2 != null)
            removeGroup(gr2);
        if (gr3 != null)
            removeGroup(gr3);
    }
}
Also used : PrincipalManager(org.apache.jackrabbit.api.security.principal.PrincipalManager) NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) PrincipalIterator(org.apache.jackrabbit.api.security.principal.PrincipalIterator) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession)

Example 10 with JackrabbitSession

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

the class SessionImplTest method testSessionHasPermission.

/**
     * @see <a href="https://issues.apache.org/jira/browse/JCR-3885">JCR-3885</a>
     */
public void testSessionHasPermission() throws Exception {
    JackrabbitSession js = (JackrabbitSession) superuser;
    assertEquals(superuser.hasPermission("/", Session.ACTION_READ), js.hasPermission("/", new String[] { Session.ACTION_READ }));
    assertEquals(superuser.hasPermission("/", Session.ACTION_READ + "," + Session.ACTION_ADD_NODE), js.hasPermission("/", Session.ACTION_READ, Session.ACTION_ADD_NODE));
    try {
        js.hasPermission("/", new String[0]);
        fail();
    } catch (IllegalArgumentException e) {
    // success
    }
    try {
        js.hasPermission("/", new String[] { "" });
        fail();
    } catch (IllegalArgumentException e) {
    // success
    }
    // note: that's a bit unexpected
    assertEquals(superuser.hasPermission("/", ",,"), js.hasPermission("/", "", "", ""));
}
Also used : 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