Spring 安全正则表达式模式匹配器和“/”字符

Spring security regex patern matcher and '/' character

在我的 spring 安全配置中

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

此模式也匹配路径“/admin”,即使此字符串不是由正则表达式“/admin/*”生成的(末尾没有斜杠)。这是为什么?我没有找到关于它的文档。正则表达式路径匹配是否有其他类似的特性? 我正在使用 Spring 安全 3.0。

编辑 我显然把“”误认为是“.”。应该小睡一下而不是在这里问:)

* 在正则表达式中表示 "match the preceding character zero or more times",因此您的正则表达式确实匹配字符串“/admin”。

您可能想使用 +,这意味着 "match the preceding character one or more times"。