gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 05:33:19 24 4
gpt4 key购买 nike

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

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

我想要匹配并让 spring security 忽略的字符串是这样的: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$

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

关于java - 正则表达式与 antMatcher URL 模式不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57119334/

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