标签:instance 学习 信息 image images 理解 默认 登录 support
IniRealm的类结构如下图:
下面分析每个类:
(1)Ream:
域的顶点,其代码如下:securityManager会使验证器来调用,验证器通过Realm返回用户信息,确定用户是否登录成功:
1 public interface Realm { 2 String getName();//返回Realm的名字,唯一 3 boolean supports(AuthenticationToken token);//校验token 4 AuthenticationInfo getAuthenticationInfo(AuthenticationToken token) throws AuthenticationException;//返回用户信息 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 }
标签:instance 学习 信息 image images 理解 默认 登录 support
原文地址:http://www.cnblogs.com/pingqlin341/p/7218884.html