原文戳我
前段时间项目要用到权限控制的相关模块,经过讨论决定采用Apache下面的Shiro开源框架进行身份校验与权限控制,因项目需部署在集群环境下,所以需要分布式的支持,故配置了Redis作为权限数据的存储,这里简单的记录下相关的配置
applicationContext-shiro.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | <? xml version = "1.0" encoding = "UTF-8" ?> < beans xmlns = "http://www.springframework.org/schema/beans" xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance" xmlns:p = "http://www.springframework.org/schema/p" xmlns:c = "http://www.springframework.org/schema/c"
xmlns:util = "http://www.springframework.org/schema/util" xmlns:aop = "http://www.springframework.org/schema/aop"
xmlns:tx = "http://www.springframework.org/schema/tx" xmlns:context = "http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/utilhttp://www.springframework.org/schema/util/spring-util-3.1.xsd
http://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx-3.1.xsd
http://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop-3.1.xsd">
< bean id = "lifecycleBeanPostProcessor" class = "org.apache.shiro.spring.LifecycleBeanPostProcessor" />
< bean id = "securityManager" class = "org.apache.shiro.web.mgt.DefaultWebSecurityManager" >
< property name = "authenticator" ref = "authenticator" />
< property name = "sessionManager" ref = "sessionManager" />
<!--<propertyname="sessionMode"value="http"/>-->
< property name = "cacheManager" ref = "redisCacheManager" />
< property name = "realms" >
< list >
< ref local = "customRealm" />
</ list >
</ property >
</ bean >
< bean class = "com.bbk.security.realm.CustomRealm" id = "customRealm" >
< property name = "credentialsMatcher" ref = "hashedCredentialsMatcher" />
</ bean >
< bean id = "redisCacheManager" class = "com.bbk.security.cache.RedisCacheManager" > <!--自定义cacheManager-->
< property name = "redisManager" ref = "redisManager" />
</ bean >
< bean id = "redisCache" class = "com.bbk.security.cache.RedisCache" > <!--自定义cacheManager-->
< constructor-arg ref = "redisManager" ></ constructor-arg >
</ bean >
< bean id = "roleOR" class = "com.bbk.filter.CustomAuthorizationFilter" />
< bean id = "shiroFilter" class = "org.apache.shiro.spring.web.ShiroFilterFactoryBean" >
<!--调用我们配置的权限管理器-->
< property name = "securityManager" ref = "securityManager" />
</ bean >
< bean id = "authenticator" class = "org.apache.shiro.authc.pam.ModularRealmAuthenticator" />
< bean id = "sessionManager" class = "org.apache.shiro.web.session.mgt.DefaultWebSessionManager" >
< property name = "sessionDAO" ref = "redisShiroSessionDAO" />
< property name = "globalSessionTimeout" value = "${shiro.session.timeout}" /> <!--会话过期时间,在配置文件里面配置-->
< property name = "sessionValidationInterval" value = "3000000" />
< property name = "sessionValidationSchedulerEnabled" value = "true" />
</ bean >
< bean id = "redisShiroSessionDAO" class = "com.bbk.security.cache.RedisSessionDAO" >
< property name = "redisManager" ref = "redisManager" />
</ bean >
< bean id = "redisManager" class = "com.bbk.security.cache.RedisManager" ></ bean >
< bean id = "hashedCredentialsMatcher" class = "org.apache.shiro.authc.credential.HashedCredentialsMatcher" > <!--密钥的算法-->
< property name = "hashAlgorithmName" value = "MD5" />
< property name = "storedCredentialsHexEncoded" value = "true" />
< property name = "hashIterations" value = "1" />
</ bean >
<!--copyto‘spring-mvc.xml‘-->
<!--<beandepends-on="lifecycleBeanPostProcessor"/>
<bean>
<propertyname="securityManager"ref="securityManager"/></bean>--> </ beans > |
RedisCache
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 知识推荐
我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8
不良信息举报平台
互联网安全管理备案
Copyright 2023 www.wodecom.cn All Rights Reserved |