@Override
@RequiredPermission(Permission.MANAGE_SECURITY)
public void removeSubjectsFromRole(Subject subject, int roleId, int[] subjectIds) {
if ((subjectIds != null) && (subjectIds.length > 0)) {
Role role = entityManager.find(Role.class, roleId);
if (role == null) {
throw new IllegalArgumentException("Could not find role[" + roleId + "] to remove subjects from");
}
role.getSubjects().size(); // load them in
for (Integer subjectId : subjectIds) {
Subject doomedSubject = entityManager.find(Subject.class, subjectId);
if (doomedSubject == null) {
throw new IllegalArgumentException("Tried to remove subject[" + subjectId + "] from role[" + roleId
+ "], but subject was not found");
}
if (doomedSubject.getFsystem() || (authorizationManager.isSystemSuperuser(doomedSubject))) {
throw new PermissionException("You cannot remove user[" + doomedSubject.getName() + "] from role["
+ roleId + "] - roles are fixed for this user");
}
role.removeSubject(doomedSubject);
}
}
}