Scrivio Interview library
ConceptFoundations7 min read · updated 12 November 2026

What is DelegatingFilterProxy, why does Spring Security need it, and how does Spring Boot register it?

DelegatingFilterProxy is a plain servlet filter that the servlet container can create on its own, and that hands every request to a Spring bean named springSecurityFilterChain, which it looks up lazily from the application context. Spring Security needs it because the container builds its filters outside the Spring context, so it cannot use Spring beans as filters directly. Spring Boot registers the proxy through a DelegatingFilterProxyRegistrationBean, ordered by spring.security.filter.order, which is -100 by default.

Why this question is asked

Every request that Spring Security protects passes through DelegatingFilterProxy first, yet most of us never write a line that mentions it. It matters the moment something goes wrong at the edge of the application: a filter that cannot see the logged-in user, a security rule that seems to be skipped, or a custom filter that runs twice. Interviewers ask about it because the answer shows whether we understand where the servlet world ends and the Spring world begins. In this answer, we will recap how servlet filters are created, see the problem that DelegatingFilterProxy solves, follow a request through the proxy into FilterChainProxy, and then look at how Spring Boot registers it and why its order matters.

1A Quick Recap of Servlet Filters

A servlet filter is an object that sees every HTTP request before it reaches the servlet, and the response on its way back. It implements jakarta.servlet.Filter and has one important method, doFilter(request, response, chain). Inside it, the filter can inspect or change the request, reject it, or call chain.doFilter() to pass it on to the next filter.

The servlet container (Tomcat, Jetty or Undertow) owns these filters. It creates them, calls their init() method once, keeps them in an ordered list, and runs them for every request. That ownership is the heart of the question: the container decides when a filter is created, and it knows nothing about Spring.

2Why the Container Cannot Use Spring Beans as Filters

Spring Security is made of many Spring beans: the filters themselves, the AuthenticationManager, the user lookup, the password encoder, the rules we write in a SecurityFilterChain bean. These beans need dependency injection and they need the application context to be ready.

The container, on the other hand, creates its filters when the web application starts, from its own registration list, before or outside the Spring context. In a classic WAR the container reads web.xml or a ServletContainerInitializer and instantiates filter classes itself, with a no-argument constructor. In Spring Boot the embedded container starts while the context is still refreshing, so many beans do not exist yet when the container wants its filters. Either way, the container cannot simply ask for a fully built Spring bean at that moment.

So we need a bridge: something the container can create early and cheaply, which finds the real Spring bean later, when it is actually needed. That bridge is DelegatingFilterProxy.

3How the Proxy Hands Requests to Spring

DelegatingFilterProxy is a real servlet filter from spring-web. It holds a bean name, and for Spring Security that name is springSecurityFilterChain. When the first request arrives, the proxy looks up the bean with that name in the WebApplicationContext, keeps the reference, and from then on simply calls delegate.doFilter() for every request.

Java
// What DelegatingFilterProxy does, reduced to its idea
public class DelegatingFilterProxy extends GenericFilterBean {
private volatile Filter delegate; // null until the first request
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) {
Filter target = this.delegate;
if (target == null) {
target = context.getBean("springSecurityFilterChain", Filter.class); // lazy lookup
this.delegate = target;
}
target.doFilter(req, res, chain); // the Spring bean does the real work
}
}
Step throughOne request through the proxy
TomcatDelegatingFilterProxyFilterChainProxySecurityFilterChainController
doFilter(request)
delegate: bean springSecurityFilterChain
pick the first chain that matches /orders
run its filters in order
request is authenticated and allowed
response
finally: clear SecurityContextHolder

7 messages in order. Play them, or step through them one at a time.

The container only knows the proxy; everything after it is Spring beans.

Notice that the lookup is lazy. The proxy can be registered with the container long before the bean exists, and the context only has to be ready by the time the first request comes in. The reason for the lazy lookup is exactly the timing problem we saw above.

The bean behind the name is FilterChainProxy, Spring Security's own filter. It holds a list of SecurityFilterChain instances, one for each SecurityFilterChain bean we define. For each request it picks the first chain whose request matcher fits, and runs that chain's filters in order: the filter that loads the security context, CSRF protection, the authentication filters, ExceptionTranslationFilter, AuthorizationFilter and so on. FilterChainProxy also applies the HTTP firewall that rejects suspicious URLs, and it clears the SecurityContextHolder when the request finishes.

4How Spring Boot Registers It

In a Spring Boot application we never declare the proxy ourselves. Boot's security filter auto-configuration (SecurityFilterAutoConfiguration) defines a DelegatingFilterProxyRegistrationBean. This is a registration bean: a Spring bean whose job is to tell the embedded container to add a filter, with a name, URL patterns, dispatcher types and an order. Here it creates a DelegatingFilterProxy pointing at the bean name springSecurityFilterChain.

