Spring 安全性显示“错误凭据”错误而不是重定向

问题描述 投票:0回答:1
java spring spring-mvc spring-security
1个回答
2
投票

定义成功和失败处理程序

@Bean
public AuthenticationSuccessHandler getSuccessHandler(){
  SavedRequestAwareAuthenticationSuccessHandler handler =  new SavedRequestAwareAuthenticationSuccessHandler();
  handler.setDefaultTargetUrl("/login.html");
  return handler;
}


@Bean
public AuthenticationFailureHandler getFailureHandler(){
  SimpleUrlAuthenticationFailureHandler handler  =  new SimpleUrlAuthenticationFailureHandler();
  handler.setDefaultFailureUrl("/login.html");
  return handler;
}

在你的过滤器中

@Autowired
    @Qualifier("authenticationManager")
    @Override
    public void setAuthenticationManager(AuthenticationManager authenticationManager, AuthenticationSuccessHandler successHandler, AuthenticationFailureHandler failureHandler) {
        super.setAuthenticationManager(authenticationManager);
        this.setAuthenticationSuccessHandler(successHandler);
        this.setAuthenticationFailureHandler(failureHandler);
    }
© www.soinside.com 2019 - 2024. All rights reserved.