shiro 退出系统的两种方式


有两种方式实现logout 
1. 普通的action中 实现自己的logout方法,取到Subject,然后logout 
这种需要在ShiroFilterFactoryBean 中配置 filterChainDefinitions 
对应的action的url为anon 
<property name="filterChainDefinitions"> 
            <value> 
                /user/logout = anon  
                /** = authc 
            </value> 

2. 使用shiro提供的logout filter 
需要定义 相应的bean 
<bean id="logout" class="org.apache.shiro.web.filter.authc.LogoutFilter"> 
        <property name="redirectUrl" value="/login" /> 
    </bean> 

<bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">

  <property name="filters">

<map>

 <entry key="logout" value-ref="logout" />

</map>

</property>

</bean>

然后将相应的url filter配置为logout如下 
<property name="filterChainDefinitions"> 
            <value> 
                /logout = logout 
                /** = authc 
            </value>

猜你喜欢

转载自feiteyizu.iteye.com/blog/2243269
今日推荐