use of org.apache.jackrabbit.api.security.principal.PrincipalIterator in project jackrabbit by apache.
the class DefaultPrincipalProviderTest method testUnknownUserMemberShip.
// TODO: add tests for 'findPrincipals'
public void testUnknownUserMemberShip() throws RepositoryException {
Principal userPrincipal = getTestPrincipal();
PrincipalIterator pit = principalProvider.getGroupMembership(userPrincipal);
// unknown user must be in 'everyone' group but nothing else
assertTrue(pit.hasNext());
assertEquals(EveryonePrincipal.getInstance(), pit.nextPrincipal());
assertFalse(pit.hasNext());
}
use of org.apache.jackrabbit.api.security.principal.PrincipalIterator in project jackrabbit by apache.
the class DefaultPrincipalProviderTest method testEveryonePrincipal2.
public void testEveryonePrincipal2() throws Exception {
Group g = null;
try {
g = userMgr.createGroup(EveryonePrincipal.NAME);
save(superuser);
Principal p = principalProvider.getPrincipal(EveryonePrincipal.NAME);
assertNotNull(p);
assertEquals(EveryonePrincipal.getInstance(), p);
PrincipalIterator pit = principalProvider.findPrincipals(EveryonePrincipal.NAME);
assertNotNull(pit);
if (pit.getSize() == -1) {
assertTrue(pit.hasNext());
assertEquals(EveryonePrincipal.getInstance(), pit.nextPrincipal());
assertFalse(pit.hasNext());
} else {
assertEquals(1, pit.getSize());
assertEquals(EveryonePrincipal.getInstance(), pit.nextPrincipal());
}
} finally {
if (g != null) {
g.remove();
save(superuser);
}
}
}
use of org.apache.jackrabbit.api.security.principal.PrincipalIterator in project jackrabbit by apache.
the class DefaultPrincipalProviderTest method testEveryonePrincipal.
public void testEveryonePrincipal() throws Exception {
Principal p = principalProvider.getPrincipal(EveryonePrincipal.NAME);
assertNotNull(p);
assertEquals(EveryonePrincipal.getInstance(), p);
PrincipalIterator pit = principalProvider.findPrincipals(EveryonePrincipal.NAME);
assertNotNull(pit);
if (pit.getSize() == -1) {
assertTrue(pit.hasNext());
assertEquals(EveryonePrincipal.getInstance(), pit.nextPrincipal());
assertFalse(pit.hasNext());
} else {
assertEquals(1, pit.getSize());
assertEquals(EveryonePrincipal.getInstance(), pit.nextPrincipal());
}
}
use of org.apache.jackrabbit.api.security.principal.PrincipalIterator in project jackrabbit by apache.
the class NestedGroupTest method testInheritedMembership.
public void testInheritedMembership() throws NotExecutableException, RepositoryException {
Group gr1 = null;
Group gr2 = null;
Group gr3 = null;
if (!(superuser instanceof JackrabbitSession)) {
throw new NotExecutableException();
}
try {
gr1 = createGroup(getTestPrincipal());
gr2 = createGroup(getTestPrincipal());
gr3 = createGroup(getTestPrincipal());
assertTrue(addMember(gr1, gr2));
assertTrue(addMember(gr2, gr3));
// NOTE: don't test with Group.isMember for not required to detect
// inherited membership -> rather with PrincipalManager.
boolean isMember = false;
PrincipalManager pmgr = ((JackrabbitSession) superuser).getPrincipalManager();
for (PrincipalIterator it = pmgr.getGroupMembership(gr3.getPrincipal()); it.hasNext() && !isMember; ) {
isMember = it.nextPrincipal().equals(gr1.getPrincipal());
}
assertTrue(isMember);
} finally {
if (gr1 != null && gr1.isMember(gr2)) {
removeMember(gr1, gr2);
}
if (gr2 != null && gr2.isMember(gr3)) {
removeMember(gr2, gr3);
}
if (gr1 != null)
removeGroup(gr1);
if (gr2 != null)
removeGroup(gr2);
if (gr3 != null)
removeGroup(gr3);
}
}
use of org.apache.jackrabbit.api.security.principal.PrincipalIterator in project jackrabbit by apache.
the class AbstractACLTemplateTest method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
if (!(superuser instanceof JackrabbitSession)) {
throw new NotExecutableException();
}
principalMgr = ((JackrabbitSession) superuser).getPrincipalManager();
PrincipalIterator it = principalMgr.getPrincipals(PrincipalManager.SEARCH_TYPE_NOT_GROUP);
if (it.hasNext()) {
testPrincipal = it.nextPrincipal();
} else {
throw new NotExecutableException();
}
privilegeMgr = (PrivilegeManagerImpl) ((JackrabbitWorkspace) superuser.getWorkspace()).getPrivilegeManager();
}
Aggregations