Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/373.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 预授权(“isAuthenticated()”)不在RestController上工作_Java_Json_Rest_Spring Security_Uri - Fatal编程技术网

Java 预授权(“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>

我发现了许多类似的问题,但都没有解决我的问题我的问题是: 预授权(“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> 

但不工作任何用户都可以使用此资源。

通过
@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)