/** * @return a Collection of principals that contains the current user * principal and all groups it is member of. */ protected Set<Principal> getPrincipals() { // use linked HashSet instead of HashSet in order to maintain the order // of principals (as in the Subject). Set<Principal> principals = new LinkedHashSet<Principal>(); principals.add(principal); PrincipalIterator groups = principalProvider.getGroupMembership(principal); while (groups.hasNext()) { principals.add(groups.nextPrincipal()); } return principals; }
public void testFindPrincipalByTypeAll() { Principal[] pcpls = getPrincipals(superuser); for (Principal pcpl : pcpls) { if (pcpl.equals(everyone)) { // special case covered by another test continue; } PrincipalIterator it = principalMgr.findPrincipals(pcpl.getName(), PrincipalManager.SEARCH_TYPE_ALL); PrincipalIterator it2 = principalMgr.findPrincipals(pcpl.getName()); // both search must reveal the same result and size assertTrue(it.getSize() == it2.getSize()); Set<Principal> s1 = new HashSet<Principal>(); Set<Principal> s2 = new HashSet<Principal>(); while (it.hasNext() && it2.hasNext()) { s1.add(it.nextPrincipal()); s2.add(it2.nextPrincipal()); } assertEquals(s1, s2); assertFalse(it.hasNext() && it2.hasNext()); } }
public boolean hasMoreElements() { return members.hasNext(); } public Principal nextElement() {
public Principal nextElement() { return members.nextPrincipal(); } };
public boolean hasMoreElements() { return members.hasNext(); } public Principal nextElement() {
public Principal nextElement() { return members.nextPrincipal(); } };
/** * @return a Collection of principals that contains the current user * principal and all groups it is member of. */ protected Set<Principal> getPrincipals() { // use linked HashSet instead of HashSet in order to maintain the order // of principals (as in the Subject). Set<Principal> principals = new LinkedHashSet<Principal>(); principals.add(principal); PrincipalIterator groups = principalProvider.getGroupMembership(principal); while (groups.hasNext()) { principals.add(groups.nextPrincipal()); } return principals; }
@Test public void testFindPrincipalByTypeAll() { for (Principal pcpl : adminPrincipals) { if (pcpl.equals(everyone)) { // special case covered by another test continue; } assertTrue(principalMgr.hasPrincipal(pcpl.getName())); PrincipalIterator it = principalMgr.findPrincipals(pcpl.getName(), PrincipalManager.SEARCH_TYPE_ALL); PrincipalIterator it2 = principalMgr.findPrincipals(pcpl.getName()); assertTrue("Principal "+ pcpl.getName() + " not found", it.hasNext()); assertTrue("Principal "+ pcpl.getName() + " not found", it2.hasNext()); // both search must reveal the same result and size assertTrue(it.getSize() == it2.getSize()); Set<Principal> s1 = new HashSet<Principal>(); Set<Principal> s2 = new HashSet<Principal>(); while (it.hasNext() && it2.hasNext()) { s1.add(it.nextPrincipal()); s2.add(it2.nextPrincipal()); } assertEquals(s1, s2); assertFalse(it.hasNext() && it2.hasNext()); } }
/** * {@inheritDoc} */ public PrincipalIterator findPrincipals(String simpleFilter, int searchType) { checkIsValid(); List<CheckedIteratorEntry> entries = new ArrayList<CheckedIteratorEntry>(providers.length); for (PrincipalProvider pp : providers) { PrincipalIterator it = pp.findPrincipals(simpleFilter, searchType); if (it.hasNext()) { entries.add(new CheckedIteratorEntry(it, pp)); } } return new CheckedPrincipalIterator(entries); }
private Set<Principal> getAuthorizablesToCheck(Authorizable authorizable, Context context) throws RepositoryException { Set<Principal> principals = new HashSet<>(); Principal principal = authorizable.getPrincipal(); principals.add(principal); for (PrincipalIterator it = (context.getSession()).getPrincipalManager() .getGroupMembership(principal); it.hasNext(); ) { principals.add(it.nextPrincipal()); } return principals; }
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()); } }
/** * {@inheritDoc} */ public PrincipalIterator findPrincipals(String simpleFilter) { checkIsValid(); List<CheckedIteratorEntry> entries = new ArrayList<CheckedIteratorEntry>(providers.length); for (PrincipalProvider pp : providers) { PrincipalIterator it = pp.findPrincipals(simpleFilter); if (it.hasNext()) { entries.add(new CheckedIteratorEntry(it, pp)); } } return new CheckedPrincipalIterator(entries); }
private Set<Principal> getAuthorizablesToCheck(Authorizable authorizable, Context context) throws RepositoryException { Set<Principal> principals = new HashSet<>(); Principal principal = authorizable.getPrincipal(); principals.add(principal); for (PrincipalIterator it = (context.getSession()).getPrincipalManager() .getGroupMembership(principal); it.hasNext(); ) { principals.add(it.nextPrincipal()); } return principals; }
@Test public void testSystemUserPrincipal() throws RepositoryException { Authorizable authorizable = getUserManager(root).getAuthorizable(systemUser.getID()); // EXERCISE: what is the nature of the principal of the system user? Assert your expectedation. Principal principal = authorizable.getPrincipal(); PrincipalManager principalManager = getPrincipalManager(root); PrincipalIterator pIter = principalManager.getGroupMembership(principal); int expectedSize = -1; // EXERCISE assertEquals(expectedSize, pIter.getSize()); List<Principal> expectedGroupPrincipals = null; // EXERCISE while (pIter.hasNext()) { Principal group = pIter.nextPrincipal(); assertTrue(expectedGroupPrincipals.remove(group)); } assertTrue(expectedGroupPrincipals.isEmpty()); }
/** * {@inheritDoc} */ public PrincipalIterator findPrincipals(String simpleFilter, int searchType) { checkIsValid(); List<CheckedIteratorEntry> entries = new ArrayList<CheckedIteratorEntry>(providers.length); for (PrincipalProvider pp : providers) { PrincipalIterator it = pp.findPrincipals(simpleFilter, searchType); if (it.hasNext()) { entries.add(new CheckedIteratorEntry(it, pp)); } } return new CheckedPrincipalIterator(entries); }
private Principal[] getPrincipals(Credentials credentials) throws Exception { Set<Principal> principals = new HashSet<Principal>(); if (credentials instanceof SimpleCredentials) { Principal p = principalMgr.getPrincipal(((SimpleCredentials) credentials).getUserID()); if (p != null) { principals.add(p); PrincipalIterator principalIterator = principalMgr.getGroupMembership(p); while (principalIterator.hasNext()) { principals.add(principalIterator.nextPrincipal()); } } } return principals.toArray(new Principal[principals.size()]); }
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); } } }
/** * {@inheritDoc} */ public PrincipalIterator findPrincipals(String simpleFilter) { checkIsValid(); List<CheckedIteratorEntry> entries = new ArrayList<CheckedIteratorEntry>(providers.length); for (PrincipalProvider pp : providers) { PrincipalIterator it = pp.findPrincipals(simpleFilter); if (it.hasNext()) { entries.add(new CheckedIteratorEntry(it, pp)); } } return new CheckedPrincipalIterator(entries); }
public void testGetGroupPrincipals() { PrincipalIterator it = principalMgr.getPrincipals(PrincipalManager.SEARCH_TYPE_GROUP); while (it.hasNext()) { Principal p = it.nextPrincipal(); assertTrue(isGroup(p)); } }
/** * {@inheritDoc} * @param searchType */ public PrincipalIterator getPrincipals(int searchType) { checkIsValid(); List<CheckedIteratorEntry> entries = new ArrayList<CheckedIteratorEntry>(providers.length); for (PrincipalProvider pp : providers) { PrincipalIterator it = pp.getPrincipals(searchType); if (it.hasNext()) { entries.add(new CheckedIteratorEntry(it, pp)); } } return new CheckedPrincipalIterator(entries); }