* @see org.rhq.enterprise.server.auth.SubjectManagerLocal#deleteUsers(Subject, int[])
*/
@RequiredPermission(Permission.MANAGE_SECURITY)
public void deleteUsers(Subject subject, int[] subjectIds) {
for (Integer doomedSubjectId : subjectIds) {
Subject doomedSubject = getSubjectById(doomedSubjectId);
if (subject.getName().equals(doomedSubject.getName())) {
throw new PermissionException("You cannot remove yourself: " + doomedSubject.getName());
}
if (authorizationManager.isSystemSuperuser(doomedSubject)) {
throw new PermissionException("You cannot delete a system root user - they must always exist");
}
Set<Role> roles = doomedSubject.getRoles();
doomedSubject.setRoles(new HashSet<Role>()); // clean out roles
for (Role doomedRoleRelationship : roles) {
doomedRoleRelationship.removeSubject(doomedSubject);
}
// TODO: we need to reassign ownership of things this user used to own
// if this user was authenticated via JDBC and thus has a principal, remove it
if (isUserWithPrincipal(doomedSubject.getName())) {
deletePrincipal(doomedSubject);
}
// one more thing, delete any owned groups
List<ResourceGroup> ownedGroups = doomedSubject.getOwnedGroups();
if (null != ownedGroups && !ownedGroups.isEmpty()) {
int size = ownedGroups.size();
int[] ownedGroupIds = new int[size];
for (int i = 0; (i < size); ++i) {
ownedGroupIds[i] = ownedGroups.get(i).getId();
}
try {
resourceGroupManager.deleteResourceGroups(subject, ownedGroupIds);
} catch (Throwable t) {
if (log.isDebugEnabled()) {
log.error("Error deleting owned group " + Arrays.toString(ownedGroupIds), t);
} else {
log.error("Error deleting owned group " + Arrays.toString(ownedGroupIds) + ": "
+ t.getMessage());
}
}
}
// Delete searches saved by this user
SavedSearchCriteria savedSearchCriteria = new SavedSearchCriteria();
savedSearchCriteria.addFilterSubjectId(doomedSubjectId);
savedSearchCriteria.clearPaging();
PageList<SavedSearch> savedSearches = savedSearchManager.findSavedSearchesByCriteria(subject,
savedSearchCriteria);
for (SavedSearch savedSearch : savedSearches) {
savedSearchManager.deleteSavedSearch(subject, savedSearch.getId());
}
alertNotificationManager.cleanseAlertNotificationBySubject(doomedSubject.getId());
repoManager.removeOwnershipOfSubject(doomedSubject.getId());
entityManager.remove(doomedSubject);
}
return;