【发布时间】:2013-07-06 11:48:44
【问题描述】:
我有一个自定义身份验证提供程序,它返回 'AbstractAuthenticationTokenwithROLE_ADMINonly. I have a method annotated with@PreAuthorize("hasRole('ROLE_USER')")` 的具体实现。我正在尝试设置角色层次结构,以让我的管理员用户访问此方法。
我的 spring-security.xml 中有以下内容:
<beans:bean id="roleHierarchy" class="org.springframework.security.access.hierarchicalroles.RoleHierarchyImpl">
<beans:property name="hierarchy">
<beans:value>
ROLE_ADMIN > ROLE_USER
</beans:value>
</beans:property>
</beans:bean>
<beans:bean id="methodExpressionHandler" class="org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler">
<beans:property name="roleHierarchy" ref="roleHierarchy" />
</beans:bean>
<sec:global-method-security pre-post-annotations="enabled">
<sec:expression-handler ref="methodExpressionHandler" />
</sec:global-method-security>
对受保护方法的请求被拒绝,但如果我将注释更改为 @PreAuthorize("hasRole('ROLE_ADMIN')"),它会起作用。
我在AccessDeniedException 上设置了一个断点,它是从AffirmativeBased.decide(...) 抛出的。问题似乎是PreInvocationAuthorizationAdviceVoter 的expressionHandler 是null。这表明我的 roleHierarchy 或 methodExpressionHandler 的连接有问题。
我的 spring-security.xml 有什么明显的问题吗?我对这些东西应该如何工作有什么误解吗?
【问题讨论】:
标签: java spring-security