2011-03-13 82 views
4


我想創建自定義的AccessDecisionVoter,並在被調用時停止調試。Spring-security - AccessDecisionVoter-impl不會被調用

我在每種方法中都放了一個breake點,但沒有發現。

彈簧security.xml文件:

<bean id="accessDecisionManager" class="org.springframework.security.access.vote.UnanimousBased"> 
    <property name="decisionVoters"> 
    <list> 
      <bean class="com.affiliates.server.security.voters.VoterTest"> 
       <property name="brandsApi" ref="brandsApi"/> 
      </bean> 
     </list> 
    </property> 

IBrandsApi.java

public interface IBrandsApi { 

    IHibernateBean getByPK(Integer id); 

    @Secured({ "ROLE_BRAND_ADMIN" })  
    IHibernateBean update(IHibernateBean brand); 

    @Secured({ "ROLE_BRAND_ADMIN" })  
    IHibernateBean insert(IHibernateBean brand); 

    @Secured({ "ROLE_BRAND_ADMIN" })  
    ResultContainer getAll(IFilter filter); 

    @Secured({ "ROLE_ADMIN" }) 
    Integer delete(IFilter filter); 
} 

VoterTest.java(帶斷點空文件)

public class VoterTest implements AccessDecisionVoter { 
private IBrandsApi brandsApi; 

    public IBrandsApi getBrandsApi() { 
     return brandsApi; 
    } 

    public void setBrandsApi(IBrandsApi brandsApi) { 
     this.brandsApi = brandsApi; 
    } 

     @Override 
     public boolean supports(ConfigAttribute attribute) { 
      System.out.println("here"); 
      return false; 

     } 

     @Override 
     public boolean supports(Class<?> clazz) { 
      System.out.println("here"); 
      return false; 
     } 

     @Override 
     public int vote(Authentication authentication, Object object, 
       Collection<ConfigAttribute> attributes) { 
      System.out.println("here"); 
      return 0; 
     } 
    } 

BTW,有應用程序加載過程中引發/運行 感謝

+0

您是否擁有<全局方法安全性secured-annotations =「enabled」/>? – 2011-03-13 11:07:27

+0

是的,我可以使用註釋和@Autowire spring beans,謝謝 – fatnjazzy 2011-03-13 11:11:14

回答

6

您需要使用您的自定義的AccessDecisionManager沒有例外,否則,一個是使用默認值。你可以用

<global-method-security access-decision-manager-ref="accessDecisionManager"/> 

做到這一點看看the documentation更多這方面的信息。

還有一件事:你的選民的supports()方法可能應該返回true否則vote()不會被調用。

+0

謝謝!加工 – fatnjazzy 2011-03-13 11:29:32