← Spring Boot learning pathSpring Boot · Module 7 of 10
Spring Security
Protect endpoints with authentication and authorisation.
📖 Key ideas
- Adding spring-boot-starter-security secures all endpoints by default.
- Configure a SecurityFilterChain bean to set rules.
- Passwords encoded with BCryptPasswordEncoder.
- JWT or OAuth2 resource server for APIs.
- Method security: @PreAuthorize("hasRole('ADMIN')").
💡 Real-life example: Spring Security is a security office with checkpoints (filters) every request passes through.
SecurityFilterChainBean defining security rules
BCryptPasswordEncoderHashes passwords
@PreAuthorizeMethod-level access rule
OAuth2Standard for delegated authorisation