shiro mgt包下RealmSecurityManager类

2021SC@SDUSC
类图:
在这里插入图片描述

私有变量

realms

private Collection<Realm> realms;

用于所有身份验证和授权操作的Realm 的内部集合。

方法分析

setRealm

public void setRealm(Realm realm) {
        if (realm == null) {
            throw new IllegalArgumentException("Realm argument cannot be null");
        }
        Collection<Realm> realms = new ArrayList<Realm>(1);
        realms.add(realm);
        setRealms(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.");
        }
        this.realms = realms;
        afterRealmsSet();
    }

设置由这个 SecurityManager 实例管理的realms。

afterRealmsSet

protected void afterRealmsSet() {
        applyCacheManagerToRealms();
        applyEventBusToRealms();
    }

在设置完Realms之后执行该方法,堆Realms应用CacheManager和EventBus

getRealms

public Collection<Realm> getRealms() {
        return realms;
    }

返回由此 SecurityManager 实例管理的 Realm。

applyCacheManagerToRealms

 protected void applyCacheManagerToRealms() {
        CacheManager cacheManager = getCacheManager();
        Collection<Realm> realms = getRealms();
        if (cacheManager != null && realms != null && !realms.isEmpty()) {
            for (Realm realm : realms) {
                if (realm instanceof CacheManagerAware) {
                    ((CacheManagerAware) realm).setCacheManager(cacheManager);
                }
            }
        }
    }

在任何内部配置上设置内部 CacheManager,实现了 CacheManagerAware 接口。
通过 setCacheManager 方法在此 securityManager 上设置 cacheManager 后调用此方法,以允许它向下传播到需要使用它的所有内部Realm。
在通过 setRealm 或 setRealms 方法设置一个或多个领域后,它也会被调用,以允许这些新可用的Realm被赋予已在使用的缓存管理器。

applyEventBusToRealms

protected void applyEventBusToRealms() {
        EventBus eventBus = getEventBus();
        Collection<Realm> realms = getRealms();
        if (eventBus != null && realms != null && !realms.isEmpty()) {
            for(Realm realm : realms) {
                if (realm instanceof EventBusAware) {
                    ((EventBusAware)realm).setEventBus(eventBus);
                }
            }
        }
    }

在任何内部配置上设置内部 EventBus,实现了 EventBusAware 接口。
通过setEventBus 方法在此 securityManager 上设置 eventBus 后调用此方法,以允许它向下传播到需要使用它的所有内部Realm。
它也会在通过 setRealm 或setRealms方法设置一个或多个领域后调用,以允许为这些新可用的领域提供已在使用的 EventBus。

afterCacheManagerSet

protected void afterCacheManagerSet() {
        super.afterCacheManagerSet();
        applyCacheManagerToRealms();
    }

只需调用applyCacheManagerToRealms() 以允许将新设置的 CacheManager 传播到需要的Realm内部集合用它。

afterEventBusSet

 protected void afterEventBusSet() {
        super.afterEventBusSet();
        applyEventBusToRealms();
    }

只需调用applyEventBusToRealms 以允许将新设置的 CacheManager 传播到需要的Realm内部集合用它。

destroy

public void destroy() {
        LifecycleUtils.destroy(getRealms());
        this.realms = null;
        super.destroy();
    }

删除realms,将其设置为空。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值