@Secured يطرح AccessDeniedException على الرغم من صحة الأدوار
-
22-07-2019 - |
سؤال
بعد حل جميع المشاكل المتعلقة بالمصادقة في أول تطبيق ويب خاص بي في Spring، أصبحت الآن عالقًا في عملية التفويض.
التكوين باستخدام @Secured
التعليقات التوضيحية واضحة جدًا، لذا لا أعتقد أنني ارتكبت خطأً هنا.بالإضافة إلى ذلك، أستخدم Active Directory باستخدام موفر مصادقة 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
role وكائن المستخدم الخاص بي يتمتع بهذا الامتياز.أنا حقا لا أعرف ما الذي يسبب هذه المشكلة.
المحلول
هل تستخدم 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>