繁体   English   中英

正则表达式与 antMatcher URL 模式不匹配

[英]Regex doesn't match antMatcher URL pattern

我试图忽略身份验证中的 url 我尝试了多种不同的模式,但 java 似乎无法识别它们。 我的配置是这样的:

  @Override
  public void configure(WebSecurity web) throws Exception {
    super.configure(web);
    web.ignoring().antMatchers(
            "/api/pies.*active=true");
  }

我想匹配并让 spring 安全忽略的字符串是这样的:http://"someEnv"/"somePath"/api/pies?active=true

但是无论我尝试什么通配符组合,它都不匹配。 匹配必须有 ?active=true

下面是方法定义:

    @GetMapping()
    public ResponseEntity<List<PieResponseDto>> getPies(@RequestParam(name = "active") Boolean active) 

下面是类定义:


@RestController
@RequestMapping(path = "/api/pies", produces = MediaType.APPLICATION_JSON_VALUE)

使用.regexMatchers而不是.antMatchers然后试试这个正则表达式:

^[a-zA-Z:\/.]*pies\?active=true$

有很多用于正则表达式的在线工具。 您可以尝试例如这个:在线正则表达式测试器

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM