Spring / Spring7 Intermediate to Advanced Interview questions
Explain the execution flow of a request through the Spring Security filter chain?
Every request to a secured application first passes through a single servlet Filter, FilterChainProxy, which delegates to an ordered list of security filters matched to that request's SecurityFilterChain.
flowchart LR
A[Request] --> B[FilterChainProxy]
B --> C[SecurityContextHolderFilter]
C --> D[CsrfFilter]
D --> E[Authentication Filter]
E --> F[ExceptionTranslationFilter]
F --> G[AuthorizationFilter]
G --> H[DispatcherServlet / Controller]
Early filters establish context: SecurityContextHolderFilter loads any existing authentication from the session (or leaves it empty for a stateless JWT setup), and CsrfFilter validates state-changing requests against a CSRF token. An authentication filter appropriate to the configured mechanism - form login, HTTP Basic, a bearer-token resolver, or an OAuth2 login filter - attempts to authenticate the request if it isn't already. ExceptionTranslationFilter wraps everything downstream of it, catching AuthenticationException and AccessDeniedException to redirect to a login page or return a 401/403 as appropriate rather than letting them propagate as generic 500 errors. Finally, AuthorizationFilter makes the actual access decision by consulting the configured AuthorizationManager rules (like the requestMatchers(...).hasAuthority(...) chain) before allowing the request through to DispatcherServlet and the controller.
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
