class AmbariBasicAuthenticationFilter extends BasicAuthenticationFilter implements AmbariAuthenticationFilter {

  @Override
  protected void onUnsuccessfulAuthentication(HttpServletRequest servletRequest,
                                              HttpServletResponse servletResponse,
                                              AuthenticationException authException) throws IOException {
    if (eventHandler != null) {
      AmbariAuthenticationException cause;
      if (authException instanceof AmbariAuthenticationException) {
        cause = (AmbariAuthenticationException) authException;
      } else {
        String header = servletRequest.getHeader("Authorization");
        String username = null;
        try {
          username = getUsernameFromAuth(header, getCredentialsCharset(servletRequest));
        } catch (Exception e) {
          LOG.warn("Error occurred during decoding authorization header.", e);
        }

        cause = new AmbariAuthenticationException(username, authException.getMessage(), false, authException);
      }

      eventHandler.onUnsuccessfulAuthentication(this, servletRequest, servletResponse, cause);
    }
  }

  public  AmbariBasicAuthenticationFilter(AuthenticationManager authenticationManager,
                                         AmbariEntryPoint ambariEntryPoint,
                                         AmbariAuthenticationEventHandler eventHandler);

}