Spring explict身份验证调用未调用自定义处理程序

时间:2017-05-19 07:32:03

标签: java spring spring-security

要求是当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;
    }

1 个答案:

答案 0 :(得分:0)

您使用成功处理程序作为失败处理程序。尝试

.successHandler(mainSuccessHandler)