Nội dung
Danh sách bài học
- 01~4 phút
Security Architecture & Filter Chain — tổng quan
Module này mổ kiến trúc Spring Security: chuỗi filter, luồng authentication, và cấu hình SecurityFilterChain DSL.
- 02~12 phút
Filter chain architecture — Spring Security đứng trước DispatcherServlet ra sao
Spring Security không hook vào Spring MVC — nó là một chuỗi Servlet Filter chạy trước DispatcherServlet. Bài này giải thích tại sao thiết kế đó đúng, FilterChainProxy là gateway duy nhất, 15+ filter mỗi cái một trách nhiệm, và Security 6 lambda DSL thay thế WebSecurityConfigurerAdapter như thế nào.
- 03~12 phút
Authentication flow & SecurityContext — từ request đến principal trong ThreadLocal
Bóc đúng một mảnh của Spring Security: request đi qua filter, AuthenticationManager điều phối AuthenticationProvider để trả Authentication hoặc ném exception; kết quả lưu vào SecurityContextHolder ThreadLocal per-request. Giải thích tại sao ThreadLocal, tại sao tách authentication/authorization, và cơ chế exception mapping 401/403.
- 04~12 phút
SecurityFilterChain DSL — khai báo security bằng lambda Spring Security 6
Spring Security 6 thay WebSecurityConfigurerAdapter bằng @Bean SecurityFilterChain + HttpSecurity lambda DSL. Bài này bóc cú pháp requestMatchers, authorizeHttpRequests, các DSL method phổ biến (csrf/cors/sessionManagement/oauth2), và lý do thiết kế: tại sao lambda DSL composable + type-safe hơn chained .and() cũ.
- 05~13 phút
Multiple SecurityFilterChain & Stateless JWT — tách chain theo nhóm endpoint
Một app Spring có thể chạy song song nhiều SecurityFilterChain bean với @Order + securityMatcher để áp dụng policy khác nhau cho từng nhóm URL. Bài này bóc cơ chế FilterChainProxy chọn chain, cách cấu hình stateless cho JWT REST API (SessionCreationPolicy.STATELESS + csrf disable), và WebSecurityCustomizer để bypass static resources.
- 06~4 phút
Security Architecture & Filter Chain — tổng kết
Tóm tắt Security Architecture & Filter Chain.