小编Ale*_*tea的帖子

Spring WebFlux添加WebFIlter以匹配特定路径

在Spring Boot应用程序的上下文中,我试图添加WebFilter以仅过滤与特定路径匹配的请求。

到目前为止,我有一个过滤器:

    @Component
    public class AuthenticationFilter implements WebFilter {

        @Override
        public Mono<Void> filter(ServerWebExchange serverWebExchange,
                             WebFilterChain webFilterChain) {
        final ServerHttpRequest request = serverWebExchange.getRequest();

            if (request.getPath().pathWithinApplication().value().startsWith("/api/product")) {
               // logic to allow or reject the processing of the request
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)

我想要达到的目的是从过滤器中删除匹配的路径,并将其添加到更合适的其他位置,例如,到目前为止,我已经阅读了SecurityWebFilterChain

非常感谢!

java spring-security spring-webflux

5
推荐指数
1
解决办法
704
查看次数

标签 统计

java ×1

spring-security ×1

spring-webflux ×1