log.error("Security Alert! Carbon Everyone role is being manipulated");
throw new UserStoreException("Invalid data");// obscure error
// message
}
UserStoreManager admin = realm.getUserStoreManager();
String[] oldUserList = admin.getUserListOfRole(roleName);
Arrays.sort(oldUserList);
List<String> delUsers = new ArrayList<String>();
List<String> addUsers = new ArrayList<String>();
for (FlaggedName fName : userList) {
boolean isSelected = fName.isSelected();
String userName = fName.getItemName();
if (CarbonConstants.REGISTRY_ANONNYMOUS_USERNAME.equals(userName)) {
log.error("Security Alert! Carbon anonymous user is being manipulated");
return;
}
int oldindex = Arrays.binarySearch(oldUserList, userName);
if (oldindex > -1 && !isSelected) {
// deleted
delUsers.add(userName);
} else if (oldindex < 0 && isSelected) {
// added
addUsers.add(userName);
}
}
admin.updateUserListOfRole(roleName, delUsers.toArray(new String[delUsers.size()]),
addUsers.toArray(new String[addUsers.size()]));
} catch (UserStoreException e) {
// previously logged so logging not needed
log.error(e.getMessage(), e);
throw new UserAdminException(e.getMessage(), e);