Back Forum Reply New

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..beans.factory.NoSuchBeanDefini  tionException: No bean named 'springSecurityFilterChain' is defined
at org..beans.factory.support.DefaultL  istableBeanFactory.getBeanDefinition(DefaultListab  leBeanFactory.java:391)
at org..beans.factory.support.Abstract  BeanFactory.getMergedLocalBeanDefinition(AbstractB  eanFactory.java:999)
at org..beans.factory.support.Abstract  BeanFactory.getBean(AbstractBeanFactory.java:233)
at org..beans.factory.support.Abstract  BeanFactory.getBean(AbstractBeanFactory.java:174)

I have the following in my web.xml:Code:   lt;filtergt;
lt;filter-namegt;springSecurityFilterChainlt;/filter-namegt;
lt;filter-classgt;
org..web.filter.DelegatingFilterProxy
lt;/filter-classgt;   lt;/filtergt;
   lt;filter-mappinggt;       lt;filter-namegt;springSecurityFilterChainlt;/filter-namegt;
lt;ucl-patterngt;/*lt;/ucl-patterngt;   lt;/filter-mappinggt;
And my Spring security context XML is simply:Code:
lt;?xml version=quot;1.0quot; encoding=quot;UTF-8quot;?gt;
lt;beans:beans xmlns=quot;schema/securityquot;
xmlns:beans=quot;schema/beansquot;
xmlns:xsi=quot;2001/XMLSchema-instancequot;
xsi:schemaLocation=quot;schema/beans schema/beans/spring-beans-2.0.xsd            schema/security schema/security/spring-security-2.0.xsdquot;gt;
   lt;beans:bean id=quot;filterChainProxyquot; class=quot;org..security.util.FilterChainProxyquot;gt;       lt;filter-chain-map path-type=quot;antquot;gt;lt;filter-chain pattern=quot;/**quot; filters=quot;sifquot;/gt;       lt;/filter-chain-mapgt;   lt;/beans:beangt;
   lt;beans:bean id=quot;sifquot;
class=quot;org..security.context.fromSessionContextIntegrationFilterquot; /gt;

lt;/beans:beansgt;
I've seen a few posts regarding the same error, but no real solutions. Any ideas what's up?

Thanks

Nick

Bah! Ignore me. I needed to call the FilerChainProxy bean quot;springSecurityFilterChainquot; and it works.

Nick

Or you can use the name quot;filterChainProxyquot; in your web.xml.

I had the same issue and turns out lt;security:from/gt; and lt;security:authentication-provider/gt; need to be in the primary config that's listed in web.xml via:

Code:
lt;context-paramgt;
lt;param-namegt;contextConfigLocationlt;/param-namegt;
lt;param-valuegt;/WEB-INF/classes/hibernateSpringContext.xmllt;/param-valuegt;
lt;/context-paramgt;
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:
lt;servletgt;
lt;servlet-namegt;myDispatcherlt;/servlet-namegt;
lt;servlet-classgt;org..web.servlet.DispatcherServletlt;/servlet-classgt;
lt;load-on-startupgt;1lt;/load-on-startupgt;
lt;/servletgt;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.

Yay more Spring MAGIC

This had me stumped too. The springSecurityFilterChain bean is supposed to be created automatically when you use the lt;security:from... /gt; 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 quot;security:quot; prefixes. If you leave beans as the default namespace, as shown below, you need to use the quot;security:quot; prefix everywhere. Then the springSecurityFilterChain bean is created OK. The context file below works fine for me.Context-xml

lt;beans xmlns=quot;schema/beansquot;      xmlns:security=quot;schema/securityquot;      xmlns:xsi=quot;2001/XMLSchema-instancequot;      xsi:schemaLocation=quot;schema/beans      schem...-beans-2.5.xsd      schema/security      schema/security/spring-security-2.0.4.xsdquot;gt;
   lt;!-- Configure security --gt;   lt;security:from auto-config=quot;truequot;gt;lt;security:intercept-ucl pattern=quot;/**quot; access=quot;ROLE_USERquot; /gt;    lt;/security:fromgt;
   lt;security:authentication-providergt;lt;security:user-servicegt;lt;security:user name=quot;jimiquot; password=quot;jimiquot; authorities=quot;ROLE_USER, ROLE_ADMINquot; /gt;         lt;security:user name=quot;bobquot; password=quot;bobquot; authorities=quot;ROLE_USERquot; /gt;lt;/security:user-servicegt;    lt;/security:authentication-providergt;

lt;/beansgt;
¥
Back Forum Reply New