Spring Security niestandardowy komunikat AuthenticationException

Hi potrzebowałem dodać nowy wyjątek w wiosennym formularzu logowania bezpieczeństwa, wszystko działa idealnie, z wyjątkiem tego, że chcę mieć swój własny komunikat o błędzie (do tej pory wyświetlał on „zły login / hasło”).

Zastąpiłem domyślną metodę uwierzytelniania próby z hasła użytkownika Filtr uwierzytelniania:

@Override
public Authentication attemptAuthentication(final HttpServletRequest request, final HttpServletResponse response)
{
if (!myTest()) {
throw new CustomAuthenticationException("custom message");
}
}

Mój wyjątek:

public class CustomAuthenticationException extends AuthenticationException {

    public CustomAuthenticationException(final String message)
    {
        super(message);
    }

    public CustomAuthenticationException(final String message, final Throwable cause)
    {
        super(message, cause);
    }

}

W moim kontrolerze widzę wyjątek w SPRING_SECURITY_LAST_EXCEPTION, ale komunikat o błędzie jest zawsze taki sam, jak w przypadku złych poświadczeń. Jak mogę to zmienić?

Dziękuję Ci

questionAnswers(4)

yourAnswerToTheQuestion