Spring Security is one of the most important frameworks in modern Java application development. Whether you are building REST APIs, microservices or enterprise applications, securing resources and controlling access is a critical requirement.

As a result, Spring Security questions frequently appear in technical interviews for Spring Boot developers, senior developers and solution architects.
This article covers the most commonly asked Spring Security interview questions along with detailed answers and practical explanations.
Who Should Read This Article?
- Java Developers
- Spring Boot Developers
- Backend Engineers
- Microservices Developers
- Interview Candidates
1. What is Spring Security?
Spring Security is the official security framework provided by the Spring ecosystem. It offers a comprehensive set of features for authentication, authorization and protection against common security vulnerabilities.
Before Spring Security, developers often implemented authentication and authorization manually, which resulted in inconsistent security implementations and increased maintenance effort.
Spring Security standardizes application security and provides powerful capabilities such as:
- Authentication
- Authorization
- Password Encoding
- Session Management
- CSRF Protection
- JWT Integration
- OAuth2 Support
Interview Tip: Mention that Spring Security is deeply integrated with Spring Boot and is the standard security framework used in enterprise Java applications.
2. What is Authentication?
Authentication is the process of verifying the identity of a user.
Authentication answers the question:
Who are you?
When a user submits credentials such as a username and password, Spring Security validates those credentials against a configured user store.
Only after successful verification is the user considered authenticated.
Examples of authentication mechanisms include:
- Username and Password
- JWT Authentication
- OAuth2 Login
- Single Sign-On (SSO)
- Multi-Factor Authentication (MFA)
3. What is Authorization?
Authorization is the process of determining what an authenticated user is allowed to access.
Authorization answers the question:
What are you allowed to do?
For example, an ADMIN user may be allowed to delete records while a USER may only view data.
Authentication always occurs before authorization because the system must know the user's identity before assigning permissions.
4. What is the Difference Between Authentication and Authorization?
| Authentication | Authorization |
|---|---|
| Verifies Identity | Verifies Permissions |
| Who Are You? | What Can You Access? |
| Executed First | Executed After Authentication |
A simple way to remember:
Authentication
↓
Authorization
5. What is SecurityFilterChain?
SecurityFilterChain is the foundation of modern Spring Security configuration.
Every incoming request passes through a chain of security filters before reaching application controllers.
Client Request
|
v
SecurityFilterChain
|
v
Authentication
|
v
Authorization
|
v
Controller
The SecurityFilterChain is responsible for validating credentials, checking permissions and protecting application endpoints.
6. Why was WebSecurityConfigurerAdapter Deprecated?
Spring Security moved away from inheritance-based configuration in favour of bean-based configuration using SecurityFilterChain.
This approach is more flexible, easier to understand and aligns better with modern Spring Boot development practices.
7. What is UserDetailsService?
UserDetailsService is a Spring Security interface used to load user details during authentication.
UserDetailsService
When a user attempts to log in, Spring Security calls the UserDetailsService implementation to retrieve information about that user.
8. What is UserDetails?
UserDetails represents a security user inside Spring Security.
It contains information such as:
- Username
- Password
- Roles
- Authorities
- Account Status
9. What is PasswordEncoder?
PasswordEncoder is used to securely encode passwords before storing them in a database.
Storing plain text passwords is a major security risk and should always be avoided.
10. Why is BCryptPasswordEncoder Commonly Used?
BCrypt is one of the most widely used password hashing algorithms because it generates secure hashes and automatically applies salting.
This makes password cracking significantly more difficult.
new BCryptPasswordEncoder()
11. What is JWT?
JWT stands for JSON Web Token. It is a compact and self-contained token used for stateless authentication. After successful login, the server generates a token and returns it to the client. The client includes the token in subsequent requests using the Authorization header.
Authorization:
Bearer eyJhbGciOi...
12. What are the Three Parts of JWT?
A JWT consists of three sections:
Header
Payload
Signature
The Header stores metadata, the Payload contains claims and the Signature protects token integrity.
13. Why is JWT Popular in REST APIs?
JWT supports stateless authentication.
The server does not need to maintain session information, making JWT ideal for cloud-native and microservice architectures.
14. What is Role-Based Access Control (RBAC)?
Role-Based Access Control restricts system access based on roles assigned to users.
ADMIN
MANAGER
USER
Each role receives specific permissions.
15. What is SecurityContext?
SecurityContext stores information about the currently authenticated user.
After authentication succeeds, Spring Security stores Authentication details inside the SecurityContext.
SecurityContextHolder
.getContext()
16. What is CSRF?
CSRF (Cross-Site Request Forgery) is an attack where a malicious website tricks a user's browser into sending unwanted requests.
Spring Security provides built-in CSRF protection for web applications.
17. Why is CSRF Often Disabled for REST APIs?
Most REST APIs use stateless authentication with JWT instead of server-side sessions.
In those cases, CSRF protection is often disabled because session-based attacks are less relevant.
18. What is OncePerRequestFilter?
OncePerRequestFilter ensures a filter executes only once during request processing.
JWT validation filters commonly extend this class.
19. What is Method-Level Security?
Method-Level Security applies authorization rules directly to methods.
@PreAuthorize(
"hasRole('ADMIN')"
)
Only users with appropriate permissions can invoke the method.
20. What is the Difference Between 401 and 403?
| Status Code | Meaning |
|---|---|
| 401 | User is not authenticated |
| 403 | User is authenticated but lacks required permissions |
21. What is OAuth2?
OAuth2 is an authorization framework that allows third-party applications to access resources on behalf of users without sharing passwords.
Examples include Google Login and GitHub Login.
22. What is Session Management?
Session management controls how user sessions are created, maintained and terminated.
Traditional applications commonly rely on sessions for authentication.
23. What is Stateless Authentication?
In stateless authentication, the server does not store session information.
Each request contains all required authentication information, typically through a JWT token.
24. What are Spring Security Filters?
Filters are components that process requests before they reach controllers.
Examples include:
- Authentication Filter
- Authorization Filter
- JWT Filter
- Logout Filter
25. Explain the Spring Security Request Lifecycle.
Client Request
|
v
SecurityFilterChain
|
v
Authentication
|
v
Authorization
|
v
Security Context
|
v
Controller
Every incoming request passes through this process before business logic is executed.
Recommended Spring Security Learning Path
Spring Security Basics
↓
Authentication vs Authorization
↓
RBAC
↓
SecurityFilterChain
↓
JWT Authentication
↓
OAuth2
Related Articles
- Spring Security Explained for Beginners with Real Examples
- Authentication vs Authorization in Spring Security
- JWT Authentication in Spring Boot Explained with Real Examples
- Role-Based Access Control (RBAC) in Spring Security
- SecurityFilterChain in Spring Security Explained with Real Examples
Conclusion
Spring Security remains one of the most important frameworks in the Java ecosystem. Understanding Authentication, Authorization, JWT, RBAC, SecurityFilterChain and password encoding concepts is essential for building secure applications and performing well in Spring Security interviews.
Reviewed by 13thGhost
on
10:07 PM
Rating: