assert all_users_with_principals.contains(rhqadmin.getName());
assert !subjectManager.isUserWithPrincipal(superuser.getName());
assert subjectManager.isUserWithPrincipal(rhqadmin.getName());
// get all subjects, whether or not they have a principal
SubjectManagerLocal subjectManager = LookupUtil.getSubjectManager();
Subject subject = null;
try {
subject = subjectManager.loginUnauthenticated(RHQADMIN);
} catch (Exception e) {
assert false : "There must be at least rhqadmin user";
}
SubjectCriteria c = new SubjectCriteria();
c.addFilterFsystem(false);
c.addSortName(PageOrdering.ASC);
PageList<Subject> all_subjects = subjectManager.findSubjectsByCriteria(subject, c);
assert all_subjects.size() >= 1 : "There must be at least rhqadmin user";
assert !all_subjects.contains(superuser) : "The superuser should not have been returned in the list";
assert all_subjects.contains(rhqadmin) : "Missing user [" + rhqadmin + "] from: " + all_subjects;
// create, modify then delete the user
new_user = new Subject();
new_user.setFsystem(false);
new_user.setFactive(true);
new_user.setName("dummy-user");
new_user.setFirstName("my-firstname");
new_user.setLastName("my-lastname");
new_user.setEmailAddress("email@address.com");
new_user.setPhoneNumber("1-800-555-1212");
new_user.setSmsAddress("sms address");
new_user.setDepartment("my-department");
new_user = subjectManager.createSubject(rhqadmin, new_user);
new_user = createSession(new_user);
assert !subjectManager.isUserWithPrincipal(new_user.getName());
subjectManager.createPrincipal(subjectManager.getOverlord(), new_user.getName(), "my-password");
assert subjectManager.isUserWithPrincipal(new_user.getName());
// make sure it was persisted and you can actually login with it
assert new_user.getId() != 0;
Subject login_new_user = subjectManager.loginUnauthenticated(new_user.getName());
assert login_new_user.equals(new_user);
new_user = login_new_user; // login_new_user was given a new session ID
subjectManager.changePassword(new_user, new_user.getName(), "my-new-password");
subjectManager.changePassword(rhqadmin, new_user.getName(), "my-new-password"); // see that rhqadmin can change it too
getTransactionManager().commit();
getTransactionManager().begin();
try {
subjectManager.changePassword(new_user, rhqadmin.getName(), "not-allowed");
assert false : "The new user does not have permission to change another's password";
} catch (PermissionException se) {
} finally {
// PermissionException causes a rollback, let's start a new tx
getTransactionManager().rollback();
}
getTransactionManager().begin();
// this new user has no roles - therefore, no global permissions
assert authorizationManager.getExplicitGlobalPermissions(new_user).size() == 0;
try {
subjectManager.deleteUsers(new_user, new int[] { new_user.getId() });
assert false : "The new user should not have had the permission to delete itself";
} catch (PermissionException e) {
} finally {
// PermissionException causes a rollback, let's start a new tx
getTransactionManager().rollback();
}
getTransactionManager().begin();
// delete the new user
assert subjectManager.getSubjectByName(new_user.getName()).equals(new_user);
assert subjectManager.isUserWithPrincipal(new_user.getName());
subjectManager.deleteUsers(rhqadmin, new int[] { new_user.getId() });
assert subjectManager.getSubjectByName(new_user.getName()) == null;
assert !subjectManager.isUserWithPrincipal(new_user.getName());
getTransactionManager().commit();
}