首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在csrfFilter中初始化requireCsrfProtectionMatcher的依据是什么

在csrfFilter中初始化requireCsrfProtectionMatcher的依据是什么
EN

Stack Overflow用户
提问于 2021-11-18 11:58:12
回答 1查看 32关注 0票数 0

CsrfFilter有一个验证

代码语言:javascript
复制
if (!this.requireCsrfProtectionMatcher.matches(request)) {
            filterChain.doFilter(request, response);
            return;
        }

在上面的代码片段中,this.requireCsrfProtectionMatcher被初始化为AndRequestMatcher。但我只想使用DefaultRequiresCsrfMatcher。谁能提供更多关于这方面的信息?我的安全配置

代码语言:javascript
复制
 @Override
    protected void configure(HttpSecurity http) throws Exception {
          http.csrf().and().
          cors().and()
            .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
            .and()
            .authorizeRequests()
            .antMatchers("/rest/open/**").permitAll()
            .and().authorizeRequests()
            .antMatchers("/**").authenticated()
            .anyRequest().permitAll()
            .and()
            .oauth2ResourceServer()
            .jwt()
            .jwtAuthenticationConverter(getJwtAuthoritiesConverter());
            

    }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-11-18 16:28:19

正在使用AndRequestMatcher初始化requireCsrfProtectionMatcher,因为您正在使用oauth2ResourceServer().jwt()

oauth2ResourceServer DSL告诉CsrfFilter忽略包含Bearer令牌的请求。您可以在source code中查看它。

由于JWT身份验证是无状态的,因此请求中不需要CSRF令牌。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70019432

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档