所以我有一个AuthenticationWebFilter可以在有人进行身份验证时添加触发器:
val builder : HttpSecurity.AuthorizeExchangeBuilder = http
.addFilterAt(
CustomAuthenticationWebFilter(securityContextRepository),
SecurityWebFiltersOrder.AUTHENTICATION
)
.authorizeExchange().permitAll()
然后在" CustomAuthenticationWebFilter"我用一些逻辑改变了statusCode,像这样:
override fun filter(exchange: ServerWebExchange, chain: WebFilterChain): Mono<Void> {
return super.filter(exchange, chain)
.doOnSuccess {
exchange.response.statusCode = UNAUTHORIZED
return@doOnSuccess
}
关键是,当我正在做请求时,流程将转到WebFilter之前
AbstractServerHttpResponse#doCommit
然后状态变为&#34;委托&#34;当我打电话给
AbstractServerHttpResponse#setStatusCode
它无法改变它。
可以在提交之前更改statusCode吗?
的build.gradle
编译(&#39; org.springframework.boot:弹簧引导起动webflux&#39;) 编译(&#39; org.springframework.security:弹簧安全的web&#39;) 编译(&#39; org.springframework.security:弹簧安全配置&#39)
答案 0 :(得分:0)
好的,这几天测试了很多东西之后,我解决了它只是将“SecurityWebFiltersOrder”更改为“SecurityWebFiltersOrder.AUTHORIZATION”