shiro的源碼學習(四)-- 深入理解realm
阿新 • • 發佈:2017-07-21
instance his face 成功 返回 void exce gen 調用
IniRealm的類結構如下圖:
下面分析每個類:
(1)Ream:
域的頂點,其代碼如下:securityManager會使驗證器來調用,驗證器通過Realm返回用戶信息,確定用戶是否登錄成功:
1 public interface Realm { 2 String getName();//返回Realm的名字,唯一 3 boolean supports(AuthenticationToken token);//校驗token 4 AuthenticationInfo getAuthenticationInfo(AuthenticationToken token) throwsAuthenticationException;//返回用戶信息 5 }
(2) CachingRealm:
緩存域,支持用戶信息的緩存:可以註入緩存器,支持Realm名字的修改,支持用戶的登出:
1 public abstract class CachingRealm implements Realm, Nameable, CacheManagerAware, LogoutAware { 2 private String name; 3 private boolean cachingEnabled;//支持緩存,默認為true 4 private CacheManager cacheManager; //註入緩存器5 public CachingRealm() { 6 this.cachingEnabled = true; 7 this.name = getClass().getName() + "_" + INSTANCE_COUNT.getAndIncrement(); 8 } 9 ........... 10 public void setCacheManager(CacheManager cacheManager) { 11 this.cacheManager = cacheManager; 12 afterCacheManagerSet();13 } 14 public void onLogout(PrincipalCollection principals) { 15 clearCache(principals); 16 } 17 18 ........ 19 }
shiro的源碼學習(四)-- 深入理解realm