Announcement Announcement Module
Collapse
No announcement yet.
Problem when finding springSecurityFilterChain bean Page Title Module
Move Remove Collapse
This topic is closed
X
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem when finding springSecurityFilterChain bean

    Hi,

    I've been trying to use the preauth sample in my own Tomcat 4 application, but am getting the following error when the server starts up:

    2008-05-09 10:01:08 StandardContext[/macroderivatives]: Exception starting filter springSecurityFilterChain
    org.springframework.beans.factory.NoSuchBeanDefini tionException: No bean named 'springSecurityFilterChain' is defined
    at org.springframework.beans.factory.support.DefaultL istableBeanFactory.getBeanDefinition(DefaultListab leBeanFactory.java:391)
    at org.springframework.beans.factory.support.Abstract BeanFactory.getMergedLocalBeanDefinition(AbstractB eanFactory.java:999)
    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:233)
    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:174)
    I have the following in my web.xml:

    Code:
        <filter>
    	<filter-name>springSecurityFilterChain</filter-name>
    	<filter-class>
    		org.springframework.web.filter.DelegatingFilterProxy
    	</filter-class>
        </filter>
    
        <filter-mapping>
            <filter-name>springSecurityFilterChain</filter-name>
    	<url-pattern>/*</url-pattern>
        </filter-mapping>
    And my Spring security context XML is simply:

    Code:
    <?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"
    	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
                            http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-2.0.xsd">
    
        <beans:bean id="filterChainProxy" class="org.springframework.security.util.FilterChainProxy">
            <filter-chain-map path-type="ant">
                <filter-chain pattern="/**" filters="sif"/>
            </filter-chain-map>
        </beans:bean>
    
        <beans:bean id="sif"
    		class="org.springframework.security.context.HttpSessionContextIntegrationFilter" />
    
    </beans:beans>
    I've seen a few posts regarding the same error, but no real solutions. Any ideas what's up?

    Thanks

    Nick

  • #2
    Bah! Ignore me. I needed to call the FilerChainProxy bean "springSecurityFilterChain" and it works.

    Nick

    Comment


    • #3
      Or you can use the name "filterChainProxy" in your web.xml.

      Comment


      • #4
        I had the same issue and turns out <security:http/> and <security:authentication-provider/> need to be in the primary config that's listed in web.xml via:
        Code:
        <context-param>
        	<param-name>contextConfigLocation</param-name>
        	<param-value>/WEB-INF/classes/hibernateSpringContext.xml</param-value>
        </context-param>
        When i had it in a servlet dispatcher configuration file i got the same exception as mentioned above.
        So don't put it here. It will not work:
        Code:
        <servlet>
        	<servlet-name>myDispatcher</servlet-name>
        	<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        	<load-on-startup>1</load-on-startup>
        </servlet>

        Comment


        • #5
          Yes, this is a common misconception with Spring app contexts - the fact that the *-servlet.xml beans aren't visible from the main context. Often people wonder why security pointcuts defined in the main context aren't applied to beans in their web dispatcher context, which is essentially the same problem.

          Comment


          • #6
            Namespace issue

            This had me stumped too. The springSecurityFilterChain bean is supposed to be created automatically when you use the <security:http... /> configuration. It turned out that the problem was not reading the manual... they make security the default xml namespace so in their examples they omit all the "security:" prefixes. If you leave beans as the default namespace, as shown below, you need to use the "security:" prefix everywhere. Then the springSecurityFilterChain bean is created OK. The context file below works fine for me.


            Context-xml

            <beans xmlns="http://www.springframework.org/schema/beans"
            xmlns:security="http://www.springframework.org/schema/security"

            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:schemaLocation="http://www.springframework.org/schema/beans
            http://www.springframework.org/schem...-beans-2.5.xsd
            http://www.springframework.org/schema/security
            http://www.springframework.org/schema/security/spring-security-2.0.4.xsd">

            <!-- Configure security -->
            <security:http auto-config="true">
            <security:intercept-url pattern="/**" access="ROLE_USER" />
            </security:http>

            <security:authentication-provider>
            <security:user-service>
            <security:user name="jimi" password="jimi" authorities="ROLE_USER, ROLE_ADMIN" />
            <security:user name="bob" password="bob" authorities="ROLE_USER" />
            </security:user-service>
            </security:authentication-provider>

            </beans>

            Comment

            Working...
            X