Announcement Announcement Module
Collapse
No announcement yet.
Spring bean fails to be injected into custom decision voter Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring bean fails to be injected into custom decision voter

    Hi all!

    Problem in few words:
    For some reasons I need to validate current user against database data. To solve this I added custom decision voter. Then I injected desired bean into decision voter by using @Autowired annotation. As result my webbapp startup fails with long exception message.

    Code:
    ringframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.access.intercept.aopalliance.MethodSecu
    rityInterceptor#0': Invocation of init method failed; nested exception is java.lang.NullPointerException:
    java.lang.NullPointerException
            at org.springframework.security.access.vote.AbstractAccessDecisionManager.supports(AbstractAccessDecisionManager.java:129)
            at org.springframework.security.access.intercept.AbstractSecurityInterceptor.afterPropertiesSet(AbstractSecurityInterceptor.java:128)
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1514
    )
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1452)
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
            at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
            at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
            at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
            at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
            at org.springframework.security.access.intercept.aopalliance.MethodSecurityMetadataSourceAdvisor.getAdvice(MethodSecurityMetadataSourceAdvisor
    .java:96)
            at org.springframework.aop.support.AbstractPointcutAdvisor.getOrder(AbstractPointcutAdvisor.java:50)
            at org.springframework.core.OrderComparator.getOrder(OrderComparator.java:70)
            at org.springframework.core.OrderComparator.compare(OrderComparator.java:58)
            at java.util.Arrays.mergeSort(Arrays.java:1270)
            at java.util.Arrays.sort(Arrays.java:1210)
            at java.util.Collections.sort(Collections.java:157)
            at org.springframework.core.OrderComparator.sort(OrderComparator.java:83)
            at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.sortAdvisors(AbstractAdvisorAutoProxyCreator.java:143)
            at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findEligibleAdvisors(AbstractAdvisorAutoProxyCreator.java:90)
            at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.getAdvicesAndAdvisorsForBean(AbstractAdvisorAutoProxyCreator.ja
    Here is cut of my spring security config:
    Code:
    <beans:bean id="domainObjectAccessVoter" class="com.company.security.DomainObjectAccessVoter"/>
    
    
        <beans:bean id="accessDecisionManager" class="org.springframework.security.access.vote.AffirmativeBased">
            <beans:property name="decisionVoters">
                <beans:list>
                    <beans:bean class="org.springframework.security.access.vote.RoleVoter" />
                    <beans:bean class="org.springframework.security.access.vote.AuthenticatedVoter" />
                    <beans:ref bean="domainObjectAccessVoter"/>
                </beans:list>
            </beans:property>
        </beans:bean>
    Any idea?

    Does anyone solved problem when u need DAO layer access in custom voter?

    Thanx!
    Last edited by u268; May 13th, 2013, 06:41 AM.

  • #2
    Anyone????

    Comment


    • #3
      Hi,

      the error trace you pasted doesn't give many information related to the injection of desired bean in your voter.

      Anyway, accessDecisionManager is not finding something (is null) when looking for what it supports.
      AffirmativeBased looks for what its voters support, and you get a NullPoinerException there, which may be due to your voter not being properly initialised.
      I'd suggest you to try with a hardcoded object to solve any security configuration related error that may appear, and afterwards solve the injection problem.

      Comment

      Working...
      X