public abstract class CachingSecurityManager implements SecurityManager, Destroyable, CacheManagerAware, EventBusAware {
/**
* The CacheManager to use to perform caching operations to enhance performance. Can be null.
*/
private CacheManager cacheManager;
/**
* The EventBus to use to use to publish and receive events of interest during Shiro's lifecycle.
* @since 1.3
*/
private EventBus eventBus;
/**
* Default no-arg constructor that will automatically attempt to initialize a default cacheManager
*/
public CachingSecurityManager() {
//use a default event bus:
setEventBus(new DefaultEventBus());
}
/**
* Destroys the {@link #getCacheManager() cacheManager} via {@link LifecycleUtils#destroy LifecycleUtils.destroy}.
*/
public void destroy() {
LifecycleUtils.destroy(getCacheManager());
this.cacheManager = null;
LifecycleUtils.destroy(getEventBus());
this.eventBus = new DefaultEventBus();
}
}
复制代码
2.5 RealmSecurityManager(聚合Realm管理功能)
RealmSecurityManager引入成员变量Realm,支持Realm的管理,包罗:注册、销毁等操作;
Realm:Shiro引入的安全组件,支持获取App本地的用户安全相关数据,包罗:用户信息、脚色、权限等,用于执行用户认证和用户鉴权;
官方释义:
A Realm is a security component that can access application-specific security entities
such as users, roles, and permissions to determine authentication and authorization operations.
RealmSecurityManager主要实现如下:
public abstract class RealmSecurityManager extends CachingSecurityManager {
/**
* Internal collection of <code>Realm</code>s used for all authentication and authorization operations.
*/
private Collection<Realm> realms;
public void setRealms(Collection<Realm> realms) {
if (realms == null) {
throw new IllegalArgumentException("Realms collection argument cannot be null.");
}
if (realms.isEmpty()) {
throw new IllegalArgumentException("Realms collection argument cannot be empty.");