private UnixUser performPAMAuthentication(String ambariUsername, String localUsername, String password) {
    PAM pam = pamAuthenticationFactory.createInstance(getConfiguration());

    if (pam == null) {
      String message = "Failed to authenticate the user using the PAM authentication method: unexpected error";
      LOG.error(message);
      throw new AmbariAuthenticationException(ambariUsername, message, false);
    } else {
      if (LOG.isDebugEnabled() && !ambariUsername.equals(localUsername)) {
        LOG.debug("Authenticating Ambari user {} using the local username {}", ambariUsername, localUsername);
      }

      try {
        // authenticate using PAM
        return pam.authenticate(localUsername, password);
      } catch (PAMException e) {
        // The user was not authenticated, fail
        LOG.debug(String.format("Authentication failed: password does not match stored value: %s", localUsername), e);
        throw new InvalidUsernamePasswordCombinationException(ambariUsername, true, e);
      } finally {
        pam.dispose();
      }
    }
  }
Perform the OS-level PAM authentication routine.

@param ambariUsername the Ambari username, used for logging and notifications
@param localUsername  the username to use for authenticating
@param password       the password to use for authenticating
@return the resulting user object
ambari-server/src/main/java/org/apache/ambari/server/security/authentication/pam/AmbariPamAuthenticationProvider.java