【问题标题】:Spring explict authentication call is not invoking the custom handlerSpring 显式身份验证调用未调用自定义处理程序
【发布时间】: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


【解决方案1】:

您将成功处理程序用作失败处理程序。试试

.successHandler(mainSuccessHandler) 

【讨论】:

    猜你喜欢
    • 2011-01-03
    • 1970-01-01
    • 1970-01-01
    • 2017-09-04
    • 2013-12-10
    • 2013-11-19
    • 1970-01-01
    • 2018-12-06
    • 2017-10-01
    相关资源
    最近更新 更多