use of org.apache.jackrabbit.api.security.principal.PrincipalIterator in project jackrabbit-oak by apache.
the class PrincipalManagerTest method testMembership.
private void testMembership(int searchType) {
PrincipalIterator it = principalMgr.getPrincipals(searchType);
while (it.hasNext()) {
Principal p = it.nextPrincipal();
if (p.equals(everyone)) {
continue;
}
boolean atleastEveryone = false;
for (PrincipalIterator membership = principalMgr.getGroupMembership(p); membership.hasNext(); ) {
Principal gr = membership.nextPrincipal();
assertTrue(isGroup(gr));
if (gr.equals(everyone)) {
atleastEveryone = true;
}
}
assertTrue("All principals (except everyone) must be member of the everyone group.", atleastEveryone);
}
}
use of org.apache.jackrabbit.api.security.principal.PrincipalIterator in project jackrabbit-oak by apache.
the class PrincipalManagerTest method testGetPrincipals.
@Test
public void testGetPrincipals() {
PrincipalIterator it = principalMgr.getPrincipals(PrincipalManager.SEARCH_TYPE_NOT_GROUP);
while (it.hasNext()) {
Principal p = it.nextPrincipal();
assertFalse(isGroup(p));
}
}
use of org.apache.jackrabbit.api.security.principal.PrincipalIterator in project jackrabbit-oak by apache.
the class PrincipalManagerTest method testFindPrincipalByType.
@Test
public void testFindPrincipalByType() {
for (Principal pcpl : adminPrincipals) {
if (pcpl.equals(everyone)) {
// special case covered by another test
continue;
}
assertTrue(principalMgr.hasPrincipal(pcpl.getName()));
if (isGroup(pcpl)) {
PrincipalIterator it = principalMgr.findPrincipals(pcpl.getName(), PrincipalManager.SEARCH_TYPE_GROUP);
// search must find at least a single matching group principal
assertTrue("findPrincipals does not find principal with filter " + pcpl.getName(), it.hasNext());
} else {
PrincipalIterator it = principalMgr.findPrincipals(pcpl.getName(), PrincipalManager.SEARCH_TYPE_NOT_GROUP);
// search must find at least a single matching non-group principal
assertTrue("findPrincipals does not find principal with filter '" + pcpl.getName() + "' and type " + PrincipalManager.SEARCH_TYPE_NOT_GROUP, it.hasNext());
}
}
}
use of org.apache.jackrabbit.api.security.principal.PrincipalIterator in project jackrabbit-oak by apache.
the class PrincipalManagerTest method testFindPrincipalByTypeAll.
@Test
public void testFindPrincipalByTypeAll() {
for (Principal pcpl : adminPrincipals) {
if (pcpl.equals(everyone)) {
// special case covered by another test
continue;
}
assertTrue(principalMgr.hasPrincipal(pcpl.getName()));
PrincipalIterator it = principalMgr.findPrincipals(pcpl.getName(), PrincipalManager.SEARCH_TYPE_ALL);
PrincipalIterator it2 = principalMgr.findPrincipals(pcpl.getName());
assertTrue("Principal " + pcpl.getName() + " not found", it.hasNext());
assertTrue("Principal " + pcpl.getName() + " not found", it2.hasNext());
// both search must reveal the same result and size
assertTrue(it.getSize() == it2.getSize());
Set<Principal> s1 = new HashSet<Principal>();
Set<Principal> s2 = new HashSet<Principal>();
while (it.hasNext() && it2.hasNext()) {
s1.add(it.nextPrincipal());
s2.add(it2.nextPrincipal());
}
assertEquals(s1, s2);
assertFalse(it.hasNext() && it2.hasNext());
}
}
use of org.apache.jackrabbit.api.security.principal.PrincipalIterator in project jackrabbit-oak by apache.
the class PrincipalManagerTest method getPrincipals.
private Principal[] getPrincipals(Credentials credentials) throws Exception {
Set<Principal> principals = new HashSet<Principal>();
if (credentials instanceof SimpleCredentials) {
Principal p = principalMgr.getPrincipal(((SimpleCredentials) credentials).getUserID());
if (p != null) {
principals.add(p);
PrincipalIterator principalIterator = principalMgr.getGroupMembership(p);
while (principalIterator.hasNext()) {
principals.add(principalIterator.nextPrincipal());
}
}
}
return principals.toArray(new Principal[principals.size()]);
}
Aggregations