1 public interface Realm {
2 String getName();//返回Realm的名字,唯一
3 boolean supports(AuthenticationToken token);//校验token
4 AuthenticationInfo getAuthenticationInfo(AuthenticationToken token) throws AuthenticationException;//返回用户信息
5 }
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 }