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

  • No bean named 'springSecurityFilterChain' is defined

    Hi,

    I have seen many posts about this same problem I'm having, but I've read whatever I could find and tried any solutions proposed. If anyone can help I'd really appreciate it.

    The twist is I'm trying to secure a Grails application (Grails 1.2.1) without the plugin, and just falling back to standard Spring security. I've followed two articles about doing that, so believe I'm setup the same.

    I receive this when I start:

    Running Grails application..
    2010-04-02 14:27:22,828 [main] ERROR [localhost].[/riainaday] - 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:504)
    at org.springframework.beans.factory.support.Abstract BeanFactory.getMergedLocalBeanDefinition(AbstractB eanFactory.java:1041)
    at org.springframework.beans.factory.support.Abstract BeanFactory.doGetBean(AbstractBeanFactory.java:273 )
    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:193)
    at org.springframework.beans.factory.support.Abstract BeanFactory.doGetBean(AbstractBeanFactory.java:265 )
    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:193)
    at org.springframework.context.support.AbstractApplic ationContext.getBean(AbstractApplicationContext.ja va:1008)
    at org.springframework.web.filter.DelegatingFilterPro xy.initDelegate(DelegatingFilterProxy.java:217)
    at org.springframework.web.filter.DelegatingFilterPro xy.initFilterBean(DelegatingFilterProxy.java:145)
    at org.springframework.web.filter.GenericFilterBean.i nit(GenericFilterBean.java:179)
    at org.apache.catalina.core.ApplicationFilterConfig.g etFilter(ApplicationFilterConfig.java:275)
    at org.apache.catalina.core.ApplicationFilterConfig.s etFilterDef(ApplicationFilterConfig.java:397)
    at org.apache.catalina.core.ApplicationFilterConfig.< init>(ApplicationFilterConfig.java:108)
    at org.apache.catalina.core.StandardContext.filterSta rt(StandardContext.java:3827)
    at org.apache.catalina.core.StandardContext.start(Sta ndardContext.java:4477)
    at org.apache.catalina.core.ContainerBase.start(Conta inerBase.java:1045)
    at org.apache.catalina.core.StandardHost.start(Standa rdHost.java:722)
    at org.apache.catalina.core.ContainerBase.start(Conta inerBase.java:1045)
    at org.apache.catalina.core.StandardEngine.start(Stan dardEngine.java:443)
    at org.apache.catalina.core.StandardService.start(Sta ndardService.java:515)
    at org.apache.catalina.core.StandardServer.start(Stan dardServer.java:708)
    at org.apache.catalina.startup.Tomcat.start(Tomcat.ja va:286)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)

    I'll skip the rest of the trace.

    My web.xml:

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
    	<display-name>/@grails.project.key@</display-name>
    	
    
    
    	<context-param>
    		<param-name>contextConfigLocation</param-name>
    		<param-value>/WEB-INF/applicationContext.xml</param-value>
    		
    	</context-param>
    
    	<context-param>
    		<param-name>webAppRootKey</param-name>
    		<param-value>@grails.project.key@</param-value>
    	</context-param>
    
    	<filter>
    		<filter-name>sitemesh</filter-name>
    		<filter-class>org.codehaus.groovy.grails.web.sitemesh.GrailsPageFilter</filter-class>
    	</filter>
    
    	<filter>
    		<filter-name>charEncodingFilter</filter-name>
    		<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
    		<init-param>
    			<param-name>targetBeanName</param-name>
    			<param-value>characterEncodingFilter</param-value>
    		</init-param>
    		<init-param>
    			<param-name>targetFilterLifecycle</param-name>
    			<param-value>true</param-value>
    		</init-param>
    	</filter>
    
    	<filter>
    		<filter-name>springSecurityFilterChain</filter-name>
    		<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
    	</filter>
    	
    	<filter-mapping>
    		<filter-name>charEncodingFilter</filter-name>
    		<url-pattern>/*</url-pattern>
    	</filter-mapping>
    	
    	<filter-mapping>
    		<filter-name>sitemesh</filter-name>
    		<url-pattern>/*</url-pattern>
    	</filter-mapping>
    	
    	<filter-mapping>
    		<filter-name>springSecurityFilterChain</filter-name>
    		<url-pattern>/*</url-pattern>
    	</filter-mapping>
    
    
    	<listener>
    		<listener-class>org.codehaus.groovy.grails.web.util.Log4jConfigListener</listener-class>
    	</listener>
    
    	<listener>
    		<listener-class>org.codehaus.groovy.grails.web.context.GrailsContextLoaderListener</listener-class>
    	</listener>
    
    	<!-- Grails dispatcher servlet -->
    	<servlet>
    		<servlet-name>grails</servlet-name>
    		<servlet-class>org.codehaus.groovy.grails.web.servlet.GrailsDispatcherServlet</servlet-class>
    		<load-on-startup>1</load-on-startup>
    	</servlet>
    
    	<!-- The Groovy Server Pages servlet -->
    	<servlet>
    		<servlet-name>gsp</servlet-name>
    		<servlet-class>org.codehaus.groovy.grails.web.pages.GroovyPagesServlet</servlet-class>
    	</servlet>
    
    	<servlet-mapping>
    		<servlet-name>gsp</servlet-name>
    		<url-pattern>*.gsp</url-pattern>
    	</servlet-mapping>
    
    	<welcome-file-list>
    		<!--
    			The order of the welcome pages is important. JBoss deployment will
    			break if index.gsp is first in the list.
    		-->
    		<welcome-file>index.html</welcome-file>
    		<welcome-file>index.jsp</welcome-file>
    		<welcome-file>index.gsp</welcome-file>
    	</welcome-file-list>
    
    	<jsp-config>
    		<taglib>
    			<taglib-uri>http://java.sun.com/jsp/jstl/core</taglib-uri>
    			<taglib-location>/WEB-INF/tld/c.tld</taglib-location>
    		</taglib>
    		<taglib>
    			<taglib-uri>http://java.sun.com/jsp/jstl/fmt</taglib-uri>
    			<taglib-location>/WEB-INF/tld/fmt.tld</taglib-location>
    		</taglib>
    		<taglib>
    			<taglib-uri>http://www.springframework.org/tags</taglib-uri>
    			<taglib-location>/WEB-INF/tld/spring.tld</taglib-location>
    		</taglib>
    		<taglib>
    			<taglib-uri>http://grails.codehaus.org/tags</taglib-uri>
    			<taglib-location>/WEB-INF/tld/grails.tld</taglib-location>
    		</taglib>
    	</jsp-config>
    
    
    
    </web-app>
    Note: I've tried Spring Security 2 and 3, currently at 2.

    I have an applicationContext-security.xml in the grails-app/conf/spring directory:

    Code:
    <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/schem...-beans-2.5.xsd
    	http://www.springframework.org/schema/security
    	http://www.springframework.org/schema/security/spring-security-2.0.5.xsd">
    
    
    	<http auto-config='true'>
    		<intercept-url pattern="/**" access="ROLE_USER" />
    	</http>
    
    	<beans:bean id="userService" class="com.riainaday.UserService" />
    
    	<authentication-manager alias="authenticationManager">
    		<authentication-provider user-service-ref="userService" />
    	</authentication-manager>
    
    
    </beans:beans>
    I import this in resources.xml.

    Code:
    <import resource="applicationContext-security.xml"/>
    I understand that this bean not found does not need to be included in any xml file, and is created automatically by Spring simply by having the http element in my xml configuration.

    I'm guessing this has something to do with the http element in applicationContext-security.xml not being processed in time due to having that loaded by Grails, however that is a wild guess and it seems to have worked for a few others based on articles I've found.

    I will probably post something to the Grails mailing list as well, but I'm hoping someone can help here after reading about my situation.

    Thanks,

    Larry
    Last edited by con19m31; Apr 4th, 2010, 10:07 AM.

  • #2
    Please use [ code][/code ] tags when posting code.

    Make sure that the security xml is loaded by the ContextLoaderListener and not the DispatcherServlet. The DelegatingFilterProxy will only look into the root applicationcontext (which is loaded by the ContextLoaderListener) for the bean to delegate to.

    Comment


    • #3
      Problem Fixed

      Marten,

      Based on your advice, I moved my applicationContext-security.xml reference into web.xml so it is a contextConfigLocation parameter and would hopefully load along with applicationContext, and this has worked! I did have one other error which I think was related to how I had Spring Security 2 configured, so I moved it to Spring Security 3 and now it starts up without any errors.

      Thank you very much for your advice

      Larry

      Comment


      • #4
        I have the same problem and try to follow your solution:

        in web.xml
        Code:
            <context-param>
                <param-name>contextConfigLocation</param-name>
                <param-value>/WEB-INF/applicationContext.xml
                classpath:spring-security-context.xml</param-value>
            </context-param>
        I try to put my spring-security-context.xml in different location but I allways got an IOException
        nested exception is java.io.FileNotFoundException: class path resource [spring-security-context.xml] cannot be opened because it does not exist

        Where did you place your applicationContext-security.xml file

        Thanks in advance
        Martin

        Comment


        • #5
          File Location

          Hi Martin,

          I tried the same thing you did, including adding folders to the classpath, and after spending a bit of time on it, I switched to just adding the applicationContext-security.xml file into same location as the applicationContext.xml, so in web.xml I have:

          Code:
          <context-param>
          		<param-name>contextConfigLocation</param-name>
          		<param-value>/WEB-INF/applicationContext.xml /WEB-INF/applicationContext-security.xml</param-value>
          	</context-param>
          Larry

          Comment


          • #6
            After copying my file to scr/main/java directory, grails find it.

            Comment

            Working...
            X