Spring security自定义用户认证流程详解

2020-03-11 18:01:22王冬梅
@Autowired
  private MySimpleUrlAuthenticationFailureHandler mySimpleUrlAuthenticationFailureHandler;
  @Override
  protected void configure(HttpSecurity http) throws Exception {
    http.formLogin()
        // 先进controller中去
        .loginPage("/user/auth")
        // 指定自定义登录页面
        .loginPage("/login.html")
        // 登录url
        .loginProcessingUrl("/auth/login")
        .successHandler(myAuthenticationSuccessHandler)
        .failureHandler(mySimpleUrlAuthenticationFailureHandler)
        .and()
        .authorizeRequests()
        // 该controller需要授权
        .antMatchers("/user/auth").permitAll()
        // 添加一个url匹配器,如果匹配到login.html,就授权
        .antMatchers("/login.html").permitAll()
        .anyRequest()
        .authenticated()
        .and()
        // 关闭spring security默认的防csrf攻击
        .csrf().disable();
  }

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持易采站长站。