gpt4 book ai didi

spring-security - Spring Cloud Gateway POST 禁止

转载 作者:行者123 更新时间:2023-12-04 10:18:28 25 4
gpt4 key购买 nike

我在带有 RelayToken 过滤器的 Cloud Gateway 路由后面有一个资源服务:

      routes:
- id: apis
uri: http://rest-app:8080/apis
predicates:
- Path=/apis/**
filters:
- TokenRelay=

GET 请求工作正常,但在 POST 上我收到 403 Forbidden 响应正文包含CSRF Token 已关联到此客户端我试图通过添加 Bean

来禁用 CSRF 保护
@Bean
fun springWebFilterChain(http: ServerHttpSecurity): SecurityWebFilterChain {
return http.csrf().disable().cors().disable().build()
}

但这没有效果,我仍然得到 403。此外,我无法调试到底是哪个过滤器阻止客户端执行 POST 请求,这是我获得的唯一日志记录信息

logging:
level:
root: INFO
org.springframework.web: TRACE
org.springframework.security: TRACE
org.springframework.security.oauth2: TRACE
org.springframework.cloud.gateway: TRACE
org.springframework.security.jwt: TRACE

只是几行说 POST 被禁止

[2020-04-01 13:21:32,635] TRACE o.s.w.s.a.HttpWebHandlerAdapter  - [58a0e540-10] HTTP POST "/apis/", headers={masked} 
[2020-04-01 13:21:32,640] TRACE o.s.w.s.a.HttpWebHandlerAdapter - [58a0e540-10] Completed 403 FORBIDDEN, headers={masked}
[2020-04-01 13:21:32,640] TRACE o.s.h.s.r.ReactorHttpHandlerAdapter - [58a0e540-10] Handling completed

如何正确关闭 CSRF?

最佳答案

正确的 SecurityWebFilterChain 解决了我的问题:

@Bean
fun springWebFilterChain(http: ServerHttpSecurity): SecurityWebFilterChain {
return http
.authorizeExchange().anyExchange().authenticated()
.and()
.oauth2Login()
.and()
.csrf().disable()
.build()
}

关于spring-security - Spring Cloud Gateway POST 禁止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60971877/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com