虽然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>

shiro自定义logout filter的更多相关文章

  1. shiro 自定义filter

    1.自定义登录filter package com.creatunion.callcenter.filter; import com.alibaba.fastjson.JSONObject; impo ...

  2. Spring Security笔记:自定义Login/Logout Filter、AuthenticationProvider、AuthenticationToken

    在前面的学习中,配置文件中的<http>...</http>都是采用的auto-config="true"这种自动配置模式,根据Spring Securit ...

  3. 解决shiro自定义filter后,ajax登录无法登录,并且无法显示静态资源的问题

    这个问题困扰了我一天,看了下面两个文章,豁然开朗: https://www.cnblogs.com/gj1990/p/8057348.html https://412887952-qq-com.ite ...

  4. shiro自定义拦截url

    在实际项目上,我们针对不同的用户(guste,user,admin,mobile user)等等,需要进入不同的页面,比如,手机端用户需要进入Mobile/这个路径下的,这个时候,我们需要自定义拦截u ...

  5. Shiro 自定义登陆、授权、拦截器

    Shiro 登陆.授权.拦截 按钮权限控制 一.目标 Maven+Spring+shiro 自定义登陆.授权 自定义拦截器 加载数据库资源构建拦截链 使用总结: 1.需要设计的数据库:用户.角色.权限 ...

  6. 一个自定义 HBase Filter -“通过RowKeys来高性能获取数据”

    摘要: 大家在使用HBase和Solr搭建系统中经常遇到的一个问题就是:“我通过SOLR得到了RowKeys后,该怎样去HBase上取数据”.使用现有的Filter性能差劲,网上也没有现成的自定义Fi ...

  7. MVC之 自定义过滤器(Filter)

    MVC之 自定义过滤器(Filter) 一.自定义Filter 自定义Filter需要继承ActionFilterAttribute抽象类,重写其中需要的方法,来看下ActionFilterAttri ...

  8. spring-cloud-Zuul学习(四)【中级】--自定义zuul Filter详解【重新定义spring cloud实践】

      实现自定义zuul Filter 方法很简单,只要继承ZuulFilter跟加入到spring IOC容器即可,zuulFilter是一个抽象类,里面包含以下方法需要我们实现: String fi ...

  9. Struct2中自定义的Filter无效

    解决办法,把自定义的Filter配置放在struct2前 <?xml version="1.0" encoding="UTF-8"?> <we ...

随机推荐

  1. 解决虚拟机安装tomcat主机访问不到

    在wmware中安装linux后安装好数据库,JDK及tomcat后启动服务,虚拟机中可以访问,但是主机却无法访问,但是同时主机和虚拟机之间可以ping的通.解决方法是关闭虚拟机中的防火墙服务.桌面- ...

  2. linux coreseek-4.1安装

    1.假设已经有coreseek-4.1-beta.tar.gz源文件 [root@qp232 ~]# cd /usr/local [root@qp232 local]# tar -zxvf /yd/l ...

  3. mysql truncate drop delete的区别

    以下讨论,针对于mysql数据库. 为什么会想到这个问题呢? 因为项目中需要清除数据库的数据,而且需要实现自增的主键从0开始计数.所以想到总结一个几个常用的删除语法的差异. 可以做一个测试 建一个带有 ...

  4. 设计模式之迭代器模式(PHP实现)

    github地址:https://github.com/ZQCard/design_pattern/** * 迭代器模式(Iterator Pattern)是 Java 和 .Net 编程环境中非常常 ...

  5. JSON-JSON 百科

    1,百度百科 http://baike.baidu.com/view/136475.htm?fr=aladdin 2,JSON教程 http://www.w3school.com.cn/json/

  6. Android Tabhost置于底部

    方法一: <TabHost xmlns:android="http://schemas.android.com/apk/res/android" android:id=&qu ...

  7. Shell 同时读取多个文件

    现有两个文件 1.txt  2.txt,内容分别如下: [root@SHO-XXW-- readmulti]# .txt [root@SHO-XXW-- readmulti]# .txt a b c ...

  8. 使用LBS(地理位置)

    一.使用之前的简单封装的OkHttpUtil http://www.cnblogs.com/itfenqing/p/6758909.html 二.关键代码: public class MainActi ...

  9. 动态添加Fragment

    在Fragment简单用法的基础上做修改 一.新建:another_right_fragment.xml <LinearLayout xmlns:android="http://sch ...

  10. spring 国际化-i18n

    i18n(其 来源是英文单词 internationalization的首末字符i和n,18为中间的字符数)是“国际化”的简称.在资讯领域,国际化(i18n)指让产品(出版 物,软件,硬件等)无需做大 ...