正则表达式在Spring Security上下文中用于查询。

huangapple go评论69阅读模式
英文:

Regular expression in spring security context for query

问题

我尝试在我的Spring安全上下文XML中匹配这个URL:

/settings/folder_0+folder_1+folder_2.yaml?tag=test

我尝试了:

<s:intercept-url pattern="/settings/(.)([+]?).yaml?tag=test" access="hasAnyRole('ROLE')"/>

但它不起作用。我无法找出我犯了哪个错误。

有人能帮助我吗?

如果可能的话,我想改进这个正则表达式,以接受不同的格式,比如yaml、json等,以及接受任何标签名称。

谢谢 正则表达式在Spring Security上下文中用于查询。

英文:

I try to match this url in my spring security context xml:

> /settings/folder_0+folder_1+folder_2.yaml?tag=test

I tried :

> <s:intercept-url pattern="/settings/(.)([+]?).yaml?tag=test" access="hasAnyRole("ROLE")"/>

But it doesn't works. I can't figure out where I made a mistake.

Can someone help me ?

If it's possible I want to improve this regex in order to accept different format like yaml, json, ... and in order to accept any tag name.

Thank you 正则表达式在Spring Security上下文中用于查询。

答案1

得分: 1

您的Spring Security上下文XML中的正则表达式存在一些问题。

其次,模式中的问号(?)在正则表达式中也有特殊含义,因此也应该进行转义。

以下是一个经过修订的正则表达式,应该可以匹配您提供的URL:

<intercept-url pattern="/settings/.*\\.(yaml|json)\\?tag=.*" access="hasAnyRole('ROLE')" />
英文:

There are a couple of issues with the regular expression in your Spring Security context XML.

Second, the question mark (?) in the pattern also has a special meaning in regular expressions and should be escaped as well.

Here's a revised regex that should match the URL you provided:

&lt;intercept-url pattern=&quot;/settings/.*\\.(yaml|json)\\?tag=.*&quot; access=&quot;hasAnyRole(&#39;ROLE&#39;)&quot; /&gt;

huangapple
  • 本文由 发表于 2023年3月7日 00:56:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/75653665.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定