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

shiro-filter执行流程

 

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

 

shiro-filter执行流程

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 去执行的,实际上就是执行一个过滤器链

shiro-filter执行流程

 

 

 

auth

shiro-filter执行流程

 

shiro-filter执行流程

 

 表单登录

shiro-filter执行流程

 

 真正调用Realm auth的地方

shiro-filter执行流程

 

 

shiro-filter执行流程

 

 retryCount判断

shiro-filter执行流程

 

 

密码匹配
shiro-filter执行流程

 

登录成功------

shiro-filter执行流程

 

AdviceFilter 切面过滤hasRole 等注解

 

AccessControlFilter

isAccessAllowed  判断是否登录(身份是否有效)

onAccessDenied

shiro-filter执行流程

 

 

 

 

shiro拦截器链: http://blog.csdn.net/angel_g/article/details/53993877

 

 

 

权限校验是通过methodInterceptor方式

 

shiro-filter执行流程

 

 Eclipse Debug中方法栈,

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

shiro-filter执行流程

 

 

spring mvc中 

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

shiro-filter执行流程

 

 HandlerMapping 中 HandlerExecutionChain   中的Handler为 HandlerMethod

 

 

 

shiro-filter执行流程

每个HandingMapping可以配置  handlerInterceptor

 

DispatcherServlet中 doService() 中调用doDispatch方法

 

 

 

========================================================================================

shiro-web集成spirng   权限,角色@hasRole  注解校验入口

 

shiro-filter执行流程

 

切面方式

 

相关文章:

  • 2021-11-04
  • 2022-01-03
  • 2022-12-23
  • 2021-11-20
  • 2022-01-07
  • 2021-09-04
  • 2021-04-30
  • 2021-05-01
猜你喜欢
  • 2022-12-23
  • 2021-09-19
  • 2021-06-28
  • 2021-09-27
  • 2021-09-25
  • 2022-12-23
  • 2021-05-30
相关资源
相似解决方案