shiro源码阅读记录

1.创建org.apache.shiro.session.Sesseion

shiro默认调用原生HttpSession来记录登录信息。在将HttpSession封装为org.apache.shiro.session.Sesseion。

调用链为:

可见在创建Subject之前先得到HttpSession并封装为org.apache.shiro.session.Sesseion。

 

2.认证

比对token和认证信息的特征

UsernamePasswordToken.getCredentials()

 

3.默认过滤器定义在org.apache.shiro.web.filter.mgt.DefaultFilter中

 

4.shiro 路径匹配

首先进入OncePerRequestFilter过滤器

在org.apache.shiro.web.servlet.AbstractShiroFilter#executeChain产生一个增强的FilterChain类org.apache.shiro.web.servlet.ProxiedFilterChain

从上面449行进入org.apache.shiro.web.servlet.AbstractShiroFilter#getExecutionChain到

org.apache.shiro.web.filter.mgt.PathMatchingFilterChainResolver#getChain到org.apache.shiro.web.filter.mgt.DefaultFilterChainManager#getChainNames

可知org.apache.shiro.web.servlet.ProxiedFilterChain存有根据路径匹配的过滤器,如不匹配返回原始的FilterChain

org.apache.shiro.web.servlet.ProxiedFilterChain#doFilter

可见如果shiro所有过滤器走完后就走原始过滤器链。

其中shiro过滤器就是在配置shiro工厂org.apache.shiro.spring.web.ShiroFilterFactoryBean中配置的过滤器路径映射,之后创建shiro过滤器的时候在DefaultFilterChainManager中存了一份。

 

org.apache.shiro.web.servlet.OncePerRequestFilter#doFilter到org.apache.shiro.web.servlet.AdviceFilter#doFilterInternal到org.apache.shiro.web.filter.PathMatchingFilter#preHandle

可见执行过滤器还要进行一次preHandle校验,因为个过滤器里面也存了一份匹配路径。第一个匹配上的路径就在org.apache.shiro.web.filter.PathMatchingFilter#isFilterChainContinued里执行shiro过滤器

org.apache.shiro.web.filter.AccessControlFilter#onPreHandle中可看出自定义的过滤器继承父类后的判断逻辑。

 

其中权限过滤器org.apache.shiro.web.filter.authz.PermissionsAuthorizationFilter的流程为

org.apache.shiro.subject.support.DelegatingSubject#isPermitted再一直进到org.apache.shiro.realm.AuthorizingRealm#getAuthorizationInfo

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值