簡體   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