我想为除一个 url 之外的整个应用程序启用 oauth2。
我的配置:
@EnableWebFluxSecurity
class SecurityConfig {
@Bean
fun securityWebFilterChain(http: ServerHttpSecurity) =
http
.authorizeExchange()
.pathMatchers("/devices/**/register").permitAll()
.and()
.oauth2Login().and()
.build()
}
应用程序.yml:
spring.security.oauth2.client.registration.google.client-id: ...
spring.security.oauth2.client.registration.google.client-secret: ...
所有路径都受到 oauth2 保护,但问题是当我调用允许的端点时/devices/123/register
然后我得到的回应是:
CSRF Token has been associated to this client
我需要以不同的方式配置该路径吗?
permitAll
是一个仅关于权威的声明——所有典型的 Web 应用程序漏洞仍然受到缓解,如 XSS 和 CSRF。
如果你试图表明这一点/devices/**/register
应该被 Spring Security 完全忽略,那么你可以这样做:
http
.securityMatcher(new NegatedServerWebExchangeMatcher(
pathMatchers("/devices/**/register")))
... omit the permitAll statement
但是,如果您仍然希望该端点获取安全响应标头,而不是 CSRF 保护,那么您可以执行以下操作:
http
.csrf()
.requireCsrfProtectionMatcher(new NegatedServerWebExchangeMatcher(
pathMatchers("/devices/**/register")))
... keep the permitAll statement
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)