虽然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. java读取配置文件常用的四种方式

    配置文件 放置在src下面 obj.properties className=com.store.order.dao.impl.OrderDaoImpl 方式一 @Test public void t ...

  2. springMVC初探视图解析器——ResourceBundleViewResolver

    视图解析器ResourceBundleViewResolver是根据proterties文件来找对应的视图来解析”逻辑视图“的, 该properties文件默认是放在classpath路径下的view ...

  3. 愤怒的TryCatch

    本文地址:http://www.cnblogs.com/likeli/p/5719230.html 前言 本文不提供任何搭梯子之类的内容,我在这里仅仅讨论网络爬虫遇到的IP封杀,然后使用Tor如何对抗 ...

  4. Nginx为什么比Apache Httpd高效

    转载于:http://www.toxingwang.com/linux-unix/linux-basic/1712.html 一.进程.线程? 在回答nginx 为什么比apache更高效之前,必须要 ...

  5. Exception thrown in catch and finally clause

    Based on reading your answer and seeing how you likely came up with it, I believe you think an " ...

  6. Linux学习之一-从三个重要人物的故事和一张思维导图说起

    Linux是一套自由加开放源代码的类Unix操作系统,诞生于1991年10月5日(第一次正式向外公布),由芬兰学生Linus Torvalds和后来陆续加入的众多爱好者共同开发完成. Linux是一个 ...

  7. eCos系统无法正确链接到在C++源文件里自己定义的cyg_user_start函数的问题和解决的方法

    在C++源文件里定义cyg_user_start函数前,将其声明成C函数.就可以解决这个问题. eCos官网:http://ecos.sourceware.org eCos中文技术网:http://w ...

  8. ubuntu apt-get install xxx时一直报错E: Unable to locate package xxxxxxx

    $ sudo add-apt-repository main $ sudo add-apt-repository universe $ sudo add-apt-repository restrict ...

  9. 批量扫描IP端口程序 (适用于window&linux)

    批量扫描IP端口,根据扫描IP导出IP命名的文件的结果.假设1.txt文件内容为127.0.0.1192.168.1.1然后我们获取文件内容IP进行扫描window .bat版本 :1.txt为文件名 ...

  10. python sqlite3 MySQLdb

    SQLite是一种嵌入式数据库,它的数据库就是一个文件.由于SQLite本身是C写的,而且体积很小,所以,经常被集成到各种应用程序中,甚至在iOS和Android的App中都可以集成. Python就 ...