在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。
非常感谢!