【发布时间】:2017-10-19 05:31:54
【问题描述】:
要求是当JSP页面提交的时候action为 “测试/登录”,然后下面的方法将调用并检查有效性,如果它 成功,它必须重定向到 CustomSuccess 处理程序,但它不起作用。
控制器:
@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;
}
【问题讨论】:
标签: java spring spring-security