@Override
  public Authentication authenticate(Authentication authentication) throws AuthenticationException {
    if (authentication.getName() == null) {
      LOG.info("Authentication failed: no username provided");
      throw new InvalidUsernamePasswordCombinationException("");
    }

    String userName = authentication.getName().trim();

    if (authentication.getCredentials() == null) {
      LOG.info("Authentication failed: no credentials provided: {}", userName);
      throw new InvalidUsernamePasswordCombinationException(userName);
    }

    Users users = getUsers();

    UserEntity userEntity = users.getUserEntity(userName);

    if (userEntity == null) {
      LOG.info("User not found: {}", userName);
      throw new InvalidUsernamePasswordCombinationException(userName);
    }

    UserAuthenticationEntity authenticationEntity = getAuthenticationEntity(userEntity, UserAuthenticationType.LOCAL);
    if (authenticationEntity != null) {
      String password = authenticationEntity.getAuthenticationKey();
      String presentedPassword = authentication.getCredentials().toString();

      if (passwordEncoder.matches(presentedPassword, password)) {
        // The user was  authenticated, return the authenticated user object
        LOG.debug("Authentication succeeded - a matching username and password were found: {}", userName);

        try {
          users.validateLogin(userEntity, userName);
        }
        catch (AccountDisabledException | TooManyLoginFailuresException e) {
          if (getConfiguration().showLockedOutUserMessage()) {
            throw e;
          } else {
            // Do not give away information about the existence or status of a user
            throw new InvalidUsernamePasswordCombinationException(userName, false, e);
          }
        }

        AmbariUserDetails userDetails = new AmbariUserDetailsImpl(users.getUser(userEntity), password, users.getUserAuthorities(userEntity));
        return new AmbariUserAuthentication(password, userDetails, true);
      }
    }

    // The user was not authenticated, fail
    LOG.debug("Authentication failed: password does not match stored value: {}", userName);
    throw new InvalidUsernamePasswordCombinationException(userName);
  }
AmbariLocalAuthenticationProvider is an {@link org.springframework.security.authentication.AuthenticationProvider}
implementation used to authenticate users using username and password details from the local Ambari database.
<p>
Users will fail to authenticate, even if they supply the correct credentials if the account is locked out
by being disabled or locked due to too many consecutive failure.
ambari-server/src/main/java/org/apache/ambari/server/security/authentication/AmbariLocalAuthenticationProvider.java