shiro 集成spring 配置 学习记录(一)
首先当然是项目中需要增加shiro的架包依赖:
<!-- shiro -->
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-core</artifactId>
<version>${shiro.version}</version>
<exclusions>
<exclusion>
<artifactId>slf4j-api</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-spring</artifactId>
<version>${shiro.version}</version>
</dependency>
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-ehcache</artifactId>
<version>${shiro.version}</version>
<exclusions>
<exclusion>
<artifactId>slf4j-api</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
</exclusions>
</dependency>
1、shiro 总体来说就是过滤器的集合,首先在项目的web.xml里增加shiro的filter配置:如下
<!--Shiro过滤器-->
<filter>
<filter-name>shiroFilter</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
<init-param>
<param-name>targetFilterLifecycle</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>shiroFilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
2、在项目的resource目录下 新增shiro的配置xml文件如:applicationContext-shiro.xml:
1)、增加 securityManager 的初始化;
2)、增加 shiroFilter 的配置, 注意 此配置文件中的bean 过滤器的 id 必须是 web.xml中的 filter-name值
3)、增加自定义的realm实现
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <description>Shiro安全配置</description> <!--此Bean 只是增加登录时的验证码处理,不是shiro必须的配置-->
<bean class="com.itzixi.web.utils.ItzixiCaptcha">
<property name="cacheManager" ref="shiroEhcacheManager"/>
<!-- 复用半小时缓存 -->
<property name="cacheName" value="itzixiCaptcha"/>
</bean> <!-- 安全管理器 -->
<bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
<property name="realm" ref="shiroDbRealm"></property>
</bean> <!-- 用户授权信息Cache, 采用EhCache -->
<bean id="shiroEhcacheManager" class="org.apache.shiro.cache.ehcache.EhCacheManager">
<property name="cacheManagerConfigFile" value="classpath:shiro/ehcache-shiro.xml"/>
</bean> <!-- 项目自定义的Realm -->
<bean id="shiroDbRealm" class="com.itzixi.web.shiro.ShiroDBRealm">
</bean> <!-- Shiro Filter -->
<bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
<!-- 安全管理器 -->
<property name="securityManager" ref="securityManager"/>
<!-- 默认的登陆访问url -->
<property name="loginUrl" value="/login.action"/>
<!-- 登陆成功后跳转的url -->
<property name="successUrl" value="/index.action"/>
<!-- 登录成功以后,没有权限访问的页面,会跳转到该url -->
<property name="unauthorizedUrl" value="/unauth.action"/> <property name="filterChainDefinitions">
<value>
<!--
anon 不需要认证
authc 需要认证
user 验证通过或RememberMe登录的都可以
-->
/** = authc
</value>
</property>
</bean>
</beans>
经过如上的配置 基本完成了shiro初始化集成。
shiro 集成spring 配置 学习记录(一)的更多相关文章
- shiro 权限集成 sessionManager 配置 学习记录(三)
1.shiro配置文件增加sessionManager管理 <!-- 6.shiro结合Session会话管理器 start --> <bean id="sessionMa ...
- shiro 权限集成Ehcache 配置 学习记录(二)
1.加入依赖 <dependency> <groupId>org.apache.shiro</groupId> <artifactId>shiro-eh ...
- Spring Boot学习记录(二)--thymeleaf模板 - CSDN博客
==他的博客应该不错,没有细看 Spring Boot学习记录(二)--thymeleaf模板 - CSDN博客 http://blog.csdn.net/u012706811/article/det ...
- 我的Spring Boot学习记录(二):Tomcat Server以及Spring MVC的上下文问题
Spring Boot版本: 2.0.0.RELEASE 这里需要引入依赖 spring-boot-starter-web 这里有可能有个人的误解,请抱着怀疑态度看. 建议: 感觉自己也会被绕晕,所以 ...
- Spring Boot学习记录(二)–thymeleaf模板
自从来公司后都没用过jsp当界面渲染了,因为前后端分离不是很好,反而模板引擎用的比较多,thymeleaf最大的优势后缀为html,就是只需要浏览器就可以展现页面了,还有就是thymeleaf可以很好 ...
- shiro集成spring&工作流程&DelegatingFilterProxy
1.集成Spring 参考文献: 新建web工程: ehcache-core来自Hibernate wen.xml <?xml version="1.0" encoding= ...
- 【转载】Spring boot学习记录(一)-入门篇
前言:本系列文章非本人原创,转自:http://tengj.top/2017/04/24/springboot0/ 正文 首先声明,Spring Boot不是一门新技术.从本质上来说,Spring B ...
- shiro 集成spring 使用 redis作为缓存 学习记录(六)
1.在applicationContext-redis.xml配置文件中增加如下: 申明一个cacheManager对象 用来注入到 shiro的 securityManager 属性 cac ...
- 我的Spring Boot学习记录(一):自动配置的大致调用过程
1. 背景 Spring Boot通过包管理工具引入starter包就可以轻松使用,省去了配置的繁琐工作,这里简要的通过个人的理解说下Spring Boot启动过程中如何去自动加载配置. 本文中使用的 ...
随机推荐
- centos vi显示中文
1. 控制台终端显示中文 修改 /etc/sysconfig/i18n 文件如下: #LANG="en_US.UTF-8"LANG="zh_CN.GB2312" ...
- phpMyAdmin“缺少 mcrypt 扩展。请检查 PHP 配置。”解决办法
在ecmall二次开发中因php版本要求低于5.3,而如下更新要求升级PHP,所以以下方式不适合于ecmall商城项目. 解决办法:安装php-mcrypt libmcrypt libmcrypt-d ...
- 1.Python3关于文件的操作
1.写了一个简单的Demo,就是向txt文本写入内容,最初代码如下: file = open("D:/Users/nancy/python.txt","wb") ...
- 框架(yii和thinkphp)中实例化php内置或者扩展中的对象问题
将php原生语句实例化SphinxClient对象移植到yii2框架中报错 原生语句中这样写: $s = new SphinxClient(); 框架中应该加入反斜杠,这样写: $s = new \S ...
- Linux:WebServer(Nginx 虚拟主机配置与伪静态实现)
ps + 查看方式 | grep + 服务/端口/软件等:查看状态: 一.基本操作 Nginx 多用于商业系统: 一个端口只能被一个服务使用: Nginx 可以同时监听多个端口,也就是配置时, ...
- Java安全 – JCE Blowfish算法报错
代码里用Blowfish算法加解密,结果jdk升到1.7后算法初始化失败 java.lang.RuntimeException: java.lang.RuntimeException: PANIC: ...
- if、while中变量的作用域问题
我们知道,函数.类会改变当前变量的作用域.if,while等分支循环结构会继承外部作用域,即外部变量对分支循环结构内部可见. 但是C语言不支持if,while等分支循环结构内部作用域对外可见,而PHP ...
- C/C++程序内存情况
一个由C/C++编译的程序占用的内存分为以下几个部分 1.栈区(stack)— 由编译器自动分配释放 ,存放函数的参数值,局部变量的值等.其操作方式类似于数据结构中的栈. 2.堆区(heap) — 一 ...
- TCP/IP协议:最大传输单元MTU 和 最大分节大小MSS
MTU = MSS + TCP Header + IP Header. mtu是网络传输最大报文包. mss是网络传输数据最大值. MTU:maximum transmission unit,最大传输 ...
- 02——微信小程序官方demo讲解——app部分
第一节讲了目录结构,这节主要讲解下目录中app.js部分. 它由三部分组成app.js.app.json与app.wxss 1.JS部分 1.1概述 //app.js App({ onLaunch: ...