public void testAddParentToGroup() throws RepositoryException, NotExecutableException {
UserManager umgr = getUserManager(uSession);
Authorizable pU = umgr.getAuthorizable(parentUID);
Group gr = (Group) umgr.getAuthorizable(groupAdmin.getID());
// adding and removing the parent-user as member of a group must
// never succeed.
try {
assertFalse(gr.addMember(pU));
} catch (AccessDeniedException e) {
// ok
} finally {
gr.removeMember(pU);
}
// ... even if the editing user becomes member of the user-admin group
Group uAdministrators = null;
try {
Authorizable userAdmin = userMgr.getAuthorizable(UserConstants.USER_ADMIN_GROUP_NAME);
if (userAdmin == null || !userAdmin.isGroup()) {
throw new NotExecutableException("Cannot execute test. User-Admin name has been changed by config.");
}
uAdministrators = (Group) userAdmin;
uAdministrators.addMember(userMgr.getAuthorizable(uID));
try {
assertFalse(gr.addMember(pU));
gr.removeMember(pU);
} catch (AccessDeniedException e) {
// fine as well.
}
} finally {
// let superuser do the clean up.
// remove testuser from u-admin group again.
if (uAdministrators != null) {
uAdministrators.removeMember(userMgr.getAuthorizable(uID));
}
}
}