Simple web application with Spring Security: Part 13

In the last few pages on spring security series, I was about to tackle method-level security and domain-instance security using spring security; But before doing this, I am going to go back to basics and explore the basics of spring security in a deeper way.

Back to basics

We are going to revert to simplest configuration first of all:

In our springsecuritywebapp-servlet.xml file, we remove the configuration for the aclDemoController for now and any reference to it within the file.

In our web.xml:

We configure a listener to load the context of the web application at start up. This will load our applicationContext-security.xml file.

We register a filter named springSecurityFilterChain that delegates all requests matching the url pattern ‘/*’ to a DelegatingFilterProxy.

- Location of the XML file that defines the root application context -
Applied by ContextLoaderListener.

- Loads the root application context of this web app at startup. - The
application context is then available via -



In our applicationContext-security.xml we leave it empty like so:

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns=""
	xmlns:beans="" xmlns:xsi=""


Build and deploy

The application builds ok and deploys to tomcat. However it fails when starting up on tomcat due to:

SEVERE: Error filterStart
SEVERE: Context [/springsecuritywebapp] startup failed due to previous errors

Looking in the tomcat logs we see the following error:

23/12/2008 18:33:28 org.apache.catalina.core.StandardContext filterStart
SEVERE: Exception starting filter springSecurityFilterChain
org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'springSecurityFilterChain' is defined
	at org.springframework.web.filter.DelegatingFilterProxy.initDelegate(
	at org.springframework.web.filter.DelegatingFilterProxy.initFilterBean(
	at org.springframework.web.filter.GenericFilterBean.init(

Clearly the problem is that we haven’t configured any bean named ‘springSecurityFilterChain’.

Fixing springSecurityFilterChain problem

If we use the <http> configuration element it should auto create a default springSecurityFilterChain.

We update our applicationContext-security.xml to look like so:

<http auto-config="false" session-fixation-protection="none">

When we build and deploy this we get another problem:

org.apache.catalina.core.StandardContext listenerStart
SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: No AuthenticationEntryPoint could be established. Please make sure you have a login mechanism configured through the namespace (such as form-login) or specify a custom AuthenticationEntryPoint with the custom-entry-point-ref attribute
Offending resource: ServletContext resource [/WEB-INF/applicationContext-security.xml]
	at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(
	at org.springframework.beans.factory.parsing.ReaderContext.error(
	at org.springframework.beans.factory.parsing.ReaderContext.error(

So spring security is failing fast as it expects us to have some form of authentication mechanism:

We update our applicationContext-security.xml to look like so:

<http auto-config="false" session-fixation-protection="none">
    <form-login login-page="/login.jsp" default-target-url="/home.htm" />

Building and deploy, we see another problem reported on tomcat:

org.apache.catalina.core.StandardContext listenerStart
SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name '_authenticationManager': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: No authentication providers were found in the application context

So spring security expects an authentication provider to be configured to facilitate the form login via an AuthenticationManager that is being automatically created by spring security and named _authenticationManager.

So we update our applicationContext-security.xml again to add the following snippet:

   <user-service id="userDetailsService">
      <user password="password" name="username" authorities="ROLE_USER" />

Building and deploying again, we see from the tomcat logs that the application has started successfully. The authentication through form login (which is all we have configured) works as it should.

How it works behind the scenes

When the applications starts correctly using the configuration laid out as above, see see from the tomcat logs the following details:

INFO: Pre-instantiating singletons in defining beans
]; root of factory hierarchy

What is happening is that from that small amount of configuration, spring security is instantiating a number of beans to enable the functionality. Of special interest is the _filterChainProxy. From the logs, we see the FilterChainProxy is configured as:

INFO: FilterChainProxy: FilterChainProxy[
UrlMatcher =[requiresLowerCase='true']; Filter Chains: {/**=[[ order=200; ],[ order=700; ],[ order=1100; ],[ order=1400; ],]

Following a HTTP Request

As an example, I try to visit the following page on the application: http://localhost:8080/springsecuritywebapp/login.jsp. This requests starts off its journey navigating through the apache tomcat container:


Apache tomcats ApplicationFilterChain.doInternalChain method retrieves filter configured in our web.xml.

ApplicationFilterConfig[name=springSecurityFilterChain, filterClass=org.springframework.web.filter.DelegatingFilterProxy]

It then uses the filter [ of type DelegatingFilterProxy] and invokes doFilter on this passing the request and response types. As the DelegatingFilterProxy’s javadoc states:

This approach is particularly useful for Filter implementation with complex setup needs, allowing to apply the full Spring bean definition machinery to Filter instances. Alternatively, consider standard Filter setup in combination with looking up service beans from the Spring root application context.

And this is its purpose here, to delegate to a FilterChainProxy for which a bean is already instantiated (_filterChainProxy). This is then responsible for filtering the request through each of filters that are part of its VirtualFilterChain.

From our initial configuration set up for spring security, we have have five filters that are part of FilterChainProxys VirtualFilterChain. These are in order of execution:

  1. HttpSessionContextIntegrationFilter
  2. AuthenticationProcessingFilter
  3. SecurityContextHolderAwareRequestFilter
  4. ExceptionTranslationFilter
  5. FilterSecurityInterceptor

In the next part I will talk about what happens to our request to reach http://localhost:8080/springsecuritywebapp/login.jsp in each of these filters.

Getting the code

For this part I haven’t committed code to our code on svn as of yet as the changes are all documented here and very quick and simple.

11 Responses to “Simple web application with Spring Security: Part 13”

  1. marcKun Says:

    cool man.. very detailed walk thru… thanks a million

  2. madhava Says:

    hi can u please explain how spring security filter c hain works ,i need to add custom filter (password change filter to be called when credentials are expired)

  3. Dham Says:


    Thanks for posting such an useful article. its short, sweet n perfect.. i have jst solved a lot of erroneous phases though this.. nice work man.. keep it up..

  4. Amit Patel Says:

    Very good explanation. It is very useful

  5. Ron Says:


    Thanks a lot for so compact and useful knowledge sharing on springSecurityFilterChain.

  6. Indroniel Deb Roy Says:

    Great walk through of “springSecurityFilterChain” … It helped me to understand the spring security model better!!

  7. stanley Says:

    Thank you!
    spring always gracefully fails without giving warnings.
    and the way it works are mostly magical (black box)..
    the official documentation lacks of warning from the impending doom…

  8. lwpro2 Says:

    have anyone have anyidea, on how the entry-point configuration would be invoked?

    as for custom filter, i think you can define the bean, following the strict naming requirement, and specify the custom-filter position, like <bean id=”authenticationProcessingFilter” scope=”prototype”
    <security:custom-filter position=”PRE_AUTH_FILTER” />
    <property name=”authenticationManager” ref=”authenticationManager” />

  9. lkafle Says:

    great article

  10. Yesu Raj Says:

    good post

  11. Exception while web application deployment: No bean named ‘springSecurityFilterChain’ is defined - All Tech In One Says:

    [...]… [...]

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Get every new post delivered to your Inbox.

%d bloggers like this: