日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

Spring Security原理与应用

發布時間:2023/12/2 javascript 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Spring Security原理与应用 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Spring Security是什么

Spring Security是一個能夠為基于Spring的企業應用系統提供聲明式的安全訪問控制解決方案的安全框架。它提供了一組可以在Spring應用上下文中配置的Bean(注:包括認證與權限獲取、配置、處理相關實例),充分利用了Spring IoC,DI(控制反轉Inversion of Control ,DI:Dependency Injection 依賴注入)和AOP(面向切面編程)(注:代理增強類)功能,為應用系統提供聲明式的安全訪問控制功能,減少了為企業系統安全控制編寫大量重復代碼的工作。

核心類庫與認證流程

核心驗證器

AuthenticationManager

該對象提供了認證方法的入口,接收一個Authentiaton對象作為參數;

public interface AuthenticationManager {Authentication authenticate(Authentication authentication) throws AuthenticationException; }

驗證邏輯

AuthenticationManager?接收?Authentication?對象作為參數,并通過?authenticate(Authentication)?方法對其進行驗證;AuthenticationProvider實現類用來支撐對?Authentication?對象的驗證動作;UsernamePasswordAuthenticationToken實現了?Authentication主要是將用戶輸入的用戶名和密碼進行封裝,并供給?AuthenticationManager?進行驗證;驗證完成以后將返回一個認證成功的?Authentication?對象;

ProviderManager

它是?AuthenticationManager?的一個實現類,提供了基本的認證邏輯和方法;它包含了一個?List<AuthenticationProvider>?對象,通過 AuthenticationProvider 接口來擴展出不同的認證提供者(當Spring Security默認提供的實現類不能滿足需求的時候可以擴展AuthenticationProvider?覆蓋supports(Class<?> authentication)?方法);

實現邏輯

public Authentication authenticate(Authentication authentication) throws AuthenticationException { //#1.獲取當前的Authentication的認證類型 Class<? extends Authentication> toTest = authentication.getClass(); AuthenticationException lastException = null; Authentication result = null; boolean debug = logger.isDebugEnabled(); //#2.遍歷所有的providers使用supports方法判斷該provider是否支持當前的認證類型,不支持的話繼續遍歷 for (AuthenticationProvider provider : getProviders()) { if (!provider.supports(toTest)) { continue; } if (debug) { logger.debug("Authentication attempt using " + provider.getClass().getName()); } try { #3.支持的話調用providerauthenticat方法認證 result = provider.authenticate(authentication); if (result != null) { #4.認證通過的話重新生成Authentication對應的Token copyDetails(authentication, result); break; } } catch (AccountStatusException e) { prepareException(e, authentication); // SEC-546: Avoid polling additional providers if auth failure is due to // invalid account status throw e; } catch (InternalAuthenticationServiceException e) { prepareException(e, authentication); throw e; } catch (AuthenticationException e) { lastException = e; } } if (result == null && parent != null) { // Allow the parent to try. try { #5.如果#1 沒有驗證通過,則使用父類型AuthenticationManager進行驗證 result = parent.authenticate(authentication); } catch (ProviderNotFoundException e) { // ignore as we will throw below if no other exception occurred prior to // calling parent and the parent // may throw ProviderNotFound even though a provider in the child already // handled the request } catch (AuthenticationException e) { lastException = e; } } #6. 是否擦敏感信息 if (result != null) { if (eraseCredentialsAfterAuthentication && (result instanceof CredentialsContainer)) { // Authentication is complete. Remove credentials and other secret data

轉載于:https://www.cnblogs.com/free-wings/p/9308592.html

總結

以上是生活随笔為你收集整理的Spring Security原理与应用的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。