@Test public void testGrantImpersonationUserLookupFails() throws Exception { Principal nonExisting = new TreeBasedPrincipal("nonExisting", user.getTree(), getNamePathMapper()); UserManagerImpl uMgr = spy((UserManagerImpl) getUserManager(root)); when(uMgr.getAuthorizable(nonExisting)).thenThrow(new RepositoryException()); ImpersonationImpl imp = new ImpersonationImpl(new UserImpl(user.getID(), user.getTree(), uMgr)); assertFalse(imp.grantImpersonation(nonExisting)); }
@Override public boolean grantImpersonation(@NotNull Principal principal) throws RepositoryException { if (!isValidPrincipal(principal)) { return false; } String principalName = principal.getName(); Tree userTree = user.getTree(); PropertyState prop = userTree.getProperty(REP_PRINCIPAL_NAME); if (prop != null && prop.getValue(Type.STRING).equals(principalName)) { log.warn("Cannot grant impersonation to oneself."); return false; } user.getUserManager().onImpersonation(user, principal, true); Set<String> impersonators = getImpersonatorNames(userTree); if (impersonators.add(principalName)) { updateImpersonatorNames(userTree, impersonators); return true; } else { return false; } }
ImpersonationImpl implements Impersonation, UserConstants { @Override public boolean grantImpersonation(@NotNull Principal principal) throws RepositoryException { if (!isValidPrincipal(principal)) { return false; } String principalName = principal.getName(); Tree userTree = user.getTree(); PropertyState prop = userTree.getProperty(REP_PRINCIPAL_NAME); if (prop != null && prop.getValue(Type.STRING).equals(principalName)) { log.warn("Cannot grant impersonation to oneself."); return false; } user.getUserManager().onImpersonation(user, principal, true); Set<String> impersonators = getImpersonatorNames(userTree); if (impersonators.add(principalName)) { updateImpersonatorNames(userTree, impersonators); return true; } else { return false; } } }
ImpersonationImpl implements Impersonation, UserConstants { @Override public boolean grantImpersonation(@NotNull Principal principal) throws RepositoryException { if (!isValidPrincipal(principal)) { return false; } String principalName = principal.getName(); Tree userTree = user.getTree(); PropertyState prop = userTree.getProperty(REP_PRINCIPAL_NAME); if (prop != null && prop.getValue(Type.STRING).equals(principalName)) { log.warn("Cannot grant impersonation to oneself."); return false; } user.getUserManager().onImpersonation(user, principal, true); Set<String> impersonators = getImpersonatorNames(userTree); if (impersonators.add(principalName)) { updateImpersonatorNames(userTree, impersonators); return true; } else { return false; } } ImpersonationImpl(@NotNull UserImpl user); }
ImpersonationImpl implements Impersonation, UserConstants { @Override public boolean grantImpersonation(@NotNull Principal principal) throws RepositoryException { if (!isValidPrincipal(principal)) { return false; } String principalName = principal.getName(); Tree userTree = user.getTree(); PropertyState prop = userTree.getProperty(REP_PRINCIPAL_NAME); if (prop != null && prop.getValue(Type.STRING).equals(principalName)) { log.warn("Cannot grant impersonation to oneself."); return false; } user.getUserManager().onImpersonation(user, principal, true); Set<String> impersonators = getImpersonatorNames(userTree); if (impersonators.add(principalName)) { updateImpersonatorNames(userTree, impersonators); return true; } else { return false; } } 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); }
ImpersonationImpl implements Impersonation, UserConstants { @Override public boolean grantImpersonation(@NotNull Principal principal) throws RepositoryException { if (!isValidPrincipal(principal)) { return false; } String principalName = principal.getName(); Tree userTree = user.getTree(); PropertyState prop = userTree.getProperty(REP_PRINCIPAL_NAME); if (prop != null && prop.getValue(Type.STRING).equals(principalName)) { log.warn("Cannot grant impersonation to oneself."); return false; } user.getUserManager().onImpersonation(user, principal, true); Set<String> impersonators = getImpersonatorNames(userTree); if (impersonators.add(principalName)) { updateImpersonatorNames(userTree, impersonators); return true; } else { return false; } } 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);  }