全面解析Spring Security 過濾器鏈的機制和特性
1. 前言
過濾器作為 Spring Security 的重中之重,我們需要了解其中的機制。這樣我們才能根據(jù)業(yè)務(wù)需求的變化進行定制。今天來探討一下 Spring Security 中的過濾器鏈機制。
2. Spring Security 過濾器鏈
客戶端(APP 和后臺管理客戶端)向應(yīng)用程序發(fā)送請求,然后應(yīng)用根據(jù)請求的 URI 的路徑來確定該請求的過濾器鏈(Filter)以及最終的具體 Servlet 控制器(Controller)。
從上圖我們可以看出 Spring Security 以一個單 Filter(FilterChainProxy) 存在于整個過濾器鏈中,而這個 FilterChainProxy 實際內(nèi)部代理著眾多的 Spring Security Filter 。這簡直就是套娃啊!
2.1 過濾器鏈的形成過程
再多說一點 Filter 們的初始化過程,首先 Filter 們按照一定的順序被 SecurityBuilder 的實現(xiàn)來組裝為 SecurityFilterChain ,然后通過 WebSecurity 注入到 FilterChainProxy 中去,接著 FilterChainProxy 又在 WebSecurityConfiguration 中以 springSecurityFilterChain 的名稱注冊為 Spring Bean 。實際上還有一個隱藏層 DelegatingFilterProxy 代理了 springSecurityFilterChain 注入到最后整個 Servlet 過濾器鏈中。簡單畫了個圖;
事實上 Spring Security 的內(nèi)置 Filter 對于 Spring IoC 容器來說都是不可見的。
”Spring Security 允許有多 條過濾器鏈并行,Spring Security 的 FilterChainProxy 可以代理多條過濾器鏈并根據(jù)不同的 URI 匹配策略進行分發(fā)。但是每個請求每次只能被分發(fā)到一條過濾器鏈。如下圖所示:
關(guān)于 Filter 的其它細(xì)節(jié)可以通過 相關(guān)文章[1] 了解。
★實際每條過濾鏈 就是一個 SecurityFilterChain
”4. 總結(jié)
今天我們通過對 Spring Security 中 過濾器鏈機制,對于深入學(xué)習(xí) Spring Security 有著至關(guān)重要的意義。有什么問題和心得請留言反饋。
參考資料
相關(guān)文章: https://www.felord.cn/spring-security-filters.html
到此這篇關(guān)于Spring Security 過濾器鏈的機制和特性的文章就介紹到這了,更多相關(guān)Spring Security 過濾器鏈內(nèi)容請搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!
相關(guān)文章:
1. html中的form不提交(排除)某些input 原創(chuàng)2. ASP動態(tài)網(wǎng)頁制作技術(shù)經(jīng)驗分享3. ASP常用日期格式化函數(shù) FormatDate()4. CSS3實現(xiàn)動態(tài)翻牌效果 仿百度貼吧3D翻牌一次動畫特效5. asp.net core項目授權(quán)流程詳解6. XMLHTTP資料7. vue使用moment如何將時間戳轉(zhuǎn)為標(biāo)準(zhǔn)日期時間格式8. CSS3中Transition屬性詳解以及示例分享9. jsp文件下載功能實現(xiàn)代碼10. 開發(fā)效率翻倍的Web API使用技巧
