Security Errors and API Hardening
Learn Security Errors and API Hardening (Spring Security, Spring Boot) with worked examples, diagrams and interview questions. Free on JavaSchoolLab.
Why Your @RestControllerAdvice Does Not See Security Errors Security runs in servlet filters , before the request reaches Spring MVC. An unauthenticated or forbidden request is rejected inside the filter chain, so your controller advice never sees it. Without extra setup the client gets a plain empty 401/403 (or, for browsers, a redirect to a login page) - not the JSON error your API returns everywhere else.
More lessons in Spring Security
- Spring Boot Security Basics
- How Spring Security Authenticates
- SecurityFilterChain: Securing URLs
- Users and Passwords (BCrypt)
- Roles, Authorities and RBAC
- Method-Level Security
- CSRF and CORS
- Spring Security - Hands-On Setup
- JWT Authentication
- OAuth 2.0, OpenID Connect and Social Login
- Mini Project: Role-based API Security (Basic Auth)