Java Interview Preparation
Spring Security Interview Questions
Authentication, authorization, filter chains, JWT, OAuth, CSRF, and endpoint security.
Spring Security Interview Focus
Authentication, authorization, filter chains, JWT, OAuth, CSRF, and endpoint security.
Interview questions
1. How does Spring Security work in Spring Boot? Beginner
Spring Security uses filters to inspect requests, authenticate users, create a security context, and authorize access. Spring Boot provides the dependencies and a convenient configuration entry point.
2. What are authentication and authorization? Beginner
Authentication answers “Who are you?” Authorization answers “What are you allowed to do?” A secure application performs both checks before protected work.
3. What is the Spring Security filter chain? Intermediate
The filter chain is an ordered set of servlet filters that handles security concerns such as credentials, sessions, CSRF, and authorization. SecurityFilterChain is the bean used to configure those rules.
4. What is SecurityFilterChain? Intermediate
The filter chain is an ordered set of servlet filters that handles security concerns such as credentials, sessions, CSRF, and authorization. SecurityFilterChain is the bean used to configure those rules.
5. How do you configure endpoint authorization? Intermediate
Configure request rules in SecurityFilterChain using requestMatchers and authenticated, hasRole, or hasAuthority. Put specific rules before broad fallback rules.
6. What is the difference between roles and authorities? Intermediate
An authority is a permission string. A role is a conventionally named authority, often prefixed with ROLE_. Use roles for broad groups and authorities for fine-grained permissions.
7. How do you implement JWT authentication? Advanced
A JWT contains a header, claims payload, and signature. The server verifies the signature and important claims such as issuer and expiry, then uses the subject or authorities for authorization. Short-lived access tokens and a controlled refresh-token flow reduce risk.
8. What are the components of a JWT? Intermediate
A JWT contains a header, claims payload, and signature. The server verifies the signature and important claims such as issuer and expiry, then uses the subject or authorities for authorization. Short-lived access tokens and a controlled refresh-token flow reduce risk.
9. How do you validate and refresh JWT tokens? Advanced
A JWT contains a header, claims payload, and signature. The server verifies the signature and important claims such as issuer and expiry, then uses the subject or authorities for authorization. Short-lived access tokens and a controlled refresh-token flow reduce risk.
10. What is OAuth 2.0? Beginner
OAuth 2.0 is an authorization framework that lets a client obtain limited access to a resource on behalf of a user or service. It defines flows and tokens; it is not itself a user-identity protocol.
11. What is OpenID Connect? Intermediate
OpenID Connect adds an identity layer on top of OAuth 2.0. It provides an ID token and standard user claims so a client can verify who authenticated.
12. What is CSRF? Beginner
CSRF protects browser-based applications from forged state-changing requests. CORS controls which browser origins may call an API. They solve different problems and should not be treated as substitutes.
13. When should CSRF protection be disabled? Advanced
CSRF protects browser-based applications from forged state-changing requests. CORS controls which browser origins may call an API. They solve different problems and should not be treated as substitutes.
14. What is CORS, and how is it different from CSRF? Intermediate
CSRF protects browser-based applications from forged state-changing requests. CORS controls which browser origins may call an API. They solve different problems and should not be treated as substitutes.
15. How do you implement method-level security? Intermediate
Enable method security and place authorization annotations on service methods. @PreAuthorize checks an expression before execution, while @PostAuthorize checks it after the method returns.
16. What are @PreAuthorize and @PostAuthorize? Intermediate
Enable method security and place authorization annotations on service methods. @PreAuthorize checks an expression before execution, while @PostAuthorize checks it after the method returns.
17. How do you store passwords securely? Beginner
Store a one-way adaptive hash, never plaintext or reversible encryption. PasswordEncoder implementations such as BCrypt or a delegating encoder salt and hash passwords and can support algorithm upgrades.
18. What is PasswordEncoder? Beginner
Store a one-way adaptive hash, never plaintext or reversible encryption. PasswordEncoder implementations such as BCrypt or a delegating encoder salt and hash passwords and can support algorithm upgrades.
19. How do you secure Actuator endpoints? Advanced
Actuator exposes operational endpoints such as health, info, metrics, loggers, and mappings. Expose only the endpoints needed by operators and protect them with authentication and network controls.
20. What are the major changes in Spring Security 6? Advanced
Spring Security 6 uses the Jakarta namespace and requires modern Java and Spring versions. WebSecurityConfigurerAdapter is removed, so applications configure one or more SecurityFilterChain beans and use the updated authorization APIs.
How to Prepare for Java Technical Interviews
Use this Java technical interview question bank to revise core concepts and practise explaining your decisions clearly. The questions cover Java fundamentals, object-oriented programming, collections, exceptions, multithreading, Spring Boot, Hibernate, databases, and other topics used in real software development interviews.
Start with the fundamentals, then move to scenario-based questions and advanced topics. Filter questions by difficulty to build confidence gradually. A strong answer should define the concept, explain why it matters, and include a practical example when appropriate.
Continue your preparation with the Java tutorials, or explore all interview preparation tracks for managerial and company-focused questions.
