微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

AntPathRequestMatcher与通配符不匹配字符串

如何解决AntPathRequestMatcher与通配符不匹配字符串

我有一个SpringBoot应用程序,并且想要检测正在调用的活动端点,因此我可以允许该请求未经身份验证。

当我发出此请求时:

http://localhost:8080/001/MyApp/actuator/health/liveness

下面的代码显示false

new AntPathRequestMatcher("/**liveness")是否会导致isWhitelisted返回true

public RequestMatcher getRequestMatcher() {
  return new OrRequestMatcher(
    new AntPathRequestMatcher("/error"),new AntPathRequestMatcher("/login**"),new AntPathRequestMatcher("/**logout"),new AntPathRequestMatcher("/**liveness"));
}

public boolean isWhitelisted(HttpServletRequest httpServletRequest) {
  return getRequestMatcher().matches(httpServletRequest);
}
System.out.println(requestPropertyResolver.isWhitelisted(httpServletRequest));

解决方法

相反,需要此:

return new OrRequestMatcher(
        new AntPathRequestMatcher("/error"),new AntPathRequestMatcher("/login**"),new AntPathRequestMatcher("/**logout"),new AntPathRequestMatcher("/**/liveness"));

/**/-匹配路径中的零个或多个“目录”,因此需要结束目录树

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。