【问题标题】:Webflux statuscode can not be changedWebflux 状态码无法更改
【发布时间】: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


【解决方案1】:

好的,这几天测试了这么多东西,我解决了它只是将“SecurityWebFiltersOrder”更改为“SecurityWebFiltersOrder.AUTHORIZATION”

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-01-11
    • 2020-08-11
    • 2018-12-22
    • 2023-03-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多