【发布时间】:2017-11-16 12:21:51
【问题描述】:
我发现了很多类似的问题,但没有一个能解决我的问题我的问题是: PreAuthorize("isAuthenticated()") 在我的 RestController 上不起作用。
我的配置安全性是:
<global-method-security pre-post-annotations="enabled"/>
<authentication-manager alias="authenticationManager">
<authentication-provider>
<password-encoder ref="passwordEncoder" />
<jdbc-user-service
data-source-ref="dataSource"
users-by-username-query="
select login,password,1
from test tst where tst.login=?"
authorities-by-username-query="
select login,'ROLE_SAVE' from test tst where tst.login=?"
/>
</authentication-provider>
</authentication-manager>
在我的 RestController 上我添加了这个注解:@PreAuthorize("isAuthenticated()")
@RestController
@PreAuthorize("isAuthenticated()")
@RequestMapping("/api/test")
public class PrinterController{
@RequestMapping(value = "", method = RequestMethod.GET)
public ResponseStatus test() {
System.out.println("test");
}
但不工作,任何用户都可以使用此资源。
【问题讨论】:
-
是的,我使用
启用它 -
尝试在
value属性中添加它:@PreAuthorize( value="isAuthenticated()") -
不行,我也有同样的问题
-
bean 的容器如何发现你的配置?在您的应用程序中,您有一个 servlet 配置(Web 上下文的一部分),并且您有包含持久性配置、安全配置等的应用程序上下文(或根上下文)...
-
并在我的 applicationContext 中添加以下行:
标签: java json rest spring-security uri