Security for Spring Boots
Spring Security is the framework that protects a Spring Boot application through authentication and authorisation. A chain of servlet filters checks identity, using sessions, JWT or OAuth2, and decides which requests are allowed. Method security adds checks such as @PreAuthorize on service methods, so rules apply even outside the web layer.
Stage: Security and Integration · Part of the Spring Boot roadmap · Last reviewed 19 November 2026
What to learn in Security
- Define a SecurityFilterChain bean that permits public routes and protects the rest
- Hash passwords with BCrypt through a PasswordEncoder bean
- Validate a JWT bearer token on each API request
- Restrict a service method by role using @PreAuthorize
- Configure CORS and understand why CSRF protection matters for session apps
Security interview questions
How do authentication and authorisation map to Spring Security filters and annotations?
Authentication proves who the caller is, for example by checking a password or token. Authorisation decides what that identity may do, such as whether a user may delete an order. Spring Security performs authentication first, then evaluates authorities and roles for access. Roles are checked after the filter authenticates the caller.
Why disable CSRF for a stateless JWT API?
CSRF attacks exploit browsers that attach cookies automatically. A stateless API that reads a bearer token from the Authorization header is not exposed to that, since the browser will not add it by itself. Apps that rely on session cookies should keep CSRF protection on.
Where Security fits in the Spring Boot roadmap
Security belongs to the Security and Integration stage (intermediate level), which takes about 21 hours. Protect and connect.
Other units in this stage
Back to the full Spring Boot roadmap