【发布时间】:2014-09-16 01:27:40
【问题描述】:
我有一组通过使用 Spring-data-rest 项目在 Rest 上公开的 Sping 数据存储库。现在我想保护 HTTP,以便只有注册用户才能访问 http://localhost:8080/rest/ 所以为此我将 @Secured(value = { "ROLE_ADMIN" }) 添加到所有存储库中,我还通过指定
@EnableGlobalMethodSecurity(securedEnabled = true, jsr250Enabled = true, prePostEnabled = true)
所以现在发生的事情是我去休息,一切都很好 - 我被要求进行身份验证。接下来我要做的是访问我的网站(它使用所有存储库来访问数据库),但我的请求失败了
nested exception is org.springframework.security.authentication.AuthenticationCredentialsNotFoundException: An Authentication object was not found in the SecurityContext
这是正确的,因为我以匿名用户身份浏览我的网站。
所以我的问题是:有没有办法只为 REST 层提供方法身份验证?对我来说,这听起来像是需要一个新的注释(比如@EnableRestGlobalMethodSecurity 或@EnableRestSecurity)
【问题讨论】:
标签: spring-security spring-data-rest