【发布时间】:2022-11-26 16:08:45
【问题描述】:
以下安全Web过滤器链在 Spring Boot 2.7.x 中工作得很好,但在 Spring Boot 3.0.0 中不再工作。它只是显示“找不到预期的 CSRF 令牌” 在 Postman 中调用 REST API 时。请教我如何解决它好吗?
@Bean
public SecurityWebFilterChain securitygWebFilterChain(ServerHttpSecurity http) {
http
.cors().disable()
.csrf().disable()
.exceptionHandling()
.authenticationEntryPoint((swe, e) ->
Mono.fromRunnable(() -> swe.getResponse().setStatusCode(HttpStatus.UNAUTHORIZED))
).accessDeniedHandler((swe, e) ->
Mono.fromRunnable(() -> swe.getResponse().setStatusCode(HttpStatus.FORBIDDEN))
)
.and()
.authenticationManager(authenticationManager)
.securityContextRepository(securityContextRepository)
.authorizeExchange(exchange -> exchange
.pathMatchers(HttpMethod.OPTIONS).permitAll()
.pathMatchers("/login", "/register").permitAll()
.anyExchange().authenticated()
.and()
.cors().disable()
.csrf().disable()
)
.formLogin().disable()
.httpBasic().disable()
;
return http.csrf(csrf -> csrf.disable()).build();
}
【问题讨论】:
-
您确定正在接收这个
SecurityWebFilterChain而不是另一个?
标签: spring-boot spring-security csrf spring-boot-3