代码之家  ›  专栏  ›  技术社区  ›  bobbyrne01

AntPathRequestMatcher未将字符串与通配符匹配

  •  0
  • bobbyrne01  · 技术社区  · 6 年前

    我有一个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));
    
    0 回复  |  直到 6 年前
        1
  •  0
  •   bobbyrne01    6 年前

    需要这样做:

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

    /**/ 路径