如何跳过特定方法在spring mvc中进行身份验证。我的spring_security.xml
文件包含:
<http auto-config="true" use-expressions="true">
<intercept-url pattern="/logout" access="permitAll"/>
<intercept-url pattern="/login" access="permitAll"/>
<intercept-url pattern="/**" access="hasRole('ROLE_USER')"/>
<logout logout-success-url="/logoutPage" logout-url="/logout" />
<form-login authentication-failure-url="/login?auth=fail"
login-page="/login"
login-processing-url="/loginPage"
password-parameter="password"
username-parameter="username"
/>
</http>
<global-method-security secured-annotations="enabled" pre-post-annotations="enabled" />
现在,我如何使用annotation
@Controller
public class DataController {
@PreAuthorize("permitAll")
@RequestMapping(value = "/data/info", method = RequestMethod.GET, headers = "Content-Type=application/json")
public @ResponseBody String getDetails() {
// some code
}
}
我用的不起作用。感谢。
答案 0 :(得分:1)
Spring安全性有两个级别的安全性:
intercept-url
元素管理的基于URL的安全性PreAuthorize
注释进行管理。您可以将两者混合使用,方法安全性可以用于非常精细的规则,特别是ACL,可以应用于服务或模型方法,但不能用于覆盖基于URL的限制。
答案 1 :(得分:0)
你做不到。在控制器注释之前评估intercept-url
。
但是,您可以通过在xml中添加以下内容来解决此问题:
<intercept-url pattern="/data/info" access="permitAll"/>
@PreAuthorize("permitAll")
毫无意义,因为它基本上是无操作。
答案 2 :(得分:0)
尝试使用类似的东西
<http pattern="/data/info**" security="none"/>