shiro框架源码解析与改造(二)---ShiroFilterFactoryBean

ShiroFilterFactoryBean是shiro框架的核心起始类,是shiro框架一切流程的源头。

上文已经知道,DelegatingFilterProxy会从springmvc容器中查找这个类,并代理执行。
那么ShiroFilterFactoryBean类具体是干什么的呢?

查看源码可以看到ShiroFilterFactoryBean实现了 FactoryBean接口,所以真正注册到springmvc容器中的类并不是ShiroFilterFactoryBean本身,而是另外一个类。

@Override
    public Object getObject() throws Exception {
        if(this.instance == null) {
            this.instance = this.createInstance();
        }
        return this.instance;
    }

这个类实例就是intstance,下面看看createInstance()方法具体干了什么:

protected AbstractShiroFilter createInstance() throws Exception {
        log.debug("Creating Shiro Filter instance.");
        SecurityManager securityManager = this.getSecurityManager();
        String msg;
        if(securityManager == null) {
            msg = "SecurityManager property must be set.";
            throw new BeanInitializationException(msg);
        } else if(!(securityManager instanceof WebSecurityManager)) {
            msg = "The security manager does not implement the WebSecurityManager interface.";
            throw new BeanInitializationException(msg);
        } else {
            FilterChainManager manager = this.createFilterChainManager();
            PathMatchingFilterChainResolver chainResolver = new PathMatchingFilterChainResolver();
            chainResolver.setFilterChainManager(manager);
            return new SpringShiroFilter((WebSecurityManager)securityManager, chainResolver,this.notFilters);
        }
    }

这个方法有点复杂,做的事情比较多。

首先是获取安全管理器SecurityManager ,这是也是需要预先配置的
 SecurityManager securityManager = this.getSecurityManager();
 然后创建FilterChainManager, 
 PathMatchingFilterChainResolver,
 SpringShiroFilter

可以看到最后真正注册到springmvc容器中的bean是springShiroFilter。所以实际实行的filter也是它。
关于FilterChainManager,PathMatchingFilterChainResolver,SpringShiroFilter这三个类将在后文一 一解析。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值