ImpersonationImpl implements Impersonation, UserConstants { @NotNull @Override public PrincipalIterator getImpersonators() { Set<String> impersonators = getImpersonatorNames(); if (impersonators.isEmpty()) { return PrincipalIteratorAdapter.EMPTY; } else { Set<Principal> s = new HashSet<>(); for (final String pName : impersonators) { Principal p = principalManager.getPrincipal(pName); if (p == null) { log.debug("Impersonator {} does not correspond to a known Principal.", pName); p = new PrincipalImpl(pName); } s.add(p); } return new PrincipalIteratorAdapter(s); } } ImpersonationImpl(@NotNull UserImpl user); @NotNull @Override PrincipalIterator getImpersonators(); @Override boolean grantImpersonation(@NotNull Principal principal); @Override boolean revokeImpersonation(@NotNull Principal principal); @Override boolean allows(@NotNull Subject subject);  }
@Test public void testGetImpersonators() throws Exception { PrincipalIterator it = impersonation.getImpersonators(); assertTrue(it.hasNext()); assertTrue(Iterators.contains(it, impersonator.getPrincipal())); }
@Test public void testGetImpersonatorsImpersonatorRemoved() throws Exception { Principal p = impersonator.getPrincipal(); impersonator.remove(); PrincipalIterator it = impersonation.getImpersonators(); assertTrue(it.hasNext()); assertTrue(Iterators.contains(it, p)); }