public void addLocalAuthentication(UserEntity userEntity, String password, boolean persist) throws AmbariException {

    // Ensure the password meets configured minimal requirements, if any
    validatePassword(password, userEntity.getUserName());

    // Encode the password..
    String encodedPassword = passwordEncoder.encode(password);

    addAuthentication(userEntity,
        UserAuthenticationType.LOCAL,
        encodedPassword,
            (user, key) -> {
              List<UserAuthenticationEntity> authenticationEntities = user.getAuthenticationEntities();

              // Ensure only one UserAuthenticationEntity exists for LOCAL for the user...
              for (UserAuthenticationEntity entity : authenticationEntities) {
                if (entity.getAuthenticationType() == UserAuthenticationType.LOCAL) {
                  throw new AmbariException("The authentication type already exists for this user");
                }
              }
            },
        persist);
  }
Adds the ability for a user to authenticate using a password stored in Ambari's database
<p>
The supplied plaintext password will be encoded before storing.

@param userEntity the user
@param password   the user's plaintext password
@param persist    true, to persist the created entity; false, to not persist the created entity
@throws AmbariException
ambari-server/src/main/java/org/apache/ambari/server/security/authorization/Users.java