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