如何在 spring gateway 中以性能方式忽略 url

问题描述 投票:0回答:0

我已经在 spring 网关中定义了一个

JwtAuthenticationGatewayFilter
,现在我定义了一个列表来存储需要忽略的 url 和有效的令牌,如下所示:

public static Predicate<ServerHttpRequest> isApiSecured;

    @PostConstruct
    public void initExcludePath(){
       isApiSecured = r -> {
            List<String> excludeList = loginExcludeUrl.getExclude();
            return excludeList.stream()
                .noneMatch(uri -> r.getURI().getPath().equals(uri));};
    }

loginExcludeUrl.getExclude()
将获得忽略 url 列表(数百或数千)。当在过滤器中使用此功能知道是否忽略 url 时:

if (isApiSecured.test(request)) {
     return authImpl(request, exchange, chain);
}

我担心当忽略列表增加时,整个网站的性能会变慢,因为每个请求都应该应用列表过滤器。有没有更好的方法来忽略 url?

java gateway
© www.soinside.com 2019 - 2024. All rights reserved.