Scrivio Interview library
InternalsFoundations6 min read · updated 12 November 2026

Describe the path of an HTTP request through Spring Security in a Spring Boot servlet application, from the servlet container to your controller. Name the main filters in order for an application with form login and CSRF enabled.

The servlet container calls a DelegatingFilterProxy, which hands the request to the FilterChainProxy bean. FilterChainProxy picks the first SecurityFilterChain whose matcher matches the request and runs its filters in order; for form login with CSRF the main ones are SecurityContextHolderFilter, HeaderWriterFilter, CorsFilter, CsrfFilter, LogoutFilter, UsernamePasswordAuthenticationFilter, RequestCacheAwareFilter, AnonymousAuthenticationFilter, ExceptionTranslationFilter and finally AuthorizationFilter, after which the request reaches the DispatcherServlet and our controller.

Why this question is asked

Most Spring Security problems, a filter that runs twice, a 401 where we expected a JSON error, a custom filter that sees no user, make sense the moment we can picture the chain a request passes through. Interviewers ask this internals question because it shows whether we understand Spring Security as a sequence of filters with clear jobs rather than a box of annotations. In this answer, we will follow one request from the container to the controller, see how FilterChainProxy chooses a chain, walk through each main filter and why it sits where it does, look closely at how ExceptionTranslationFilter and AuthorizationFilter work together, and finish with how to print the chain at startup.

1From the Servlet Container to Spring

A servlet filter is an object the container, Tomcat for example, calls before the servlet that handles a request; filters can inspect or change the request, or stop it. The container knows nothing about Spring beans, so Spring Security needs a bridge. Spring Boot registers a DelegatingFilterProxy with the container under the name springSecurityFilterChain. Its only job is to look up a bean with that name in the application context, which is the FilterChainProxy, and delegate each request to it.

FilterChainProxy is the real entry point of Spring Security. It holds a list of SecurityFilterChain objects, each with a request matcher and a list of filters. For each request it asks the chains in order whether they match and uses the first one that does; the others are ignored for that request. It also does housekeeping, such as rejecting suspicious URLs through its HTTP firewall and clearing the security context at the end.

Step throughOne request on its way to the controller
  1. Servlet containerTomcat calls its registered filters
  2. DelegatingFilterProxybridge to the springSecurityFilterChain bean
  3. FilterChainProxypicks the first matching SecurityFilterChain
  4. Security filterscontext, headers, CSRF, login, authorization
  5. DispatcherServletSpring MVC dispatching
  6. Controllerour code, only if every filter let it pass

6 layers, from the top down. Step through them one at a time.

2The Filters in Order and Why

For an application with form login and CSRF, the chain contains roughly these filters, plus a few smaller ones such as DisableEncodeUrlFilter and the default login page filters. The exact set depends on configuration and version, which is why printing the chain, covered at the end, is the reliable way to check.

Main filters for form login with CSRF
FilterWhat it does
SecurityContextHolderFilterloads the SecurityContext (from the session) for this request
HeaderWriterFilteradds security headers such as X-Content-Type-Options
CorsFilterhandles CORS preflight and headers, if CORS is configured
CsrfFilterrejects POST, PUT, DELETE without a valid CSRF token
LogoutFilteron POST /logout clears the session and context
UsernamePasswordAuthenticationFilteron POST /login authenticates username and password
RequestCacheAwareFilterrestores the request saved before a login redirect
AnonymousAuthenticationFiltersets an anonymous token if nobody is authenticated
ExceptionTranslationFilterturns security exceptions into redirect, 401 or 403
AuthorizationFilterfinal decision: may this request proceed?

Notice the logic of the order. The context must be loaded before anything checks who the user is. CSRF must be checked before logout and login, because both are state-changing POSTs that an attacker could forge. Login processing comes before the anonymous filter, so a real user is set first and only an empty context gets an anonymous token. And ExceptionTranslationFilter sits just before AuthorizationFilter so it can catch the exceptions authorization throws.

3Following a Request for a Protected Page

Let us follow GET /orders from a user who has not logged in. SecurityContextHolderFilter finds no context in the session. HeaderWriterFilter arranges the headers. CsrfFilter lets the GET through, because safe methods need no token, but makes a token available for the page. LogoutFilter and UsernamePasswordAuthenticationFilter do nothing, because this is not POST /logout or POST /login. AnonymousAuthenticationFilter puts an AnonymousAuthenticationToken in the context.

Then AuthorizationFilter asks its AuthorizationManager whether an anonymous user may access /orders. The answer is no, so it throws AccessDeniedException. That exception travels back up the call stack to ExceptionTranslationFilter, which sees that the user is anonymous, saves the request in the request cache, and starts authentication by redirecting to /login. After a successful login, RequestCacheAwareFilter helps send the user back to /orders.

Step throughGET /orders without a login
BrowserContext filtersExceptionTranslationAuthorization
GET /orders
no session context; set anonymous token
continue
continue
AccessDeniedException (anonymous)
save request, start authentication
302 redirect to /login

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

The decision is made last, and ExceptionTranslationFilter turns it into the right response.

