使用shiro框架,注销问题的解决

在使用shiro框架的时候,有时候会因为登录问题找不到注销的controller。所以会报404的错误,下面是解决办法:

1.首先写一个类SystemLogoutFilter继承LogoutFilter类,具体代码如下,注意要贴@Service标签:

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

import org.apache.shiro.session.SessionException;
import org.apache.shiro.subject.Subject;
import org.apache.shiro.web.filter.authc.LogoutFilter;
import org.springframework.stereotype.Service;

/**
* @author Abby
*
*/
@Service
public class SystemLogoutFilter extends LogoutFilter {
@Override
protected boolean preHandle(ServletRequest request, ServletResponse response) throws Exception {
//在这里执行退出系统前需要清空的数据

Subject subject = getSubject(request, response);

//String redirectUrl = getRedirectUrl(request, response, subject);
String redirectUrl="/login.jsp";
System.out.println(redirectUrl);

try {

subject.logout();

} catch (SessionException ise) {

ise.printStackTrace();

}

issueRedirect(request, response, redirectUrl);
//返回false表示不执行后续的过滤器,直接返回跳转到登录页面
return false;
}

}

2.需要在shiro配置文件里面添加一些新的配置,具体配置如下:

<property name="filters">
<map>
<entry key="logout" value-ref="systemLogoutFilter" />
</map>
</property>

<property name="filterChainDefinitions">
<value>
/logout=logout
</value>
</property>

原文地址:https://www.cnblogs.com/yinghuanan/p/9441432.html

时间: 2024-08-29 06:05:14

使用shiro框架,注销问题的解决的相关文章

shiro框架总结

一.概念 shiro是一个安全框架,主要可以帮助我们解决程序开发中认证和授权的问题.基于拦截器做的权限系统,权限控制的粒度有限,为了方便各种各样的常用的权限管理需求的实现,,我们有必要使用比较好的安全框架,早期spring  security 作为一个比较完善的安全框架比较火,但是spring security学习成本比较高,于是就出现了shiro安全框架,学习成本降低了很多,而且基本的功能也比较完善. 二.shiro提供的功能 1.Authentication:身份认证/登陆,验证用户是不是拥

Shiro权限验证代码记录,正确找到shiro框架在什么地方做了权限识别

权限验证方式的验证代码: org.apache.shiro.web.servlet.AdviceFilter这个类是所有shiro框架提供的默认权限验证实例类的父类 验证代码: public void doFilterInternal(ServletRequest request, ServletResponse response, FilterChain chain) throws ServletException, IOException { Exception exception = nu

shiro框架的四中权限控制方式

一.在自定义的realm中进行权限控制 在applicationContext.xml文件中添加  /areaAction_pageQuery.action = perms["area"] <bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean"> <!-- 注入shiro框架核心对象,安全管理器 --> <pr

29、shiro框架入门

1.建立测试shiro框架的项目,首先建立的项目结构如下图所示 ini文件 中的内容如下图所示 pom.xml文件中的内容如下所示 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 ht

shiro框架的使用

1.配置二级缓存 <ehcache updateCheck="false" name="shiroCache"> <defaultCache maxElementsInMemory="10000" eternal="false" timeToIdleSeconds="120" timeToLiveSeconds="120" overflowToDisk="fa

037 shiro框架的介绍和使用 - bos

官网:shiro.apache.org 一.shiro介绍 1.shiro框架的核心功能:认证.授权.会话管理.加密 2.shiro框架认证流程: 3.涉及的相关概念和类 ApplicationConde,应用程序代码,由开发人员进行开发 Subject,框架提供的接口,代表当前用户对象 SecurityManager,框架提供的接口,代表安全管理器,是shiro框架最核心的对象 Realm,可以开发人员编写,框架也提供一些,类似于DAO,用于访问权限数据 4.导包方式:只要导入shiro-al

shiro框架的学习

1shiro框架是什么:是一个权限控制的框架2shiro框架有什么作用:权限管理,管理那些资源是否需要登录才能访问.控制某些资源需要那些权限才能访问3shiro框架怎样使用: 1在web.xml配置shiro的Filter,拦截指定的URL(注意只有被shiroFilter拦截到的URL才能被shiro管理) <!-- Shiro filter--> <filter> <filter-name>shiroFilter</filter-name> <fi

shiro框架--权限管理

一.maven坐标 1 <!-- 权限控制 框架 --> 2 <dependency> 3 <groupId>org.apache.shiro</groupId> 4 <artifactId>shiro-all</artifactId> 5 <version>${shiro.version}</version> 6 </dependency> 二.shiro框架的四大功能 1.认证 2.授权 3.加

shiro框架 4种授权方式 说明

1. shiro的配置文件(applicationContext-shiro.xml)中使用filterChain过滤url的方式 详细配置看注释 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSc