英文:
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等,以及接受任何标签名称。
谢谢
英文:
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
答案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:
<intercept-url pattern="/settings/.*\\.(yaml|json)\\?tag=.*" access="hasAnyRole('ROLE')" />
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论