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);
assertTrue(uImpl.allows(buildSubject(otherP)));
uImpl.revokeImpersonation(otherP);
save(otherSession);
} else {
throw new NotExecutableException("Cannot execute test. OtherP can already impersonate UID-user.");
}
}