2011-10-24 5 views
2

私はquestionのようにSpring Securityで役割階層を使用しています。 @PreAuthorize("hasRole('ROLE_USER')")でメソッドを保護しようとすると、私はいつもAccessDeniedExceptionを取得します。ただし、私が@Secured("ROLE_USER")または@ PreAuthorizeとRoleHierarchyVoter

<protect-pointcut 
     expression="execution(* my.package.Class.*(..))" 
     access="ROLE_GUEST" /> 

に変更した場合、私は問題ありません。このanswerから、上記の違いを除いて、両方とも同じように動作するはずです。私はここに何かを逃していますか

編集: これは私の設定です。

<?xml version="1.0" encoding="UTF-8"?> 
<beans:beans xmlns="http://www.springframework.org/schema/security" 
    xmlns:beans="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:context="http://www.springframework.org/schema/context" 
    xsi:schemaLocation=" 
     http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
     http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd 
     http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.xsd"> 

    <http entry-point-ref="entryPoint"> 
    <anonymous enabled="false" /> 
    </http> 

    <beans:bean id="entryPoint" 
    class="org.springframework.security.web.authentication.Http403ForbiddenEntryPoint" /> 

    <global-method-security secured-annotations="enabled" 
    pre-post-annotations="enabled" access-decision-manager-ref="accessDecisionManager"> 
    <!-- this is disable if I secure with annotation @Secured --> 
    <protect-pointcut 
     expression="execution(* my.package.Class.*(..))" 
     access="ROLE_GUEST" /> 
    </global-method-security> 

    <beans:bean id="accessDecisionManager" 
    class="org.springframework.security.access.vote.AffirmativeBased"> 
    <beans:property name="decisionVoters"> 
     <beans:list> 
     <beans:ref bean="roleHierarchyVoter" /> 
     </beans:list> 
    </beans:property> 
    </beans:bean> 

    <beans:bean id="roleHierarchyVoter" 
    class="org.springframework.security.access.vote.RoleHierarchyVoter"> 
    <beans:constructor-arg ref="roleHierarchy" /> 
    </beans:bean> 

    <beans:bean id="roleHierarchy" 
    class="org.springframework.security.access.hierarchicalroles.RoleHierarchyImpl"> 
    <beans:property name="hierarchy"> 
     <beans:value> 
     ROLE_USER > ROLE_GUEST 
     </beans:value> 
    </beans:property> 
    </beans:bean> 

    <beans:bean id="userDetailsService" 
    class="org.springframework.security.core.userdetails.jdbc.JdbcDaoImpl"> 
    <beans:property name="dataSource" ref="dataSource" /> 
    <beans:property name="enableGroups" value="true" /> 
    <beans:property name="enableAuthorities" value="false" /> 
    </beans:bean> 

    <authentication-manager> 
    <authentication-provider user-service-ref="userDetailsService"> 
    </authentication-provider> 
    </authentication-manager> 

</beans:beans> 
+0

[documentation](http://static.springsource.org/spring-security/site/docs/3.1.x/reference/ns-config.html#ns-global-method)によると、あなたの 'global-method-security'要素の' pre-post-annotations': ''です。あなたはそれをやっていますか? – bluefoot

+0

@bluefoot、はい、私は両方のsecured-annotations = "enabled" pre-post-annotations = "enabled"を追加しました –

答えて

0

あなたの設定が他の投稿を参照しているように見えるかどうかはわかりません。解決策は簡単かもしれません。 access-decision-manager-refアウト残す:Pre*/Post*注釈は、メソッドのセキュリティのために使用されている場合、実際には

<sec:global-method-security 
    secured-annotations="enabled" pre-post-annotations="enabled" /> 

を、有権者ベースのシステムが本当に必要ではありません。実際にはそのための有権者は全くいないので、他のすべての有権者は棄権し、アクセスは拒否されます。

+0

RoleHierarchyVoterまたはaccess-decision-manager-refを削除すると、AccessDeniedExceptionが発生します。 –

+0

@CKLee:完全なSpring設定 – jeha

+0

を私の設定に追加してください。 –

関連する問題