use of org.apache.jackrabbit.api.security.principal.GroupPrincipal in project jackrabbit-oak by apache.
the class GroupTest method testMembersInPrincipal.
@Test
public void testMembersInPrincipal() throws NotExecutableException, RepositoryException {
User auth = getTestUser(superuser);
Group newGroup = null;
Group newGroup2 = null;
try {
newGroup = userMgr.createGroup(createGroupId());
newGroup2 = userMgr.createGroup(createGroupId());
superuser.save();
newGroup.addMember(newGroup2);
superuser.save();
newGroup2.addMember(auth);
superuser.save();
GroupPrincipal ngPrincipal = (GroupPrincipal) newGroup.getPrincipal();
GroupPrincipal ng2Principal = (GroupPrincipal) newGroup2.getPrincipal();
assertFalse(ng2Principal.isMember(ngPrincipal));
// newGroup2 must be member of newGroup's principal
assertTrue(ngPrincipal.isMember(newGroup2.getPrincipal()));
// testuser must be member of newGroup2's and newGroup's principal (indirect)
assertTrue(ng2Principal.isMember(auth.getPrincipal()));
assertTrue(ngPrincipal.isMember(auth.getPrincipal()));
} finally {
if (newGroup != null) {
newGroup.removeMember(newGroup2);
newGroup.remove();
superuser.save();
}
if (newGroup2 != null) {
newGroup2.removeMember(auth);
newGroup2.remove();
superuser.save();
}
}
}
use of org.apache.jackrabbit.api.security.principal.GroupPrincipal in project jackrabbit-oak by apache.
the class EveryoneGroupTest method testGroupPrincipal.
@Test
public void testGroupPrincipal() throws Exception {
Principal everyonePrincipal = everyone.getPrincipal();
assertTrue(everyonePrincipal instanceof GroupPrincipal);
assertTrue(everyonePrincipal.equals(EveryonePrincipal.getInstance()));
assertTrue(EveryonePrincipal.getInstance().equals(everyonePrincipal));
GroupPrincipal gr = (GroupPrincipal) everyonePrincipal;
assertFalse(gr.isMember(everyonePrincipal));
assertTrue(gr.isMember(getTestUser(superuser).getPrincipal()));
assertTrue(gr.isMember(new PrincipalImpl("test")));
}
use of org.apache.jackrabbit.api.security.principal.GroupPrincipal in project jackrabbit-oak by apache.
the class AbstractPrincipalTest method getGroupPrincipal.
GroupPrincipal getGroupPrincipal(@Nonnull ExternalIdentityRef ref) throws Exception {
String principalName = idp.getIdentity(ref).getPrincipalName();
Principal p = principalProvider.getPrincipal(principalName);
assertNotNull(p);
assertTrue(p instanceof GroupPrincipal);
return (GroupPrincipal) p;
}
use of org.apache.jackrabbit.api.security.principal.GroupPrincipal in project jackrabbit-oak by apache.
the class ExternalGroupPrincipalTest method testMembers.
@Test
public void testMembers() throws Exception {
GroupPrincipal principal = getGroupPrincipal();
Principal[] expectedMembers = new Principal[] { getUserManager(root).getAuthorizable(USER_ID).getPrincipal(), new PrincipalImpl(idp.getUser(USER_ID).getPrincipalName()) };
for (Principal expected : expectedMembers) {
Enumeration<? extends Principal> members = principal.members();
assertTrue(members.hasMoreElements());
assertEquals(expected, members.nextElement());
assertFalse(members.hasMoreElements());
}
}
use of org.apache.jackrabbit.api.security.principal.GroupPrincipal in project jackrabbit-oak by apache.
the class ExternalGroupPrincipalTest method testIsMemberExternalGroup.
@Test
public void testIsMemberExternalGroup() throws Exception {
GroupPrincipal principal = getGroupPrincipal();
Iterable<String> exGroupPrincNames = Iterables.transform(ImmutableList.copyOf(idp.listGroups()), new Function<ExternalGroup, String>() {
@Nullable
@Override
public String apply(ExternalGroup input) {
return input.getPrincipalName();
}
});
for (String principalName : exGroupPrincNames) {
assertFalse(principal.isMember(new PrincipalImpl(principalName)));
}
}
Aggregations