Search in sources :

Example 11 with PrincipalManager

use of org.apache.jackrabbit.api.security.principal.PrincipalManager in project jackrabbit-oak by apache.

the class CompositePrincipalConfigurationTest method testSingleGetPrincipalManager.

@Test
public void testSingleGetPrincipalManager() {
    PrincipalConfiguration testConfig = new TestPrincipalConfiguration();
    addConfiguration(testConfig);
    PrincipalManager pMgr = getComposite().getPrincipalManager(root, NamePathMapper.DEFAULT);
    assertTrue(pMgr instanceof PrincipalManagerImpl);
}
Also used : PrincipalManager(org.apache.jackrabbit.api.security.principal.PrincipalManager) Test(org.junit.Test) AbstractCompositeConfigurationTest(org.apache.jackrabbit.oak.spi.security.AbstractCompositeConfigurationTest)

Example 12 with PrincipalManager

use of org.apache.jackrabbit.api.security.principal.PrincipalManager 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 13 with PrincipalManager

use of org.apache.jackrabbit.api.security.principal.PrincipalManager in project jackrabbit-oak by apache.

the class UserPrincipalProviderWithCacheTest method testPrincipalManagerGetGroupMembershipPopulatesCache.

@Test
public void testPrincipalManagerGetGroupMembershipPopulatesCache() throws Exception {
    PrincipalManager principalManager = getPrincipalManager(systemRoot);
    PrincipalIterator principalIterator = principalManager.getGroupMembership(getTestUser().getPrincipal());
    assertPrincipals(ImmutableSet.copyOf(principalIterator), EveryonePrincipal.getInstance(), testGroup.getPrincipal());
    root.refresh();
    Tree principalCache = getCacheTree(root);
    assertTrue(principalCache.exists());
    assertEquals(CacheConstants.NT_REP_CACHE, TreeUtil.getPrimaryTypeName(principalCache));
    assertNotNull(principalCache.getProperty(CacheConstants.REP_EXPIRATION));
    PropertyState ps = principalCache.getProperty(CacheConstants.REP_GROUP_PRINCIPAL_NAMES);
    assertNotNull(ps);
    String val = ps.getValue(Type.STRING);
    assertEquals(testGroup.getPrincipal().getName(), val);
}
Also used : PrincipalManager(org.apache.jackrabbit.api.security.principal.PrincipalManager) PrincipalIterator(org.apache.jackrabbit.api.security.principal.PrincipalIterator) Tree(org.apache.jackrabbit.oak.api.Tree) PropertyState(org.apache.jackrabbit.oak.api.PropertyState) AbstractPrincipalProviderTest(org.apache.jackrabbit.oak.security.principal.AbstractPrincipalProviderTest) Test(org.junit.Test)

Example 14 with PrincipalManager

use of org.apache.jackrabbit.api.security.principal.PrincipalManager in project jackrabbit-oak by apache.

the class L13_SystemUserTest method testSystemUserPrincipal.

@Test
public void testSystemUserPrincipal() throws RepositoryException {
    Authorizable authorizable = getUserManager(root).getAuthorizable(systemUser.getID());
    // EXERCISE: what is the nature of the principal of the system user? Assert your expectedation.
    Principal principal = authorizable.getPrincipal();
    PrincipalManager principalManager = getPrincipalManager(root);
    PrincipalIterator pIter = principalManager.getGroupMembership(principal);
    // EXERCISE
    int expectedSize = -1;
    assertEquals(expectedSize, pIter.getSize());
    // EXERCISE
    List<Principal> expectedGroupPrincipals = null;
    while (pIter.hasNext()) {
        Principal group = pIter.nextPrincipal();
        assertTrue(expectedGroupPrincipals.remove(group));
    }
    assertTrue(expectedGroupPrincipals.isEmpty());
}
Also used : PrincipalManager(org.apache.jackrabbit.api.security.principal.PrincipalManager) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) PrincipalIterator(org.apache.jackrabbit.api.security.principal.PrincipalIterator) Principal(java.security.Principal) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) L3_PrecedenceRulesTest(org.apache.jackrabbit.oak.exercise.security.authorization.permission.L3_PrecedenceRulesTest) Test(org.junit.Test)

Example 15 with PrincipalManager

use of org.apache.jackrabbit.api.security.principal.PrincipalManager in project jackrabbit-oak by apache.

the class CompositePrincipalConfigurationTest method testEmptyGetPrincipalManager.

@Test
public void testEmptyGetPrincipalManager() {
    PrincipalManager pMgr = getComposite().getPrincipalManager(root, NamePathMapper.DEFAULT);
    assertTrue(pMgr instanceof PrincipalManagerImpl);
}
Also used : PrincipalManager(org.apache.jackrabbit.api.security.principal.PrincipalManager) Test(org.junit.Test) AbstractCompositeConfigurationTest(org.apache.jackrabbit.oak.spi.security.AbstractCompositeConfigurationTest)

Aggregations

PrincipalManager (org.apache.jackrabbit.api.security.principal.PrincipalManager)27 Principal (java.security.Principal)16 Test (org.junit.Test)11 JackrabbitSession (org.apache.jackrabbit.api.JackrabbitSession)9 PrincipalIterator (org.apache.jackrabbit.api.security.principal.PrincipalIterator)9 HashSet (java.util.HashSet)6 RepositoryException (javax.jcr.RepositoryException)6 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)6 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)4 Session (javax.jcr.Session)3 AccessControlPolicy (javax.jcr.security.AccessControlPolicy)3 JackrabbitAccessControlManager (org.apache.jackrabbit.api.security.JackrabbitAccessControlManager)3 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)3 Group (org.apache.jackrabbit.api.security.user.Group)3 NodeImpl (org.apache.jackrabbit.core.NodeImpl)3 PrincipalImpl (org.apache.jackrabbit.core.security.principal.PrincipalImpl)3 AbstractCompositeConfigurationTest (org.apache.jackrabbit.oak.spi.security.AbstractCompositeConfigurationTest)3 EveryonePrincipal (org.apache.jackrabbit.oak.spi.security.principal.EveryonePrincipal)3 Group (java.security.acl.Group)2 ArrayList (java.util.ArrayList)2