java - 正则表达式与 antMatcher URL 模式不匹配
问题描述
我试图忽略身份验证中的 url 我尝试了多种不同的模式,但 java 似乎无法识别它们。我的配置如下所示:
@Override
public void configure(WebSecurity web) throws Exception {
super.configure(web);
web.ignoring().antMatchers(
"/api/pies.*active=true");
}
我想匹配并忽略弹簧安全的字符串是这样的:http://"someEnv"/"somePath"/api/pies?active=true
但是,无论我尝试什么通配符组合,它都不匹配。比赛必须有 ?active=true
下面是方法def:
@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
推荐阅读
- drupal - 将 drupal 6 迁移到 drupal 8
- django - 使用 NLTK 提取名词和动词
- regex - 正则表达式重复
- angular - 继续检测对从数组创建的可观察对象的更改
- matlab - 如何在 GNU Octave 中获取当前脚本路径?
- javascript - 无法将我的项目连接到 heroku
- mysql - MySQL 8 - JSON_ARRAYAGG 中的排序和过滤
- docker - 无法登录 Docker 帐户
- php - 我无法使用 PHP 在 FTP 服务器上工作,连接正常,但我无法获取文件或其他内容。它适用于 FileZilla
- javascript - 以gzip格式发送数据导致ajax进度停止一段时间