gpt4 book ai didi

Spring-security无法匹配 "?parameter"格式?

转载 作者:行者123 更新时间:2023-12-02 09:33:58 24 4
gpt4 key购买 nike

当我通过 spring-roo 在 applicationContext-security.xml 中生成的配置文件(位于<http>)学习它时,我使用 spring-security 来保护我的网络。节点:

 <intercept-url pattern="/userses?form" access="hasRole('ROLE_ADMIN')" />

这意味着当你想创建一个Users对象时,首先你需要登录并获得ADMIN权限。但实际上并没有起作用。检查日志:

2012-05-06 11:39:11,250 [http-8088-7] DEBUG org.springframework.security.web.util.AntPathRequestMatcher - Checking match of request : '/userses'; against '/userses?form'

框架使用/userses 而不是/userses?form 进行比较,由于字符串不匹配而跳过身份验证过程。为了验证这一点,我还尝试了另一个网址:

<intercept-url pattern="/userses/abc" access="hasRole('ROLE_ADMIN')" />

我请求/userses/abc,它检测到用户未授权,并移至/login页面,检查日志:

2012-05-06 11:46:44,343 [http-8088-7] DEBUG org.springframework.security.web.util.AntPathRequestMatcher - Checking match of request : '/uesrses/abc'; against '/userses/abc'

所以我的问题是:spring-secure 3不支持“?参数”模式还是我错过了一些配置来支持这个模式?PS:所有代码都是roo生成的,没有修改,也奇怪为什么不行。

最佳答案

默认spring security使用ant风格匹配,不能匹配参数。然而,正则表达式匹配可以匹配参数

尝试像这样定义它:

<http request-matcher="regex">
<security:intercept-url pattern="\A/userses\?form.*\Z" access="hasRole('ROLE_ADMIN')" />
</http>

不知道为什么 Roo 不自动执行此操作。看起来应该如此。

关于Spring-security无法匹配 "?parameter"格式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10467930/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com