shiro-filter执行流程
web中
在xml中配置
<filter> <filter-name>shiroFilter</filter-name> <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class> <async-supported>true</async-supported> <init-param> <param-name>targetFilterLifecycle</param-name> <param-value>true</param-value> </init-param> </filter>
web.xml 中配置了shiroFilter代理,以后每当request请求时都会被改代理拦截,然后代理中调用真正的被代理filter执行处理(还没有弄清楚真正的代理对象怎么变成Filter)
DelegatingFilterProxy中初始化 delegate的过程
根据该<filter>配置中的 <filter-name>=shiroFilter去spring工厂中getBean("shiroFilter",Filter.class) 最终获取到
org.apache.shiro.spring.web.ShiroFilterFactoryBean 的一个单实例,可以看到 ShiroFilterFactoryBean没有实现任何Filter接口,
Filter delegate = wac.getBean(getTargetBeanName(), Filter.class); 生成该Filter

被代理的对象 org.apache.shiro.spring.web.ShiroFilterFactoryBean

Spring生成的是ShiroFilterFactoryBean代理对象 实际上是个Filter
在spring.xml中配置
<!-- Shiro的Web过滤器 -->
<bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
<property name="securityManager" ref="securityManager"/>
<property name="loginUrl" value="/login.jsp"/>
<property name="unauthorizedUrl" value="/unauthorized.jsp"/>
<property name="filters">
<util:map>
<entry key="authc" value-ref="formAuthenticationFilter"/>
</util:map>
</property>
<property name="filterChainDefinitions">
<value>
/index.jsp = anon
/unauthorized.jsp = anon
/login.jsp = authc
/logout = logout
/** = user
</value>
</property>
</bean>
后面所有的处理都是 DelegatingFilterProxy中交给 delegate 去执行的,实际上就是执行一个过滤器链

auth


表单登录

真正调用Realm auth的地方


retryCount判断

密码匹配
登录成功------

AdviceFilter 切面过滤hasRole 等注解
AccessControlFilter
isAccessAllowed 判断是否登录(身份是否有效)
onAccessDenied

shiro拦截器链: http://blog.csdn.net/angel_g/article/details/53993877
权限校验是通过methodInterceptor方式

Eclipse Debug中方法栈,
Filter处理完 ,后面通过MethodInterceptor方式处理@hasRole 等注解检查权限操作

spring mvc中
org.springfreamwork.web.servlet.DispatherServlet 中通过HandleMapping将 controller中 方式上的 requestMapping将 该方法关联起来

HandlerMapping 中 HandlerExecutionChain 中的Handler为 HandlerMethod

每个HandingMapping可以配置 handlerInterceptor
DispatcherServlet中 doService() 中调用doDispatch方法
========================================================================================
shiro-web集成spirng 权限,角色@hasRole 注解校验入口

切面方式

浙公网安备 33010602011771号