private void createUsers(Set<UserRequest> requests) throws AmbariException, AuthorizationException {
    // First check for obvious issues... then try to create the accounts.  This will help to avoid
    // some accounts being created and some not due to an issue with one or more of the users.
    for (UserRequest request : requests) {
      String username = request.getUsername();

      if (StringUtils.isEmpty(username)) {
        throw new AmbariException("Username must be supplied.");
      }

      if (users.getUser(username) != null) {
        String message;
        if (requests.size() == 1) {
          message = "The requested username already exists.";
        } else {
          message = "One or more of the requested usernames already exists.";
        }
        throw new DuplicateResourceException(message);
      }
    }

    for (UserRequest request : requests) {
      String username = request.getUsername();
      String displayName = StringUtils.defaultIfEmpty(request.getDisplayName(), username);
      String localUserName = StringUtils.defaultIfEmpty(request.getLocalUserName(), username);
      String password = request.getPassword();
      // Setting a user's the password here is to allow for backward compatibility with pre-Ambari-3.0
      // versions so that the contract for REST API V1 is maintained.
      if (!StringUtils.isEmpty(password)) {
        users.validatePassword(password, username);
      }

      UserEntity userEntity = users.createUser(username, localUserName, displayName, request.isActive());
      if (userEntity != null) {
        if (Boolean.TRUE.equals(request.isAdmin())) {
          users.grantAdminPrivilege(userEntity);
        }

        // Setting a user's the password here is to allow for backward compatibility with pre-Ambari-3.0
        // versions so that the contract for REST API V1 is maintained.
        if (!StringUtils.isEmpty(password)) {
          // This is performed as a user administrator since the  authorization check was done prior
          // to executing #createResourcesAuthorized.
          addOrUpdateLocalAuthenticationSource(true, userEntity, request.getPassword(), null);
        }
      }
    }
  }
Creates users.

@param requests the request objects which define the user.
@throws AmbariException when the user cannot be created.
ambari-server/src/main/java/org/apache/ambari/server/controller/internal/UserResourceProvider.java