Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.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
Spring Security@RoleAllowed可以工作,但是@Secured在Spring 3.2和Spring Security 3.1中给了我AccessDeniedException_Spring_Spring Mvc_Spring Security - Fatal编程技术网

Spring Security@RoleAllowed可以工作,但是@Secured在Spring 3.2和Spring Security 3.1中给了我AccessDeniedException

Spring Security@RoleAllowed可以工作,但是@Secured在Spring 3.2和Spring Security 3.1中给了我AccessDeniedException,spring,spring-mvc,spring-security,Spring,Spring Mvc,Spring Security,我遇到了一个问题,我的控制器方法@RolesAllowed工作正常,但如果我尝试使用@Secured,我会得到一个AccessDeniedException。虽然我更喜欢使用@RolesAllowed注释,但是已经声明,对于这个项目,我们应该使用@Secured,因为这个名称在映射到我们的传统访问权限时比较容易混淆 我将注释配置如下: <security:global-method-security jsr250-annotations="enabled" secured-annotati

我遇到了一个问题,我的控制器方法@RolesAllowed工作正常,但如果我尝试使用@Secured,我会得到一个AccessDeniedException。虽然我更喜欢使用@RolesAllowed注释,但是已经声明,对于这个项目,我们应该使用@Secured,因为这个名称在映射到我们的传统访问权限时比较容易混淆

我将注释配置如下:

<security:global-method-security jsr250-annotations="enabled" secured-annotations="enabled" pre-post-annotations="enabled" />


当我使用我的用户拥有的
@RolesAllowed(“公司报告”)
时,它工作正常。当我使用
@Secured(“COMPANY\u SEE\u REPORTS”)
时,我会得到一个AccessDeniedException。为了确保@RolesAllowed正常工作,我将角色更改为一个不存在的角色,此时@RolesAllowed抛出。因此,我的问题是如何让@securied正常工作?

尝试使用名称以
role
结尾的安全角色

:

RoleVoter

Spring提供了最常用的AccessDecisionVoter 安全性是处理配置的简单RoleVoter 如果用户 已被分配该角色

如果任何ConfigAttribute以前缀ROLE开头,它将进行投票。It 如果有授权机构返回,将投票授予访问权限 字符串表示(通过getAuthority()方法)完全相等 指向一个或多个以前缀ROLE开头的ConfigAttributes。如果 任何以角色\开头的ConfigAttribute都不完全匹配, RoleVoter将投票拒绝访问。如果没有开始配置属性 有了投票权,选民将弃权


但是您可以修改RoleVoter前缀,这对于我们的系统来说并不是一个真正的选项。角色的含义在这里不太适用,在我们的系统中,他们会称之为权利(角色是集合或权利)。我们有太好的细粒度的安全模型,我们想要打开个人的权利,而不仅仅是在角色层面。我没有尝试工作,因为从我的公司的角度来看,他们不认为它是一个角色,他们认为这是正确的(因为我们在这里有非常细粒度的权利)。我们现在只使用允许的角色选项。稍后我可能会深入研究spring源代码,看看他们是否需要角色来使用@Secured。