Spring Security architecture
30 questions in 8 subtopics.
Security filter chain
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.A team adds a customJwtLoggingFilter annotated with @Component and also adds it to the security chain with http.addFilterBefore(...). Now the filter runs twice per request, once before authentication has happened. Why?After an upgrade to Spring Security 6, an API returns 401 with an empty body for some errors, where before clients received a JSON error response from /error. What changed and how do you fix it?You lead the upgrade of 80 services from Spring Security 5.x to 6.x (and later 7). Each service has its own security configuration. How would you plan and run the upgrade with minimal risk?Some architects want to move authentication and authorization out of application code (Spring Security) into gateways and service meshes. Others say that makes services unsafe on their own. How would you decide the long-term split of security responsibilities?SecurityFilterChain configuration
Write aSecurityFilterChain bean for a Spring Boot 3 or 4 service where /actuator/health is public, /admin/** needs role ADMIN, all other requests need authentication, and the API is stateless using JWT bearer tokens.An application serves a browser UI with form login under /** and a machine API with JWT under /api/**. How do you configure two SecurityFilterChain beans, and what goes wrong if you get the ordering or matchers wrong?Your organisation has 80 Spring Boot services, each with its own hand-written SecurityFilterChain, and audits find inconsistent rules and some services with permitAll on everything. How would you standardise security configuration?Your company is preparing for SOC 2 and PCI DSS audits across many Spring applications. How would you turn security configuration into auditable controls with evidence, without slowing teams down?DelegatingFilterProxy
What isDelegatingFilterProxy, why does Spring Security need it, and how does Spring Boot register it?A tracing filter and a request-logging filter in your service need the authenticated user's id, but they log null for every request. How would you find out why and fix it?SecurityContext and holder strategies
Explain howSecurityContextHolder stores the current authentication, the available strategies, and why an @Async method sees no authenticated user.After moving from Spring Security 5 to 6, a custom login endpoint that calls SecurityContextHolder.getContext().setAuthentication(auth) logs the user in for that request only; the next request is anonymous. Why?A service uses virtual threads, CompletableFuture pipelines and Reactor in different places. How do you make sure the security context and tracing context reach every piece of work?Asynchronous flows (Kafka events, scheduled jobs, thread pools) lose the user identity that started the work, and audit logs show "system" for many actions. Define a standard for carrying identity through asynchronous work across services.Auditors require that every change to customer data can be traced to the person or system that caused it, across services, batch jobs and messaging, kept for seven years. What long-term identity and audit architecture would you set?AuthenticationManager and providers
How doAuthenticationManager, ProviderManager and AuthenticationProvider work together? What happens when an application supports both username/password and API key authentication?Implement API key authentication for /internal/** in Spring Security: keys are sent in an X-Api-Key header and stored hashed in a database. Describe the classes you would write and how they plug into the filter chain.Today only the API gateway checks tokens, and internal services trust any request that reaches them. Security wants every service to authenticate callers. Design the approach for 60 Spring Boot services.Over 15 years your company has built custom authentication code in many applications. How would you lead a programme to move to standard identity infrastructure, and how do you justify the cost?Authentication entry points and access denied handlers
In Spring Security, what is the difference between anAuthenticationEntryPoint and an AccessDeniedHandler, and which filter calls them?A REST API must return a JSON body {"error": "unauthorized"} with 401 and {"error": "forbidden"} with 403 instead of the default responses. Write the configuration.A Spring Boot API returns 403 for requests with an expired JWT, and clients cannot tell they must refresh the token. What happened and how do you fix it?Different services return different error formats for 401 and 403, and client teams complain. Design a standard across 80 services.Custom authentication filters
Write a custom filter that authenticates requests carrying an X-Service-Token header, and add it to theSecurityFilterChain. Where in the chain should it go?Compare writing a custom OncePerRequestFilter, using AuthenticationFilter with an AuthenticationConverter, and extending AbstractAuthenticationProcessingFilter for a new authentication method.Security review finds 30 services with hand-written authentication filters, each validating tokens slightly differently. What do you do?Spring Security 6 and 7 changes
Your code base usesWebSecurityConfigurerAdapter, antMatchers and authorizeRequests. What replaces each in Spring Security 6 and later?Plan an upgrade of a service from Spring Security 5.8 to 6.x and then 7.x. What steps reduce risk?Spring Security has broken compatibility several times (5 to 6, 6 to 7). How do you plan for security framework upgrades as a recurring cost across a large organisation?No question matches these choices.