Java
# application.properties
spring.security.filter.order=-100 # the default; lower numbers run earlier
# Startup log with logging.level.org.springframework.security=DEBUG
# Will secure any request with [DisableEncodeUrlFilter, WebAsyncManagerIntegrationFilter,
# SecurityContextHolderFilter, HeaderWriterFilter, CsrfFilter, LogoutFilter, ...]

Boot uses a registration bean instead of registering FilterChainProxy directly for the same timing reason. The registration can be handed to the container early, and the real bean is resolved when the first request needs it.

5Why the Order of -100 Matters

The servlet container runs all registered filters in a single ordered list, and lower numbers run first. Boot puts Spring Security at -100 so that a few infrastructure filters that must wrap the request run before it (character encoding, request wrapping, the HTTP observation filter at a very high precedence), and our own @Component filters, which get the lowest precedence by default, run after it.

This matters for every other filter in the application. A filter ordered before -100 runs before anybody is authenticated, so SecurityContextHolder is empty there. A filter ordered after it can see the authenticated user. If we change spring.security.filter.order, or give our own FilterRegistrationBean an order, we are deciding which of those two worlds the filter lives in.

Where common filters sit in the servlet order
FilterTypical orderSees the user?
CharacterEncodingFilterOrdered.HIGHEST_PRECEDENCENo
ServerHttpObservationFilter (tracing)Ordered.HIGHEST_PRECEDENCE + 1No, it starts before security
DelegatingFilterProxy (Spring Security)-100It creates the user
Our @Component filter without @OrderOrdered.LOWEST_PRECEDENCEYes
Lower numbers run first. Only filters after -100 can read the authenticated user.

6Follow-up questions

Why not register FilterChainProxy as a normal Filter bean and skip the proxy?

It can be done, and Boot registers any Filter bean it finds as a servlet filter. But the proxy keeps two useful properties. It defers the lookup until the first request, so the container never forces the whole security configuration to be built in the middle of startup, and it keeps the classic non-Boot setup (web.xml or AbstractSecurityWebApplicationInitializer) working the same way. Registering FilterChainProxy directly would also make it easy to register it twice by accident.

Our custom security filter is annotated with @Component and also added with addFilterBefore. What happens?

Boot sees a Filter bean and registers it with the servlet container as well, so it runs once as an ordinary servlet filter, at the lowest precedence, and once inside the security chain. The servlet copy runs outside Spring Security's context handling, which causes confusing behaviour. We either remove @Component and create the filter inside the configuration, or keep the bean and declare a FilterRegistrationBean for it with setEnabled(false).

Does every request go through Spring Security once it is registered?

Every request that matches the registration's URL patterns and dispatcher types reaches the proxy. FilterChainProxy then looks for a SecurityFilterChain whose matcher fits; if none matches, the request passes through without any security filters. That is why an unmatched path, such as one outside a securityMatcher, is not protected at all.

7Conclusion

In this answer, we saw that the servlet container creates its filters on its own, outside the Spring context, so Spring Security cannot be handed to it as a bean. DelegatingFilterProxy is the bridge: a simple servlet filter that lazily looks up the springSecurityFilterChain bean and delegates every request to it. That bean is FilterChainProxy, which chooses one of our SecurityFilterChain instances and runs its filters. Spring Boot registers the proxy through DelegatingFilterProxyRegistrationBean at order -100, and that order decides which other filters run before or after authentication.

What to say in the interviewAbout 90 seconds aloud

Open with

DelegatingFilterProxy is the bridge between the servlet container and Spring. The container creates and orders its filters itself, at startup, and it knows nothing about Spring beans, so it cannot directly use Spring Security's filters, which need injection and a ready context.

Then, if they want more

So Spring gives the container a plain servlet filter, DelegatingFilterProxy, which holds a bean name, springSecurityFilterChain. On the first request it looks that bean up lazily in the application context and from then on just delegates doFilter to it. The bean is FilterChainProxy.

It holds the SecurityFilterChain instances we define, picks the first one whose matcher fits the request, runs its filters, and clears the security context at the end. In Spring Boot I never declare the proxy myself.

The security filter auto-configuration creates a DelegatingFilterProxyRegistrationBean, which registers the proxy with the embedded container, and its position in the servlet filter order comes from spring.security.filter.order, which defaults to -100. That number matters in practice.

Any filter ordered before it, like the tracing filter or something I order at highest precedence, runs before authentication and will see no user in SecurityContextHolder, while my own filters with the default lowest precedence run after it. When someone tells me a filter cannot see the user, the first thing I check is where it sits relative to -100.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Official documentation
Spring Security reference
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "What is DelegatingFilterProxy, why does Spring Security need it, and how does Spring...": https://scrivio-interview-library.netlify.app/spring-boot/security-architecture/2b0b4da410/