CsrfFilter有一个验证
if (!this.requireCsrfProtectionMatcher.matches(request)) {
filterChain.doFilter(request, response);
return;
}在上面的代码片段中,this.requireCsrfProtectionMatcher被初始化为AndRequestMatcher。但我只想使用DefaultRequiresCsrfMatcher。谁能提供更多关于这方面的信息?我的安全配置
@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());
}发布于 2021-11-18 16:28:19
正在使用AndRequestMatcher初始化requireCsrfProtectionMatcher,因为您正在使用oauth2ResourceServer().jwt()。
oauth2ResourceServer DSL告诉CsrfFilter忽略包含Bearer令牌的请求。您可以在source code中查看它。
由于JWT身份验证是无状态的,因此请求中不需要CSRF令牌。
https://stackoverflow.com/questions/70019432
复制相似问题