@NotNull @Override public Impersonation perform() throws RepositoryException { Impersonation impersonation = getDelegate().getImpersonation(); return ImpersonationDelegator.wrap(sessionDelegate, impersonation); } });
@NotNull @Override public Impersonation perform() throws RepositoryException { Impersonation impersonation = getDelegate().getImpersonation(); return ImpersonationDelegator.wrap(sessionDelegate, impersonation); } });
@Override public Impersonation getImpersonation() throws RepositoryException { Impersonation internal = delegate.getImpersonation(); return new ImpersonationFacade(internal); }
@Nonnull @Override public Impersonation perform() throws RepositoryException { Impersonation impersonation = getDelegate().getImpersonation(); return ImpersonationDelegator.wrap(sessionDelegate, impersonation); } });
@Override public Impersonation getImpersonation() throws RepositoryException { return new ImpersonationImpl(getDelegate().getImpersonation()); }
@Override public Impersonation getImpersonation() throws RepositoryException { return new ImpersonationImpl(getDelegate().getImpersonation()); }
@Override public Impersonation getImpersonation() throws RepositoryException { return new ImpersonationImpl(getDelegate().getImpersonation()); }
private boolean impersonate(AuthInfo info, User user) { try { if (user.getID().equals(info.getUserID())) { log.debug("User " + info.getUserID() + " wants to impersonate himself -> success."); return true; } else { log.debug("User " + info.getUserID() + " wants to impersonate " + user.getID()); Subject subject = new Subject(true, info.getPrincipals(), Collections.emptySet(), Collections.emptySet()); return user.getImpersonation().allows(subject); } } catch (RepositoryException e) { log.debug("Error while validating impersonation: {}", e.getMessage()); } return false; }
private boolean impersonate(AuthInfo info, User user) { try { if (user.getID().equals(info.getUserID())) { log.debug("User " + info.getUserID() + " wants to impersonate himself -> success."); return true; } else { log.debug("User " + info.getUserID() + " wants to impersonate " + user.getID()); Subject subject = new Subject(true, info.getPrincipals(), Collections.emptySet(), Collections.emptySet()); return user.getImpersonation().allows(subject); } } catch (RepositoryException e) { log.debug("Error while validating impersonation: {}", e.getMessage()); } return false; }
private boolean impersonate(AuthInfo info, User user) { try { if (user.getID().equals(info.getUserID())) { log.debug("User " + info.getUserID() + " wants to impersonate himself -> success."); return true; } else { log.debug("User " + info.getUserID() + " wants to impersonate " + user.getID()); Subject subject = new Subject(true, info.getPrincipals(), Collections.emptySet(), Collections.emptySet()); return user.getImpersonation().allows(subject); } } catch (RepositoryException e) { log.debug("Error while validating impersonation: {}", e.getMessage()); } return false; }
@Override protected void setUp() throws Exception { super.setUp(); Principal test = getTestPrincipal(); String pw = buildPassword(test); newUser = userMgr.createUser(test.getName(), pw); save(superuser); impersonation = newUser.getImpersonation(); }
/** * @see <a href="https://issues.apache.org/jira/browse/JCR-2931">JCR-2931</a> */ public void testAdminImpersonatingOneself() throws RepositoryException, NotExecutableException { User admin = getTestUser(superuser); Subject subject = createSubject(admin); assertTrue(admin.getImpersonation().allows(subject)); }
public void testModifyOthersImpersonators() throws RepositoryException { Principal p = uMgr.getAuthorizable(uID).getPrincipal(); User other = (User) uMgr.getAuthorizable(otherUID); try { boolean success = other.getImpersonation().grantImpersonation(p); // omit save call assertFalse("A simple user may not add itself as impersonator to another user.",success); } catch (AccessDeniedException e) { // fine as well -> access denied. } assertFalse("A simple user may not add itself as impersonator to another user.", other.getImpersonation().allows(buildSubject(p))); }
public void testImpersonateTestUser() throws RepositoryException { Principal principal = null; // EXERCISE: fill in the correct principal such that the test passes. Impersonation impersonation = anotherUser.getImpersonation(); impersonation.grantImpersonation(principal); superuser.save(); Session testSession = superuser.getRepository().login(ExerciseUtility.getTestCredentials(testUser.getID())); sessionList.add(testSession); Session impersonated = testSession.impersonate(new SimpleCredentials(anotherUser.getID(), new char[0])); sessionList.add(impersonated); assertEquals(anotherUser.getID(), impersonated.getUserID()); }
@Test public void testImpersonation() throws RepositoryException, NotExecutableException { Principal user2Principal = user2.getPrincipal(); Subject subject = new Subject(true, Collections.singleton(user2Principal), Collections.<Object>emptySet(), Collections.<Object>emptySet()); Impersonation impers = user.getImpersonation(); assertFalse(impers.allows(subject)); assertTrue(impers.grantImpersonation(user2Principal)); assertFalse(impers.grantImpersonation(user2Principal)); superuser.save(); assertTrue(impers.allows(subject)); assertTrue(impers.revokeImpersonation(user2Principal)); assertFalse(impers.revokeImpersonation(user2Principal)); superuser.save(); assertFalse(impers.allows(subject)); }
public void testAdminPrincipalAsImpersonator() throws RepositoryException, NotExecutableException { Principal adminPrincipal = new AdminPrincipal() { @Override public String getName() { return "some-admin-name"; } }; // admin cannot be add/remove to set of impersonators of 'u' but is // always allowed to impersonate that user. Impersonation impersonation = user.getImpersonation(); assertFalse(impersonation.grantImpersonation(adminPrincipal)); assertFalse(impersonation.revokeImpersonation(adminPrincipal)); assertTrue(impersonation.allows(buildSubject(adminPrincipal))); } }
@Test public void testGrantImpCnt() throws Exception { User user = getTestUser(); Principal p2 = getUserManager(root).createUser("tmpUser", null).getPrincipal(); user.getImpersonation().grantImpersonation(p2); assertEquals(0, cntAction.onDisabledCnt); assertEquals(1, cntAction.onGrantImpCnt); assertEquals(0, cntAction.onRevokeImpCnt); }
@Test public void testRevokeImpCnt() throws Exception { User user = getTestUser(); Principal p2 = getUserManager(root).createUser("tmpUser", null).getPrincipal(); user.getImpersonation().revokeImpersonation(p2); assertEquals(0, cntAction.onDisabledCnt); assertEquals(0, cntAction.onGrantImpCnt); assertEquals(1, cntAction.onRevokeImpCnt); }
public void testSystemPrincipalAsImpersonator() throws RepositoryException { Principal systemPrincipal = new SystemPrincipal(); assertNull(userMgr.getAuthorizable(systemPrincipal)); // system cannot be add/remove to set of impersonators of 'u' nor // should it be allowed to impersonate a given user... User u = (User) userMgr.getAuthorizable(uID); Impersonation impersonation = u.getImpersonation(); assertFalse(impersonation.grantImpersonation(systemPrincipal)); assertFalse(impersonation.revokeImpersonation(systemPrincipal)); assertFalse(impersonation.allows(buildSubject(systemPrincipal))); } }
@Test public void testImpersonation() throws Exception { User u = mgr.createUser("u", "u"); Impersonation imp = u.getImpersonation(); Principal p = mgr.getAuthorizable("anonymous").getPrincipal(); assertTrue(imp.grantImpersonation(p)); assertFalse(root.hasPendingChanges()); assertTrue(imp.revokeImpersonation(p)); assertFalse(root.hasPendingChanges()); }