Search in sources :

Example 31 with PrincipalIterator

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

the class L3_EveryoneTest method testEveryoneIsMemberofEveryone.

public void testEveryoneIsMemberofEveryone() throws RepositoryException {
    java.security.acl.Group everyone = (java.security.acl.Group) principalManager.getEveryone();
    PrincipalIterator it = principalManager.getPrincipals(PrincipalManager.SEARCH_TYPE_ALL);
    // EXERCISE: discuss the dynamic nature of the everyone group principal
    while (it.hasNext()) {
        Principal principal = it.nextPrincipal();
        if (everyone.equals(principal)) {
            assertFalse(everyone.isMember(principal));
        } else {
            assertTrue(everyone.isMember(principal));
        }
    }
}
Also used : PrincipalIterator(org.apache.jackrabbit.api.security.principal.PrincipalIterator) Principal(java.security.Principal)

Example 32 with PrincipalIterator

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

the class L4_PrincipalProviderTest method testCorrespondance.

@Test
public void testCorrespondance() {
    boolean exists = principalManager.hasPrincipal(testPrincipalName);
    Principal principal = principalManager.getPrincipal(testPrincipalName);
    PrincipalIterator principalIterator = principalManager.findPrincipals(testPrincipalName, PrincipalManager.SEARCH_TYPE_ALL);
    PrincipalIterator groups = principalManager.getGroupMembership(principal);
    PrincipalIterator all = principalManager.getPrincipals(PrincipalManager.SEARCH_TYPE_ALL);
// EXERCISE: write the corresponding calls for the principal provider and verify the expected result
// EXERCISE: which methods have nor corresponding call in the other interface?
}
Also used : PrincipalIterator(org.apache.jackrabbit.api.security.principal.PrincipalIterator) Principal(java.security.Principal) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 33 with PrincipalIterator

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

the class L2_PrincipalManagerTest method testFindPrincipals.

public void testFindPrincipals() throws RepositoryException {
    // EXERCISE: play with the search hint
    String searchHint = testPrincipalName;
    // EXERCISE: modify the type flag
    int searchType = PrincipalManager.SEARCH_TYPE_ALL;
    PrincipalIterator principalIterator = principalManager.findPrincipals(testPrincipalName, searchType);
// EXERCISE: what is the expected query result depending on the search hint and the type-flag?
}
Also used : PrincipalIterator(org.apache.jackrabbit.api.security.principal.PrincipalIterator)

Example 34 with PrincipalIterator

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

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

the class ImpersonationImplTest method testGetImpersonators.

@Test
public void testGetImpersonators() throws Exception {
    PrincipalIterator it = impersonation.getImpersonators();
    assertTrue(it.hasNext());
    assertTrue(Iterators.contains(it, impersonator.getPrincipal()));
}
Also used : PrincipalIterator(org.apache.jackrabbit.api.security.principal.PrincipalIterator) Test(org.junit.Test)

Aggregations

PrincipalIterator (org.apache.jackrabbit.api.security.principal.PrincipalIterator)61 Principal (java.security.Principal)40 Test (org.junit.Test)35 EveryonePrincipal (org.apache.jackrabbit.oak.spi.security.principal.EveryonePrincipal)15 AbstractJCRTest (org.apache.jackrabbit.test.AbstractJCRTest)11 JackrabbitSession (org.apache.jackrabbit.api.JackrabbitSession)9 PrincipalManager (org.apache.jackrabbit.api.security.principal.PrincipalManager)9 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)9 ArrayList (java.util.ArrayList)8 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)7 Group (java.security.acl.Group)5 RepositoryException (javax.jcr.RepositoryException)4 Group (org.apache.jackrabbit.api.security.user.Group)4 TestPrincipal (org.apache.jackrabbit.core.security.TestPrincipal)4 EveryonePrincipal (org.apache.jackrabbit.core.security.principal.EveryonePrincipal)4 HashSet (java.util.HashSet)3 Impersonation (org.apache.jackrabbit.api.security.user.Impersonation)3 User (org.apache.jackrabbit.api.security.user.User)3 Session (javax.jcr.Session)2 Subject (javax.security.auth.Subject)2