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 注解校驗入口

切面方式
