ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

shiro mgt包下RealmSecurityManager类

2021-11-29 09:02:57  阅读:193  来源: 互联网

标签:RealmSecurityManager Realm void Collection realms mgt realm null shiro


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,将其设置为空。

标签:RealmSecurityManager,Realm,void,Collection,realms,mgt,realm,null,shiro
来源: https://blog.csdn.net/weixin_45912825/article/details/121585509

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有