Authentication with Spring Security, JWT and Secure Sessions
Learn Authentication with Spring Security, JWT and Secure Sessions (Phase 12 · Security and Performance (Production), Angular) with worked examples, diagrams and interview questions. Free on JavaSchoolLab.
Choose a session model • Server session (cookie) : after login Spring Security creates a session and sends JSESSIONID as an HttpOnly; Secure; SameSite cookie. Simple, easy to revoke (invalidate the session), JavaScript cannot read the cookie. Requires CSRF protection. Best when Angular and the API share a site. • JWT : the server issues a signed token; the client sends it in Authorization: Bearer ... . Stateless, convenient for multiple services/mobile. Harder to revoke: use short-lived access tokens (5-15 min) plus a refresh token (days) stored in an HttpOnly cookie and rotated on use. • A...