gpt4 book ai didi

java - Spring AntRequestMatcher 不匹配

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:16:49 28 4
gpt4 key购买 nike

我有一个关于 Ant 匹配器的问题。我想创建一个不应用于特定 URL 的 spring 安全过滤器。

要忽略此 url,我正在使用 AntPathRequestMatcher:

AntPathRequestMatcher ignored = new AntPathRequestMatcher("**/MyURL/**");

其实我认为它会匹配所有包含“MyURL”的 URL。但我错了。

if(ignored.matches(httpReq)) {
log.info(ignored.toString()+" matches "+httpReq.getRequestURI());
} else {
log.info(ignored.toString()+" does not match "+httpReq.getRequestURI());
}

上面的 if 部分带给我

Ant [pattern='**/myurl/**'] does not match /resource/MyURL/

在我发出请求时登录。花纹should be case unsensitive .

最佳答案

作为@M. Deinum编写的模式必须以 / 开头,请参阅 AntPathMatcher :

Note: a pattern and a path must both be absolute or must both be relative in order for the two to match. Therefore it is recommended that users of this implementation to sanitize patterns in order to prefix them with "/" as it makes sense in the context in which they're used.

AntPathMatcher#doMatch :

protected boolean More ...doMatch(String pattern, String path, boolean fullMatch, Map<String, String> uriTemplateVariables) {
if (path.startsWith(this.pathSeparator) != pattern.startsWith(this.pathSeparator)) {
return false;
}

关于java - Spring AntRequestMatcher 不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34266595/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com