简体   繁体   English

Spring Security正则表达式模式匹配器和'/'字符

[英]Spring security regex patern matcher and '/' character

In my spring security configuration I have 在我的春季安全配置中

<http auto-config="true" use-expressions="true" path-type="regex">
...
<intercept-url pattern="/admin/*" access="hasRole('ROLE_ADMIN')" />

This pattern matches the path "/admin" as well, even if this string is not produced by the regex "/admin/*" (there is no slash at the end). 即使该字符串不是由正则表达式“ / admin / *”生成的,此模式也与路径“ / admin”匹配(末尾没有斜杠)。 Why is that? 这是为什么? I found no documentation about it. 我没有找到任何文档。 Does regex path matching have any other peculiarity like this one? 正则表达式路径匹配是否还有其他类似之处? I am using Spring Security 3.0. 我正在使用Spring Security 3.0。

EDIT I obviously was mistaking " " for ". ". 编辑我显然误以为“。 ”。 Should have taken a nap instead of asking it here :) 应该小睡一下而不是在这里问:)

* in a regex means "match the preceding character zero or more times", so your regex does match the string "/admin". *在正则表达式中表示“将前面的字符匹配次或多次”,因此您的正则表达式确实与字符串“ / admin”匹配。

You probably want to use + which means "match the preceding character one or more times". 您可能要使用+ ,这意味着“ 一次或多次匹配前面的字符”。

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

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