2019獨角獸企業重金招聘Python工程師標準>>>
? ? 注意:AuthenticationProvider與Authentication緊密聯系,關于Authentication,看我的這篇博客。
????先上一張圖,如下圖1
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 圖1 AuthenticationProvider的類圖
? ? AuthenticationProvider是個接口,通過實現這個接口,實現拓展,此圖來自于《Pro Spring Security》的Chapter3:
? ? ? ? ? ? ? ? ? ? ? ? ?
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 圖2 AuthenticationProvider的繼承圖
? ? 來看個例子,DaoAuthenticationProvider,它的類圖如下圖3,使用了Template pattern,在AbstractUserDetilsAuthenticationProvider中定義執行邏輯,而在DaoAuthenticationProvider中有具體實現。Template pattern可以在一定程度上理解為父類調用子類。
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 圖3 DaoAuthenticationProvider的類圖
?
參考:
? ? 1. Carlo Scarioni, Pro Spring Security.