use of org.apache.jackrabbit.api.security.principal.GroupPrincipal in project jackrabbit-oak by apache.
the class AbstractPrincipalProviderTest method testGroupPrincipal.
@Test
public void testGroupPrincipal() throws Exception {
Principal principal = principalProvider.getPrincipal(testGroup.getPrincipal().getName());
assertNotNull(principal);
assertTrue(principal instanceof GroupPrincipal);
}
use of org.apache.jackrabbit.api.security.principal.GroupPrincipal in project jackrabbit-oak by apache.
the class PrincipalProviderImplTest method testEveryoneMembers.
@Test
public void testEveryoneMembers() throws Exception {
Principal everyone = principalProvider.getPrincipal(EveryonePrincipal.NAME);
assertTrue(everyone instanceof EveryonePrincipal);
Group everyoneGroup = null;
try {
UserManager userMgr = getUserManager(root);
everyoneGroup = userMgr.createGroup(EveryonePrincipal.NAME);
root.commit();
Principal ep = principalProvider.getPrincipal(EveryonePrincipal.NAME);
Set<? extends Principal> everyoneMembers = ImmutableSet.copyOf(Collections.list(((GroupPrincipal) ep).members()));
Iterator<? extends Principal> all = principalProvider.findPrincipals(PrincipalManager.SEARCH_TYPE_ALL);
while (all.hasNext()) {
Principal p = all.next();
if (everyone.equals(p)) {
assertFalse(everyoneMembers.contains(p));
} else {
assertTrue(everyoneMembers.contains(p));
}
}
} finally {
if (everyoneGroup != null) {
everyoneGroup.remove();
root.commit();
}
}
}
use of org.apache.jackrabbit.api.security.principal.GroupPrincipal in project jackrabbit-oak by apache.
the class UserPrincipalProviderTest method testGroupMembers.
@Test
public void testGroupMembers() throws Exception {
Group group = getUserManager(root).createGroup("testGroup" + UUID.randomUUID());
group.addMember(getTestUser());
root.commit();
try {
Principal principal = principalProvider.getPrincipal(group.getPrincipal().getName());
assertTrue(principal instanceof GroupPrincipal);
boolean found = false;
Enumeration<? extends Principal> members = ((GroupPrincipal) principal).members();
while (members.hasMoreElements() && !found) {
found = members.nextElement().equals(getTestUser().getPrincipal());
}
assertTrue(found);
} finally {
group.remove();
root.commit();
}
}
use of org.apache.jackrabbit.api.security.principal.GroupPrincipal in project jackrabbit-oak by apache.
the class UserPrincipalProviderWithCacheTest method testGroupPrincipalNameEscape.
@Test
public void testGroupPrincipalNameEscape() throws Exception {
String gId = null;
try {
Principal groupPrincipal = new PrincipalImpl(groupId + ",,%,%%");
Group gr = getUserManager(root).createGroup(groupPrincipal);
gId = gr.getID();
gr.addMember(getTestUser());
root.commit();
systemRoot.refresh();
PrincipalProvider pp = createPrincipalProvider(systemRoot);
Set<? extends Principal> principals = pp.getPrincipals(userId);
assertTrue(principals.contains(groupPrincipal));
principals = pp.getPrincipals(userId);
assertTrue(principals.contains(groupPrincipal));
} finally {
root.refresh();
if (gId != null) {
getUserManager(root).getAuthorizable(gId).remove();
root.commit();
}
}
}
use of org.apache.jackrabbit.api.security.principal.GroupPrincipal in project jackrabbit-oak by apache.
the class PrincipalManagerTest method testMembers2.
@Test
public void testMembers2() throws Exception {
Authorizable gr = null;
try {
gr = ((JackrabbitSession) superuser).getUserManager().createGroup(getClass().getName());
superuser.save();
PrincipalIterator it = principalMgr.getPrincipals(PrincipalManager.SEARCH_TYPE_ALL);
while (it.hasNext()) {
Principal p = it.nextPrincipal();
if (p.equals(principalMgr.getEveryone())) {
continue;
}
if (isGroup(p)) {
Enumeration<? extends Principal> en = ((GroupPrincipal) p).members();
while (en.hasMoreElements()) {
Principal memb = en.nextElement();
assertTrue(principalMgr.hasPrincipal(memb.getName()));
}
}
}
} finally {
if (gr != null) {
gr.remove();
superuser.save();
}
}
}
Aggregations