Spring Security使用过滤器而不是控制器

时间:2020-09-17 00:03:19

标签: java spring spring-boot security

尝试使用Spring Boot启动程序2.3.0和Spring Security 5.3.2设置登录身份验证

我的loginController最初正在处理/login POST请求

然后,我添加了Spring Security和一个UsernamePasswordAuthenticationFilter,以及其他类来验证我从其他应用复制的内容,并且可以正常工作。

它正在验证用户名和密码,但是没有通过Controller /login方法。似乎只是跳过它(没有显示sysout日志)。但是,如果我删除该方法,那么它将无法正常工作(因此就好像它必须存在但不能进入其中)。

@Override
public void configure(HttpSecurity http) throws Exception {
    
   http
    .csrf().disable()
    .cors()
    .and().sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
    .and().authorizeRequests()
    .antMatchers(SecurityConstant.PUBLIC_URLS).permitAll()
    .anyRequest().authenticated()
    .and()
    .addFilterBefore(
    //      authenticationFilter(),
            jwtAuthorizationFilter,
            UsernamePasswordAuthenticationFilter.class);    

有人曾经经历过类似的事情吗?谢谢,感谢任何帮助,尝试学习Spring Security

0 个答案:

没有答案