/** * Returns an enumeration of the members in the group. * @param principal the principal whose membership is listed. * @return an enumeration of the group members. */ public static Enumeration<? extends Principal> members(@NotNull Principal principal) { if (principal instanceof Group) { return ((Group) principal).members(); } if (principal instanceof GroupPrincipal) { return ((GroupPrincipal) principal).members(); } return Collections.emptyEnumeration(); }
/** * Returns true if the passed principal is a member of the group. * @param principal the principal whose members are being checked. * @param member the principal whose membership is to be checked. * @return true if the principal is a member of this group, false otherwise. */ public static boolean isMember(@NotNull Principal principal, @NotNull Principal member) { if (principal instanceof Group) { return ((Group) principal).isMember(member); } if (principal instanceof GroupPrincipal) { return ((GroupPrincipal) principal).isMember(member); } return false; }
private static Set<Principal> membership(@NotNull String name) { if ("a".equals(name)) { return ImmutableSet.of(EveryonePrincipal.getInstance(), gr2, gr3); } else if ("ac".equals(name)) { return ImmutableSet.of(EveryonePrincipal.getInstance(), gr3); } else if (gr2.getName().equals(name)) { return ImmutableSet.of(EveryonePrincipal.getInstance(), gr3); } else if (principals.containsKey(name)) { return ImmutableSet.of(EveryonePrincipal.getInstance()); } else { return ImmutableSet.of(); } } }
@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()); } }
@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()); } }
/** * Returns true if the passed principal is a member of the group. * @param principal the principal whose members are being checked. * @param member the principal whose membership is to be checked. * @return true if the principal is a member of this group, false otherwise. */ public static boolean isMember(Principal principal, Principal member) { if (principal instanceof Group) { return ((Group) principal).isMember(member); } if (principal instanceof GroupPrincipal) { return ((GroupPrincipal) principal).isMember(member); } return false; } }
private static Enumeration<? extends Principal> members(Principal principal) { if (principal instanceof Group) { return ((Group) principal).members(); } if (principal instanceof GroupPrincipal) { return ((GroupPrincipal) principal).members(); } return Collections.emptyEnumeration(); } }
public void testGetPrincipal() { Principal p = principalMgr.getPrincipal(everyone.getName()); assertEquals(everyone, p); Principal[] pcpls = getPrincipals(superuser); for (Principal pcpl : pcpls) { Principal pp = principalMgr.getPrincipal(pcpl.getName()); assertEquals("PrincipalManager.getPrincipal returned Principal with different Name", pcpl.getName(), pp.getName()); } }
/** * Returns true if the passed principal is a member of the group. * @param principal the principal whose members are being checked. * @param member the principal whose membership is to be checked. * @return true if the principal is a member of this group, false otherwise. */ public static boolean isMember(Principal principal, Principal member) { if (principal instanceof Group) { return ((Group) principal).isMember(member); } if (principal instanceof GroupPrincipal) { return ((GroupPrincipal) principal).isMember(member); } return false; } }
/** * Returns an enumeration of the members in the group. * @param principal the principal whose membership is listed. * @return an enumeration of the group members. */ public static Enumeration<? extends Principal> members(Principal principal) { if (principal instanceof Group) { return ((Group) principal).members(); } if (principal instanceof GroupPrincipal) { return ((GroupPrincipal) principal).members(); } return Collections.emptyEnumeration(); }
@Test public void testGetPrincipal() { Principal p = principalMgr.getPrincipal(everyone.getName()); assertEquals(everyone, p); for (Principal pcpl : adminPrincipals) { Principal pp = principalMgr.getPrincipal(pcpl.getName()); assertEquals("PrincipalManager.getPrincipal returned Principal with different Name", pcpl.getName(), pp.getName()); } }
public void testEveryoneIsMemberofEveryone() throws RepositoryException { GroupPrincipal everyone = (GroupPrincipal) principalManager.getEveryone(); PrincipalIterator it = principalManager.getPrincipals(PrincipalManager.SEARCH_TYPE_ALL); // EXERCISE: discuss the dynamic nature of the everyone group principal while (it.hasNext()) { Principal principal = it.nextPrincipal(); if (everyone.equals(principal)) { assertFalse(everyone.isMember(principal)); } else { assertTrue(everyone.isMember(principal)); } } }
/** * Returns an enumeration of the members in the group. * @param principal the principal whose membership is listed. * @return an enumeration of the group members. */ public static Enumeration<? extends Principal> members(Principal principal) { if (principal instanceof Group) { return ((Group) principal).members(); } if (principal instanceof GroupPrincipal) { return ((GroupPrincipal) principal).members(); } return Collections.emptyEnumeration(); }
public void testHasPrincipal() { assertTrue(principalMgr.hasPrincipal(everyone.getName())); Principal[] pcpls = getPrincipals(superuser); for (Principal pcpl : pcpls) { assertTrue(principalMgr.hasPrincipal(pcpl.getName())); } }
public void testSuperUserIsEveryOne() { Principal[] pcpls = getPrincipals(superuser); for (Principal pcpl : pcpls) { if (!(pcpl.equals(everyone))) { assertTrue(everyone.isMember(pcpl)); } } }
@Test public void testAllMembersKnown() { for (Principal p : testPrincipals) { if (isGroup(p)) { Enumeration<? extends Principal> en = ((GroupPrincipal) p).members(); while (en.hasMoreElements()) { Principal memb = en.nextElement(); assertTrue(principalMgr.hasPrincipal(memb.getName())); } } } }
@Test public void testHasPrincipal() { assertTrue(principalMgr.hasPrincipal(everyone.getName())); for (Principal pcpl : adminPrincipals) { assertTrue(principalMgr.hasPrincipal(pcpl.getName())); } }
@Test public void testSuperUserIsEveryOne() { for (Principal pcpl : adminPrincipals) { if (!(pcpl.equals(everyone))) { assertTrue(everyone.isMember(pcpl)); } } }
public void testGroupMembers() { PrincipalIterator it = principalMgr.getPrincipals(PrincipalManager.SEARCH_TYPE_ALL); while (it.hasNext()) { Principal p = it.nextPrincipal(); if (isGroup(p) && !p.equals(principalMgr.getEveryone())) { Enumeration<? extends Principal> en = ((GroupPrincipal) p).members(); while (en.hasMoreElements()) { Principal memb = en.nextElement(); assertTrue(principalMgr.hasPrincipal(memb.getName())); } } } }
@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))); } }