use of org.apache.jackrabbit.api.security.principal.GroupPrincipal in project jackrabbit-oak by apache.
the class PrincipalProviderDeepNestingTest method testGetPrincipalInheritedGroups.
@Override
@Test
public void testGetPrincipalInheritedGroups() throws Exception {
ExternalUser externalUser = idp.getUser(USER_ID);
for (ExternalIdentityRef ref : externalUser.getDeclaredGroups()) {
ExternalIdentity externalGroup = idp.getIdentity(ref);
Principal grPrincipal = principalProvider.getPrincipal(externalGroup.getPrincipalName());
for (ExternalIdentityRef inheritedGroupRef : externalGroup.getDeclaredGroups()) {
String inheritedPrincName = idp.getIdentity(inheritedGroupRef).getPrincipalName();
Principal principal = principalProvider.getPrincipal(inheritedPrincName);
assertNotNull(principal);
assertTrue(principal instanceof GroupPrincipal);
GroupPrincipal inheritedGrPrincipal = (GroupPrincipal) principal;
assertTrue(inheritedGrPrincipal.isMember(new PrincipalImpl(externalUser.getPrincipalName())));
assertFalse(inheritedGrPrincipal.isMember(grPrincipal));
}
}
}
use of org.apache.jackrabbit.api.security.principal.GroupPrincipal in project jackrabbit-oak by apache.
the class UserPrincipalProviderTest 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);
assertTrue(ep instanceof GroupPrincipal);
// ((GroupPrincipal) ep).members();
// assertTrue(((GroupPrincipal) ep).isMember(getTestUser().getPrincipal()));
} 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 testGroupIsMember.
@Test
public void testGroupIsMember() 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);
assertTrue(((GroupPrincipal) principal).isMember(getTestUser().getPrincipal()));
} finally {
group.remove();
root.commit();
}
}
use of org.apache.jackrabbit.api.security.principal.GroupPrincipal in project jackrabbit-oak by apache.
the class UserPrincipalProviderWithCacheTest method testGroupPrincipals.
@Test
public void testGroupPrincipals() throws Exception {
// a) force the cache to be created
PrincipalProvider pp = createPrincipalProvider(systemRoot);
Iterable<? extends Principal> principals = Iterables.filter(pp.getPrincipals(userId), new GroupPredicate());
for (Principal p : principals) {
String className = p.getClass().getName();
assertEquals("org.apache.jackrabbit.oak.security.user.UserPrincipalProvider$GroupPrincipalImpl", className);
}
Principal testPrincipal = getTestUser().getPrincipal();
// b) retrieve principals again (this time from the cache)
// -> verify that they are a different implementation
Iterable<? extends Principal> principalsAgain = Iterables.filter(pp.getPrincipals(userId), new GroupPredicate());
for (Principal p : principalsAgain) {
String className = p.getClass().getName();
assertEquals("org.apache.jackrabbit.oak.security.user.UserPrincipalProvider$CachedGroupPrincipal", className);
assertTrue(p instanceof TreeBasedPrincipal);
assertEquals(testGroup.getPath(), ((TreeBasedPrincipal) p).getPath());
GroupPrincipal principalGroup = (GroupPrincipal) p;
assertTrue(principalGroup.isMember(testPrincipal));
Enumeration<? extends Principal> members = principalGroup.members();
assertTrue(members.hasMoreElements());
assertEquals(testPrincipal, members.nextElement());
assertEquals(testGroup2.getPrincipal(), members.nextElement());
assertFalse(members.hasMoreElements());
}
}
use of org.apache.jackrabbit.api.security.principal.GroupPrincipal in project jackrabbit-oak by apache.
the class UserPrincipalProviderWithCacheTest method testCachedPrincipalsGroupRemoved.
@Test
public void testCachedPrincipalsGroupRemoved() throws Exception {
// a) force the cache to be created
PrincipalProvider pp = createPrincipalProvider(systemRoot);
Iterable<? extends Principal> principals = Iterables.filter(pp.getPrincipals(userId), new GroupPredicate());
for (Principal p : principals) {
String className = p.getClass().getName();
assertEquals("org.apache.jackrabbit.oak.security.user.UserPrincipalProvider$GroupPrincipalImpl", className);
}
testGroup.remove();
root.commit();
systemRoot.refresh();
// b) retrieve principals again (this time from the cache)
// principal for 'testGroup' is no longer backed by an user mgt group
// verify that this doesn't lead to runtime exceptions
Iterable<? extends Principal> principalsAgain = Iterables.filter(pp.getPrincipals(userId), new GroupPredicate());
for (Principal p : principalsAgain) {
String className = p.getClass().getName();
assertEquals("org.apache.jackrabbit.oak.security.user.UserPrincipalProvider$CachedGroupPrincipal", className);
assertTrue(p instanceof TreeBasedPrincipal);
assertNull(((TreeBasedPrincipal) p).getPath());
GroupPrincipal principalGroup = (GroupPrincipal) p;
assertFalse(principalGroup.isMember(getTestUser().getPrincipal()));
Enumeration<? extends Principal> members = principalGroup.members();
assertFalse(members.hasMoreElements());
}
}
Aggregations