xxxxxxxxxx
@Override
protected void configure(HttpSecurity http) throws Exception {
.failureHandler(getAuthenticationFailureHandler())
}
@Bean
public AuthenticationFailureHandler getAuthenticationFailureHandler() {
return new MyAuthenticationFailureHandler();
}
xxxxxxxxxx
public class MyAuthenticationFailureHandler implements AuthenticationFailureHandler {
@Override
public void onAuthenticationFailure(HttpServletRequest httpServletRequest,
HttpServletResponse httpServletResponse,
AuthenticationException e) throws IOException, ServletException {
httpServletResponse.setStatus(HttpStatus.UNAUTHORIZED.value());
httpServletResponse.sendRedirect("/login?loginError=true");
}
xxxxxxxxxx
<p class="text-danger" th:if="${param.loginError}" th:text="'Wrong username or password'"></p>