Search in sources :

Example 36 with JackrabbitSession

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

the class FindAuthorizablesTest method testFindAuthorizable.

@Test
public void testFindAuthorizable() throws RepositoryException, NotExecutableException {
    Set<Principal> principals = new HashSet<Principal>();
    PrincipalManager pMgr = ((JackrabbitSession) superuser).getPrincipalManager();
    Principal p = pMgr.getPrincipal(superuser.getUserID());
    if (p != null) {
        principals.add(p);
        PrincipalIterator principalIterator = pMgr.getGroupMembership(p);
        while (principalIterator.hasNext()) {
            principals.add(principalIterator.nextPrincipal());
        }
    }
    Authorizable auth;
    for (Principal principal : principals) {
        auth = userMgr.getAuthorizable(principal);
        if (auth != null) {
            if (!auth.isGroup() && auth.hasProperty(UserConstants.REP_PRINCIPAL_NAME)) {
                String val = auth.getProperty(UserConstants.REP_PRINCIPAL_NAME)[0].getString();
                Iterator<Authorizable> users = userMgr.findAuthorizables(UserConstants.REP_PRINCIPAL_NAME, val);
                // the result must contain 1 authorizable
                assertTrue(users.hasNext());
                Authorizable first = users.next();
                assertEquals(first.getID(), val);
                // since id is unique -> there should be no more users in
                // the iterator left
                assertFalse(users.hasNext());
            }
        }
    }
}
Also used : PrincipalManager(org.apache.jackrabbit.api.security.principal.PrincipalManager) PrincipalIterator(org.apache.jackrabbit.api.security.principal.PrincipalIterator) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession) Principal(java.security.Principal) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 37 with JackrabbitSession

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

the class PrincipalManagerTest method testMembers2.

@Test
public void testMembers2() throws Exception {
    Authorizable gr = null;
    try {
        gr = ((JackrabbitSession) superuser).getUserManager().createGroup(getClass().getName());
        superuser.save();
        PrincipalIterator it = principalMgr.getPrincipals(PrincipalManager.SEARCH_TYPE_ALL);
        while (it.hasNext()) {
            Principal p = it.nextPrincipal();
            if (p.equals(principalMgr.getEveryone())) {
                continue;
            }
            if (isGroup(p)) {
                Enumeration<? extends Principal> en = ((java.security.acl.Group) p).members();
                while (en.hasMoreElements()) {
                    Principal memb = en.nextElement();
                    assertTrue(principalMgr.hasPrincipal(memb.getName()));
                }
            }
        }
    } finally {
        if (gr != null) {
            gr.remove();
            superuser.save();
        }
    }
}
Also used : Group(java.security.acl.Group) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) PrincipalIterator(org.apache.jackrabbit.api.security.principal.PrincipalIterator) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession) Principal(java.security.Principal) EveryonePrincipal(org.apache.jackrabbit.oak.spi.security.principal.EveryonePrincipal) Test(org.junit.Test) AbstractJCRTest(org.apache.jackrabbit.test.AbstractJCRTest)

Example 38 with JackrabbitSession

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

the class UserImporterBaseTest method mockJackrabbitSession.

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

Example 39 with JackrabbitSession

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

the class L3_PrecedenceRulesTest method tearDown.

@Override
protected void tearDown() throws Exception {
    try {
        if (testSession != null && testSession.isLive()) {
            testSession.logout();
        }
        UserManager uMgr = ((JackrabbitSession) superuser).getUserManager();
        Authorizable testUser = uMgr.getAuthorizable(testPrincipal);
        if (testUser != null) {
            testUser.remove();
        }
        Authorizable testGroup = uMgr.getAuthorizable(testGroupPrincipal);
        if (testGroup != null) {
            testGroup.remove();
        }
        superuser.save();
    } finally {
        super.tearDown();
    }
}
Also used : UserManager(org.apache.jackrabbit.api.security.user.UserManager) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession)

Example 40 with JackrabbitSession

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

the class L5_SpecialPermissionsTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    Property p = testRootNode.setProperty(propertyName1, "val");
    propertyPath = p.getPath();
    Node child = testRootNode.addNode(nodeName1);
    childPath = child.getPath();
    p = child.setProperty(propertyName2, "val");
    childPropertyPath = p.getPath();
    Node grandChild = child.addNode(nodeName2);
    grandChildPath = grandChild.getPath();
    testUser = ExerciseUtility.createTestUser(((JackrabbitSession) superuser).getUserManager());
    testUser2 = ExerciseUtility.createTestUser(((JackrabbitSession) superuser).getUserManager());
    Group testGroup = ExerciseUtility.createTestGroup(((JackrabbitSession) superuser).getUserManager());
    testGroup.addMember(testUser);
    superuser.save();
    testPrincipal = testUser.getPrincipal();
    testGroupPrincipal = testGroup.getPrincipal();
}
Also used : Group(org.apache.jackrabbit.api.security.user.Group) Node(javax.jcr.Node) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession) Property(javax.jcr.Property)

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