public void testModifyImpersonationOfUser() throws RepositoryException, NotExecutableException {
UserManager umgr = getUserManager(otherSession);
Principal otherP = umgr.getAuthorizable(otherUID).getPrincipal();
// modify impersonation of new user
User u = null;
try {
Principal p = getTestPrincipal();
u = umgr.createUser(p.getName(), buildPassword(p));
save(otherSession);
Impersonation impers = u.getImpersonation();
assertFalse(impers.allows(buildSubject(otherP)));
assertTrue(impers.grantImpersonation(otherP));
save(otherSession);
assertTrue(impers.allows(buildSubject(otherP)));
} finally {
// impersonation get removed while removing the user u.
if (u != null) {
u.remove();
save(otherSession);
}
}
// modify impersonation of another user
u = (User) umgr.getAuthorizable(uID);
Impersonation uImpl = u.getImpersonation();
if (!uImpl.allows(buildSubject(otherP))) {
// ... trying to modify 'impersonators of another user must succeed
assertTrue(uImpl.grantImpersonation(otherP));
save(otherSession);