shiro

shiro是apache的一個開源框架,是一個權限管理的框架,實現 用戶認證、用戶受權。
spring中有spring security (原名Acegi),是一個權限框架,它和spring依賴過於緊密,沒有shiro使用簡單。
shiro不依賴於spring,shiro不只能夠實現 web應用的權限管理,還能夠實現c/s系統,分佈式系統權限管理,shiro屬於輕量框架,愈來愈多企業項目開始使用shiro。
使用shiro實現系統 的權限管理,有效提升開發效率,從而下降開發成本。web

認證原理:
一、經過ini配置文件建立securityManager
二、調用subject.login方法主體提交認證,提交的token
三、securityManager進行認證,securityManager最終由ModularRealmAuthenticator進行認證。
四、ModularRealmAuthenticator調用IniRealm(給realm傳入token) 去ini配置文件中查詢用戶信息
五、IniRealm根據輸入的token(UsernamePasswordToken,即這裏的token是用戶從頁面輸入的信息)從 shiro-first.ini查詢用戶信息(這裏是測試階段,後面都是查詢的數據庫,注入service,調用dao),根據帳號查詢用戶信息(帳號和密碼) 若是查詢到用戶信息,就給ModularRealmAuthenticator返回用戶信息(帳號和密碼) 若是查詢不到,就給ModularRealmAuthenticator返回null
六、ModularRealmAuthenticator接收IniRealm返回Authentication認證信息 若是返回的認證信息是null,ModularRealmAuthenticator拋出異常(org.apache.shiro.authc.UnknownAccountException)spring

若是返回的認證信息不是null(說明inirealm找到了用戶),對IniRealm返回用戶密碼 (在ini文件中存在)和 token中的密碼 進行對比,若是不一致拋出異常(org.apache.shiro.authc.IncorrectCredentialsException)數據庫

相關文章
相關標籤/搜索