gpt4 book ai didi

java - @Secured 抛出 AccessDeniedException 尽管角色是正确的

转载 作者:行者123 更新时间:2023-12-02 08:36:49 24 4
gpt4 key购买 nike

解决完所有authentication related problems后在我的第一个 Spring Web 应用程序中,我现在陷入了授权的困境。

使用@Secured注释进行配置非常简单,所以我认为我在这里没有犯错误。此外,我使用的是使用 LDAP 身份验证提供程序的 Active Directory,并按 AD 组分配角色,因此也不是问题。

这是我的问题的简短摘要:

  • 不安全的操作工作
  • 使用 @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>

关于java - @Secured 抛出 AccessDeniedException 尽管角色是正确的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1443632/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com