Search in sources :

Example 46 with PrincipalIterator

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

the class PrincipalManagerImplTest method testGetPrincipalsNonGroupContainsNoGroups.

@Test
public void testGetPrincipalsNonGroupContainsNoGroups() {
    PrincipalIterator it = principalMgr.getPrincipals(PrincipalManager.SEARCH_TYPE_NOT_GROUP);
    while (it.hasNext()) {
        Principal p = it.nextPrincipal();
        assertFalse(isGroup(p));
    }
}
Also used : PrincipalIterator(org.apache.jackrabbit.api.security.principal.PrincipalIterator) Principal(java.security.Principal) Test(org.junit.Test)

Example 47 with PrincipalIterator

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

the class PrincipalManagerImplTest method testFindEveryoneTypeNonGroup.

@Test
public void testFindEveryoneTypeNonGroup() {
    // search non-group only -> everyone should not be part of the result set
    PrincipalIterator it = principalMgr.findPrincipals(EveryonePrincipal.NAME, PrincipalManager.SEARCH_TYPE_NOT_GROUP);
    assertFalse("findPrincipals did find principal with filter '" + EveryonePrincipal.NAME + '\'', Iterators.contains(it, EveryonePrincipal.getInstance()));
}
Also used : PrincipalIterator(org.apache.jackrabbit.api.security.principal.PrincipalIterator) Test(org.junit.Test)

Example 48 with PrincipalIterator

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

the class L2_PrincipalManagerTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    principalManager = ((JackrabbitSession) superuser).getPrincipalManager();
    // NOTE: this method call doesn't make to much sense outside of a
    // simple test with a very limited number of principals (!!)
    PrincipalIterator principalIterator = principalManager.getPrincipals(PrincipalManager.SEARCH_TYPE_NOT_GROUP);
    if (principalIterator.hasNext()) {
        testPrincipalName = principalIterator.nextPrincipal().getName();
    }
    if (testPrincipalName == null) {
        throw new NotExecutableException();
    }
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) PrincipalIterator(org.apache.jackrabbit.api.security.principal.PrincipalIterator)

Example 49 with PrincipalIterator

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

the class L4_PrincipalProviderTest method before.

@Override
public void before() throws Exception {
    super.before();
    principalProvider = getConfig(PrincipalConfiguration.class).getPrincipalProvider(root, NamePathMapper.DEFAULT);
    principalManager = getConfig(PrincipalConfiguration.class).getPrincipalManager(root, NamePathMapper.DEFAULT);
    // NOTE: this method call doesn't make to much sense outside of a
    // simple test with a very limited number of principals (!!)
    PrincipalIterator principalIterator = principalManager.getPrincipals(PrincipalManager.SEARCH_TYPE_NOT_GROUP);
    if (principalIterator.hasNext()) {
        testPrincipalName = principalIterator.nextPrincipal().getName();
    }
    if (testPrincipalName == null) {
        throw new NotExecutableException();
    }
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) PrincipalIterator(org.apache.jackrabbit.api.security.principal.PrincipalIterator)

Example 50 with PrincipalIterator

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

the class PrincipalManagerTest method testFindEveryone.

@Test
public void testFindEveryone() {
    Principal everyone = principalMgr.getEveryone();
    assertTrue(principalMgr.hasPrincipal(everyone.getName()));
    boolean containedInResult = false;
    // untyped search -> everyone must be part of the result set
    PrincipalIterator it = principalMgr.findPrincipals(everyone.getName());
    while (it.hasNext()) {
        Principal p = it.nextPrincipal();
        if (p.getName().equals(everyone.getName())) {
            containedInResult = true;
        }
    }
    assertTrue(containedInResult);
    // search group only -> everyone must be part of the result set
    containedInResult = false;
    it = principalMgr.findPrincipals(everyone.getName(), PrincipalManager.SEARCH_TYPE_GROUP);
    while (it.hasNext()) {
        Principal p = it.nextPrincipal();
        if (p.getName().equals(everyone.getName())) {
            containedInResult = true;
        }
    }
    assertTrue(containedInResult);
    // search non-group only -> everyone should not be part of the result set
    containedInResult = false;
    it = principalMgr.findPrincipals(everyone.getName(), PrincipalManager.SEARCH_TYPE_NOT_GROUP);
    while (it.hasNext()) {
        Principal p = it.nextPrincipal();
        if (p.getName().equals(everyone.getName())) {
            containedInResult = true;
        }
    }
    assertFalse(containedInResult);
}
Also used : PrincipalIterator(org.apache.jackrabbit.api.security.principal.PrincipalIterator) Principal(java.security.Principal) EveryonePrincipal(org.apache.jackrabbit.oak.spi.security.principal.EveryonePrincipal) Test(org.junit.Test) AbstractJCRTest(org.apache.jackrabbit.test.AbstractJCRTest)

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