【发布时间】:2018-10-23 20:05:46
【问题描述】:
所以我有一个 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
然后状态变为“COMMITTED”,当我调用时
AbstractServerHttpResponse#setStatusCode
无法更改。
可以在提交前更改 statusCode 吗?
build.gradle
编译('org.springframework.boot:spring-boot-starter-webflux') 编译('org.springframework.security:spring-security-web') 编译('org.springframework.security:spring-security-config')
【问题讨论】:
-
您可以添加解决方案并接受它作为答案吗?
标签: spring-security kotlin spring-webflux