• shiro自定义logout filter


    虽然shiro有自己默认的logout过滤器,但是,有些时候,我们需要自己定义一下操作,比如说loutgout后,进入指定页面,或者logout后写入日志操作,这个时候,我们可以通过自定义logout filter来实现:

    1,自定义一个systemLogout继承字logout filter,并重写preHandle方法

    /**
     * @author:lyy
     * @Date: 2014/10/14 9:33
     * @version:
     * @Description:
     */
    @Service
    public class SystemLogout extends LogoutFilter{
        @Autowired
        LogManDataInf logManDataInfImpl;
        @Override
       @Override
        protected boolean preHandle(ServletRequest request, ServletResponse response) throws Exception {
            //在这里执行退出系统前需要清空的数据
         Subject subject = getSubject(request, response);
            String redirectUrl = getRedirectUrl(request, response, subject);
            try {
                subject.logout();
            } catch (SessionException ise) {
               ise.printStackTrace();
            }
    //跳转到登录页面
            issueRedirect(request, response, redirectUrl);
         //返回false表示不执行后续的过滤器,直接返回跳转到登录页面
            return false;
        }
    }

    2,在配置自定义的filter进入filter chain中

    <!-- Shiro 的Web过滤器 -->
    <bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
        <property name="securityManager" ref="securityManager" />
        <property name="loginUrl" value="/login" />
        <property name="filters">
            <map>
                <entry key="logout" value-ref="systemLogout" />
            </map>
        </property>
        <!-- 过虑器链定义,从上向下顺序执行,一般将/**放在最下边 -->
        <property name="filterChainDefinitions">
            <value>
                <!-- 对静态资源设置匿名访问 -->
                /resources/** = anon
                /taglib/** = anon
                <!-- 请求 logout地址,shiro去清除session-->
                /logout = logout
                /login = anon
                <!--/** = anon-->
                /** = authc
            </value>
        </property>
    </bean>
  • 相关阅读:
    19.08.12 知识点的记录
    19.08.09 知识点的记录
    keil编译生成bin文件的方法
    python 虚拟环境virtualenv
    RT_Thread GD32F303 片上flash使用fal组件
    esp8266 deepsleep唤醒不工作打印
    5V 电源 适配器 空载耗电量 自身电量 消耗功率
    keil 更换jlink脚本版本
    ESP8266 NONOS SmartConfig配网(安信可公众号配网)
    windows安装esp开发环境
  • 原文地址:https://www.cnblogs.com/ningheshutong/p/8134008.html
Copyright © 2020-2023  润新知