← Spring Boot learning path
Spring Boot · Module 7 of 10

Spring Security

Protect endpoints with authentication and authorisation.

📖 Key ideas

  1. Adding spring-boot-starter-security secures all endpoints by default.
  2. Configure a SecurityFilterChain bean to set rules.
  3. Passwords encoded with BCryptPasswordEncoder.
  4. JWT or OAuth2 resource server for APIs.
  5. 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