Question

Après avoir résolu tous les problèmes liés à l'authentification dans Ma première application Web Spring, je suis maintenant bloquée avec une autorisation.

La configuration

à l'aide d'annotations @Secured est assez simple, je ne pense donc pas avoir commis d'erreur ici. De plus, j'utilise un annuaire Active Directory utilisant le fournisseur d'authentification LDAP et attribue des rôles par groupes AD. Ce n'est donc pas un problème.

Alors, voici un bref résumé de mon problème:

  • Les actions non sécurisées fonctionnent
  • Actions utilisant @Secured ("IS_AUTHENTICATED_FULLY") travail
  • Actions utilisant quelque chose comme @Secured ("GROUP _ *") ne fonctionne pas

Lors de l'appel d'une action sécurisée, une org.springframework.security.AccessDeniedException est levée. Voici un extrait des journaux:

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

Comme vous pouvez le constater, l'action requiert le rôle GROUP_IT et mon objet utilisateur possède ce privilège. Je ne sais vraiment pas ce qui cause ce problème.

Était-ce utile?

La solution

Utilisez-vous le org.springframework.security.access.vote.UnanimousBased ? Essayez de le remplacer par org.springframework.security.access.vote.AffirmativeBased .
Ce type de problèmes est lié à la configuration de l'électeur de rôle.

Modifier 1 (exemple ajouté):

<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>
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top