Java 预授权(“isAuthenticated()”)不在RestController上工作
我发现了许多类似的问题,但都没有解决我的问题我的问题是: 预授权(“isAuthenticated()”)无法在我的RestController上工作 我的配置安全性是:Java 预授权(“isAuthenticated()”)不在RestController上工作,java,json,rest,spring-security,uri,Java,Json,Rest,Spring Security,Uri,我发现了许多类似的问题,但都没有解决我的问题我的问题是: 预授权(“isAuthenticated()”)无法在我的RestController上工作 我的配置安全性是: <global-method-security pre-post-annotations="enabled"/> <authentication-manager alias="authenticationManager"> <authentication-provider>
<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>
但不工作任何用户都可以使用此资源。通过
@Secured
重新放置@PreAuthorize
并在安全xml文件中添加Secured annotations=“enabled”
后,问题已得到解决
<global-method-security secured-annotations="enabled"/>
您需要向安全配置类添加以下注释:
@EnableGlobalMethodSecurity(prePostEnabled = true)
感谢这篇文章:
是的,我通过尝试在
value
属性中添加它来启用它:@PreAuthorize(value=“isAuthenticated()”)
不起作用,我有同样的问题:bean的容器如何发现您的配置?在应用程序中,您有一个servlet配置(web上下文的一部分),您有一个包含持久性配置、安全性配置等的应用程序上下文(或根上下文)。在我的应用程序上下文中,我添加了以下行:
@Secured
@EnableGlobalMethodSecurity(prePostEnabled = true)