4How ExceptionTranslationFilter and AuthorizationFilter Work Together

ExceptionTranslationFilter does no checking of its own. It calls the rest of the chain inside a try block and catches two kinds of exceptions thrown by later filters. For an AuthenticationException, or an AccessDeniedException when the user is anonymous, it calls the AuthenticationEntryPoint: with form login that is a redirect to the login page, with a bearer token API it is a 401. For an AccessDeniedException when the user is logged in, it calls the AccessDeniedHandler, which by default returns 403.

AuthorizationFilter makes the final decision for the request, using the rules we configured with authorizeHttpRequests. In Spring Security 6 it replaced FilterSecurityInterceptor, which was tied to the older AccessDecisionManager and voters. The newer filter uses the simpler AuthorizationManager interface and, by default, applies to every dispatcher type, including error and forward dispatches. If AuthorizationFilter allows the request, it calls the rest of the servlet chain and the DispatcherServlet routes it to our controller.

5Printing the Filters at Startup

The most reliable way to know the chain is to print it. Spring Security logs each chain when it is built; with debug logging for the security package we see a line listing every filter. We can also ask FilterChainProxy directly.

Java
# application.properties
logging.level.org.springframework.security=DEBUG
# startup log (abridged): Will secure any request with [DisableEncodeUrlFilter, ...,
# SecurityContextHolderFilter, HeaderWriterFilter, CsrfFilter, LogoutFilter, ...]
@Bean
ApplicationRunner printChains(FilterChainProxy proxy) {
return args -> proxy.getFilterChains().forEach(chain ->
chain.getFilters().forEach(f -> System.out.println(f.getClass().getSimpleName())));
}
// SecurityContextHolderFilter
// HeaderWriterFilter
// CsrfFilter
// ...
// AuthorizationFilter

For deeper investigation, @EnableWebSecurity(debug = true) logs the filter chain used for every individual request, which is helpful when debugging but too noisy and revealing for production. The exact log level of the startup line has changed between versions, so check your version if the line does not appear at INFO.

6Follow-up questions

How can you print the filters in each chain at startup?

Set logging.level.org.springframework.security=DEBUG and Spring Security logs each SecurityFilterChain with its full filter list as it is created. Alternatively, inject FilterChainProxy and iterate getFilterChains() and each chain's getFilters() in an ApplicationRunner. For per-request detail during debugging, @EnableWebSecurity(debug = true) prints the chain used for each request.

Why is there a DelegatingFilterProxy at all?

The servlet container creates and calls filters itself, before and independent of the Spring application context. DelegatingFilterProxy is a plain filter the container can manage, which looks up the FilterChainProxy bean lazily, so all security filters can be ordinary Spring beans with dependency injection.

What happens if no SecurityFilterChain matches?

FilterChainProxy applies no security filters and passes the request straight on to the rest of the servlet chain. That is why a catch-all chain, one without a securityMatcher, is usually the last one, so every request is covered by some chain.

7Conclusion

In this answer, we followed a request from the servlet container through DelegatingFilterProxy to FilterChainProxy, which picks the first matching SecurityFilterChain. Its filters run in a deliberate order: load the context, write headers, handle CORS, check CSRF, process logout and login, restore saved requests, set an anonymous token, and finally decide with AuthorizationFilter, while ExceptionTranslationFilter turns failures into a login redirect, 401 or 403. Printing the chain at startup is the reliable way to see exactly which filters a service runs.

What to say in the interviewAbout 70 seconds aloud

Open with

The servlet container knows only plain filters, so Spring Boot registers a DelegatingFilterProxy named springSecurityFilterChain, which delegates to the FilterChainProxy bean. FilterChainProxy holds the SecurityFilterChain beans and uses the first whose matcher matches the request.

Then, if they want more

With form login and CSRF the main filters in order are: SecurityContextHolderFilter, which loads the context from the session; HeaderWriterFilter for security headers; CorsFilter if CORS is configured; CsrfFilter, which rejects state-changing requests without a token; LogoutFilter; UsernamePasswordAuthenticationFilter, which handles POST /login; RequestCacheAwareFilter, which restores the request saved before the login redirect; AnonymousAuthenticationFilter, which sets an anonymous token if nobody is logged in; ExceptionTranslationFilter; and finally AuthorizationFilter.

AuthorizationFilter, which replaced FilterSecurityInterceptor in Spring Security 6, makes the final decision using our authorizeHttpRequests rules. If it denies, it throws AccessDeniedException, and ExceptionTranslationFilter turns that into a login redirect or 401 for anonymous users, or a 403 for authenticated ones. If it allows, the request goes on to the DispatcherServlet and the controller.

To see the actual chain I enable debug logging for org.springframework.security, or iterate FilterChainProxy's chains at startup.

About this answer

Last updated
12 November 2026
Versions it names
Spring Security 6
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 "Describe the path of an HTTP request through Spring Security in a Spring Boot servlet...": https://scrivio-interview-library.netlify.app/spring-boot/security-architecture/af12c17101/

More in Spring Security architecture