本文介绍了Spring-security - AccessDecisionVoter-impl不会被调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在尝试创建自定义的AccessDecisionVoter,并在调用它时调试它。


I am trying to create custom AccessDecisionVoter and just stop it in the debugged when it gets invoked.

我已经设置了一个断点在每种方法中,但都没有发生。

I have put a breake point in each method, but nothing happed.

spring-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,应用程序加载期间没有抛出异常/运行
谢谢

BTW, there were no exceptions thrown during app loading / runningThanks

推荐答案

您需要使用自定义AccessDecisionManager,否则使用默认值。您可以使用

You need to use your custom AccessDecisionManager, otherwise the default one is used. You can do this with

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

看看以获取更多相关信息。

Take a look at the documentation for more information on this.

还有一件事:你的选民中的支持()方法应该返回 true 否则 vote()不会被叫。

One more thing: The supports() methods in your voter should probably return true otherwise vote() won`t be called.

这篇关于Spring-security - AccessDecisionVoter-impl不会被调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-09 22:43