使用shiro进行登录和退出

一.配置web.xml

     使用shiro进行登录和退出         这个在web.xml配置的过滤器只是启动拦截请求的作用,真正处理请求是在spring配置的targetBeanName的值对应bean的id类

二.创建ApplicationContext-shiro.xml

     如下:

    1.shiro核心过滤器

     <bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
          <property name="securityManager" ref="securityManager" />
           <!-- loginUrl认证提交地址,如果没有认证将会请求此地址进行认证,请求此                    地址将由formAuthenticationFilter进行表单认证 -->
           <property name="loginUrl" value="/login.action" />
           <property name="unauthorizedUrl" value="/refuse.jsp" />
           <!-- 过滤器链定义,从上向下顺序执行,一般将/**放在最下边 -->
           <property name="filterChainDefinitions">
           <value>
            <!-- 退出拦截,请求logout.action执行退出操作 -->
            /logout.action = logout
            /js/** =anon
           /images/** =anon
           /styles/** =anon
           /** = authc
          </value>
       </property>
   </bean>

        2.shiro的安全控制器

        <bean id="securityManager"       class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
        <property name="realm" ref="userRealm" />
        </bean>

        3.自定义的realm

        <bean id="userRealm" class="cn.itcast.ssm.realm.CustomRealm">

                自定义CustomRealm就是普通的认证没有加入md5进行加密

        </bean>

三.springMVC的控制器

     使用shiro进行登录和退出

    shiro登录失败它会把错误信息全类名放在request作用域中,我们不需要对于登录成  功的页面设定,因为shiro默认是跳到上一次的地址

注意:form表单提交的nameshiro提交默认值,也可以在shiro自己设定

           使用shiro进行登录和退出

四.shiro中的一系列过滤器

    使用shiro进行登录和退出