Acegi (Spring Security 前身) 是基於 Spring 的安全框架,核心解決「認證」與「授權」兩大問題。
| 概念 | 官方定義 | 通俗理解 |
|---|---|---|
| Authentication (認證) | establishing a principal is who they claim to be | 驗證「你是誰」:帳號/密碼、憑證、Token 對號入座 |
| Authorization (授權) | deciding whether a principal is allowed to perform an action | 判斷「你能做什麼」:角色、權限、ACL 綁定資源 |
Principal:系統中執行動作的主體 (用戶、設備、外部系統)。
配置層 (應用面):FilterChainProxy、AuthenticationManager、AccessDecisionManager、UserDetailsService 等 Bean 組裝。
實現層 (核心面) —「七劍」:
道生一 (核心思想:保護) → 一生二 (認證/授權) → 二生三 (七劍) → 三生萬物 (各種配置與擴充)。
唯有透徹七劍職責與協作,才能在複雜業務中:
• 正確實作 UserDetailsService 對接既有用戶表
• 自訂 AuthenticationProvider 支援多因子驗證
• 擴充 AccessDecisionVoter 實現動態權限
• 排查「為何這個請求被攔截/放行」