要求是当JSP页面以动作提交时 " test / login",然后下面的方法将调用并检查有效性以及是否有效 成功,它必须重定向到CustomSuccess hanlder,但它无法正常工作。
控制器:
@RequestMapping("test/login")
public String login(Map<String, Object> model, HttpServletRequest request) {
String userName = (String) request.getParameter("username");
String password = (String) request.getParameter("password");
Authentication authentication =authenticationProvider.authenticate(new UsernamePasswordAuthenticationToken(userName, password));
}
配置:
protected void configure(HttpSecurity http) throws Exception {
.authorizeRequests()
.antMatchers("/test/**"))
.permitAll()
.and()
.formLogin()
.loginPage("/login")
.failureHandler(mainSuccessHandler)
.permitAll()
}
处理程序:
@Bean(name = "mainSuccessHandler")
public AuthenticationSuccessHandler mainSuccessHandler(
@Qualifier("defaultSuccessHandler") AuthenticationSuccessHandler defaultSuccessHandler
CustomAuthenticationSuccessHandler result = new CustomAuthenticationSuccessHandler();
result.addAuthenticationFailureHandler(anyRefererRequestMather(), defaultSuccessHandler);
return result;
}
答案 0 :(得分:0)
您使用成功处理程序作为失败处理程序。尝试
.successHandler(mainSuccessHandler)