Shiro 認證模組

2021-10-03 17:36:28 字數 2492 閱讀 7836

僅供參考。

【認證模組】

該模組的核心物件是認證器authenticator,其唯一功能是完成token的認證。

故authenticator介面中只定義了乙個方法(基於提交的token進行認證)authenticationinfo authenticate(authenticationtoken authenticationtoken),由具體的實現類進行實現。

認證器:

authenticator:介面,定義了認證方法。

abstractauthenticator:抽象類,規劃了認證流程,即認證成功、認證失敗、賬戶登出後均通知內部的***進行相應處理。

modularrealmauthenticator:認證實現。其內部關聯了realm(乙個或多個),其實是將認證操作委託給了其關聯的realm,具體的認證細節是由realm實現的。關聯的realm認證之後再由其根據設定的認證策略決定是否認證成功。

認證資訊:

authenticationinfo:介面,定義了賬戶的認證資訊。認證成功時,將其返回。

mergableauthenticationinfo:可合併的認證資訊。多個reaml認證後會返回多個認證資訊,最終需要根據認證策略決定是否將這多個認證資訊合併。介面內部僅定義乙個方法:void merge(authenticationinfo info);

******authenticationinfo:簡單認證資訊。

認證***:

authenticationlistener:當有認證事件(認證成功、認證失敗、賬戶登出)發生時,認證器會通知關聯的***,故首先需要將***和認證器關聯。使用者可以實現該***,在感應對應事件時執行自己的邏輯處理。

認證口令:

authenticationtoken:帳戶主體和支援憑證的合併,是使用者在嘗試身份驗證時提交的。包含最基本的principal(賬戶主體)和credentials(憑證)。

hostauthenticationtoken:該介面拓展了authenticationtoken,新增了主機屬性。

remembermeauthenticationtoken:該介面拓展了authenticationtoken,新增了記住我屬性。

usernamepasswordtoken:是具體的實現。將principal指定為username,credentials指定為password。並實現上述介面,含有主機和記住我屬性。

認證策略:

authenticationstrategy:

abstractauthenticationstrategy:

allsuccessfulstrategy:所有都必須認證成功。

atleastonesuccessfulstrategy:至少有乙個認證成功。

firstsuccessfulstrategy:第乙個認證成功。

認證器呼叫realms執行認證操作,realm執行認證時也是呼叫多個元件完成。

證書匹配器:

credentialsmatcher:該介面僅定義了乙個方法boolean docredentialsmatch(authenticationtoken token, authenticationinfo info),判斷token提供的證書和賬戶的證書是否匹配。

allowallcredentialsmatcher:該證書匹配器總是允許,因為docredentialsmatch的實現總是返回true。

passwordmatcher:密碼匹配器。

******credentialsmatcher:簡單的證書匹配器,實現credentialsmatcher介面。僅將token提供的憑據和賬戶的證書做簡單的值比較。

hashedcredentialsmatcher:繼承******credentialsmatcher類。但重寫了docredentialsmatch方法,將token的憑據進行hash雜湊後再進行對比。

md2credentialsmatcher:繼承hashedcredentialsmatcher類。使用md2演算法計算雜湊。

md5credentialsmatcher:繼承hashedcredentialsmatcher類。使用md5演算法計算雜湊。

sha512credentialsmatcher:繼承hashedcredentialsmatcher類。使用sha512演算法計算雜湊。

sha256credentialsmatcher:繼承hashedcredentialsmatcher類。使用sha256演算法計算雜湊。

sha384credentialsmatcher:繼承hashedcredentialsmatcher類。使用sha384演算法計算雜湊。

sha1credentialsmatcher:繼承hashedcredentialsmatcher類。使用sha1演算法計算雜湊。

密碼服務:包括密碼的加密解密,密碼匹配等

passwordservice:

hashingpasswordservice:拓展passwordservice介面。支援hash形式的密碼。

defaultpasswordservice:具體的實現類。

Shiro許可權認證

shiro的授權以及許可權 關係圖 我們需要在service層中先寫好方法 public inte ce shirouserservice然後imp繼承 service shirouserservice public class shirouserserviceimpl implements shi...

shiro認證授權

1.shiro配置類 1.1需要配置什麼?建立乙個shirofilte ctorybean物件,檢測認證 向bean中傳入securitymanager物件 沒有認證的時候應該訪問哪個url位址 setloginurl 哪些資源是可以被匿名訪問的 setfilterchaindefinitionma...

Shiro使用者認證

通過鳥哥文章學習shiro知識,原文連線 1.搭建乙個spring boot web,然後引入shiro 本篇不講解spring boot web專案搭建,直接在乙個spring boot web 專案基礎上引入shiro並做使用者認證配置。org.apache.shiro shiro spring...