Scrivio Interview library

Spring Security architecture

30 questions in 8 subtopics.

Security filter chain

InternalsFoundations6 min read
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.
DebuggingFoundations6 min read
A team adds a custom JwtLoggingFilter 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?
DebuggingIntermediate6 min read
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?
ScenarioAdvanced6 min read
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?
LeadershipPrincipal6 min read
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

CodingFoundations6 min read
Write a SecurityFilterChain 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.
DesignIntermediate6 min read
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?
LeadershipAdvanced6 min read
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?
LeadershipPrincipal6 min read
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

ConceptFoundations7 min read
What is DelegatingFilterProxy, why does Spring Security need it, and how does Spring Boot register it?
ScenarioIntermediate7 min read
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

InternalsFoundations6 min read
Explain how SecurityContextHolder stores the current authentication, the available strategies, and why an @Async method sees no authenticated user.
DebuggingFoundations6 min read
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?
ScenarioIntermediate7 min read
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?
DesignAdvanced7 min read
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.
LeadershipPrincipal7 min read
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

InternalsFoundations6 min read
How do AuthenticationManager, ProviderManager and AuthenticationProvider work together? What happens when an application supports both username/password and API key authentication?
CodingIntermediate7 min read
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.
DesignAdvanced6 min read
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.
LeadershipPrincipal7 min read
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

ConceptFoundations5 min read
In Spring Security, what is the difference between an AuthenticationEntryPoint and an AccessDeniedHandler, and which filter calls them?
CodingFoundations6 min read
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.
DebuggingIntermediate7 min read
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?
DesignAdvanced6 min read
Different services return different error formats for 401 and 403, and client teams complain. Design a standard across 80 services.

Custom authentication filters

CodingFoundations7 min read
Write a custom filter that authenticates requests carrying an X-Service-Token header, and add it to the SecurityFilterChain. Where in the chain should it go?
DesignIntermediate6 min read
Compare writing a custom OncePerRequestFilter, using AuthenticationFilter with an AuthenticationConverter, and extending AbstractAuthenticationProcessingFilter for a new authentication method.
ScenarioAdvanced6 min read
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

ConceptFoundations5 min read
Your code base uses WebSecurityConfigurerAdapter, antMatchers and authorizeRequests. What replaces each in Spring Security 6 and later?
ScenarioIntermediate7 min read
Plan an upgrade of a service from Spring Security 5.8 to 6.x and then 7.x. What steps reduce risk?
LeadershipPrincipal6 min read
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?