You call super.onAuthenticationFailurewhich will display the redirect to the configured URL. So the answer has already been made, and you cannot decide to redirect somewhere else.
You can configure it SimpleUrlAuthenticationFailureHandlerto redirect to a single URL and only call the super method if you are not going to redirect yourself.
, AuthenticationFailureHandler , , - , :
if (oneCondition) {
} else {
}