当我在<http>节点的applicationContext-security.xml中学习spring-roo生成的配置文件时,我使用spring-security来保护我的web:
<intercept-url pattern="/userses?form" access="hasRole('ROLE_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进行比较,由于字符串不匹配,身份验证过程被跳过。为了验证这一点,我还尝试了另一个url:
<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生成的,没有经过修改,也想知道为什么它不能工作。
发布于 2012-05-06 12:36:07
默认情况下,spring security使用ant样式匹配,它不能匹配参数。但是,正则表达式匹配可以在参数上匹配
试着这样定义它:
<http request-matcher="regex">
<security:intercept-url pattern="\A/userses\?form.*\Z" access="hasRole('ROLE_ADMIN')" />
</http>我不知道为什么Roo不自动这么做。看起来应该是这样。
发布于 2012-05-06 12:41:39
该行为由正在使用的"request-matcher"定义。如文档所示,缺省值为“AntPathRequestMatcher”,表示使用RegexRequestMatcher,另一种选择是"regex“。javadocs (链接的)给出了关于匹配器的细节,包括前者匹配请求的"servletPath + pathInfo",而后者匹配请求的"servletPath + pathInfo + queryString“。
https://stackoverflow.com/questions/10467930
复制相似问题