@固定投AccessDeniedException虽然角色是正确的
-
22-07-2019 - |
题
后解决所有 认证有关的问题 在我的第一个弹簧网应用程序,我现在坚持与授权。
使用配置 @Secured
注解是相当直接的,所以我不认为我犯了一个错误在这里。此外,我使用的一个活动的目录使用LDAP认证提供者和分配角色的广告小组,因此不是一个问题。
所以这里有一个简短的摘要我的问题:
- 无担保的行动 工作
- 行动使用
@Secured("IS_AUTHENTICATED_FULLY")
工作 - 行动使用的东西喜欢
@Secured("GROUP_*")
不工作
打电话时,一个安全的行动 org.springframework.security.AccessDeniedException
被抛出。这里有一个摘录日志:
DEBUG: org.springframework.security.intercept.AbstractSecurityInterceptor - Secure object: ReflectiveMethodInvocation: public org.springframework.web.servlet.ModelAndView de.dillinger.resources.controllers.HostsController.index(); target is of class [de.dillinger.resources.controllers.HostsController]; ConfigAttributes: [GROUP_IT]
DEBUG: org.springframework.security.intercept.AbstractSecurityInterceptor - Previously Authenticated: org.springframework.security.providers.UsernamePasswordAuthenticationToken@2a5333d9: Principal: org.springframework.security.userdetails.ldap.Person@1422384: Username: di32001; Password: [PROTECTED]; Enabled: true; AccountNonExpired: true; credentialsNonExpired: true; AccountNonLocked: true; Granted Authorities: GROUP_ITS, GROUP_ITS-IT, GROUP_INTERNET, GROUP_SYSTEMGRUPPE, GROUP_IT; Password: [PROTECTED]; Authenticated: true; Details: org.springframework.security.ui.WebAuthenticationDetails@0: RemoteIpAddress: 127.0.0.1; SessionId: 773943FFB14E512872BB6CE25F46C00A; Granted Authorities: GROUP_ITS, GROUP_ITS-IT, GROUP_INTERNET, GROUP_SYSTEMGRUPPE, GROUP_IT
正如你可以看到行动要求的 GROUP_IT
角色和我的用户对象具有这个特权。我真的不知道是什么引起这一问题。
解决方案
你使用 org.springframework.security.access.vote.UnanimousBased
作选民?试图改变它 org.springframework.security.access.vote.AffirmativeBased
.
这种问题是相关的作用,选民的构成。
编辑1(例增加):
<security:global-method-security
secured-annotations="enabled"
access-decision-manager-ref="accessDecisionManager"
/>
<bean
id="accessDecisionManager"
class="org.springframework.security.access.vote.AffirmativeBased">
<property name="allowIfAllAbstainDecisions" value="false" />
<property name="decisionVoters">
<list>
<bean id="roleVoter" class="org.springframework.security.access.vote.RoleVoter" />
</list>
</property>
</bean>
不隶属于 StackOverflow