}
@Override
public synchronized void updateUsers(Set<UserRequest> requests) throws AmbariException {
for (UserRequest request : requests) {
User u = users.getAnyUser(request.getUsername());
if (null == u)
continue;
if (null != request.getOldPassword() && null != request.getPassword()) {
users.modifyPassword(u.getUserName(), request.getOldPassword(),
request.getPassword());
}
Set<String> roolesToDelete = new HashSet<String>(u.getRoles());
Set<String> roolesToAdd = request.getRoles();
roolesToDelete.removeAll(request.getRoles());
for (String role : roolesToDelete) {
users.removeRoleFromUser(u, role);
u.getRoles().remove(role);
}
roolesToAdd.removeAll(u.getRoles());
for (String role : roolesToAdd) {
users.addRoleToUser(u, role);
}
}