- 浏览: 3363454 次
- 性别:
- 来自: 珠海
文章分类
- 全部博客 (1633)
- Java (250)
- Android&HTML5 (111)
- Struts (10)
- Spring (236)
- Hibernate&MyBatis (115)
- SSH (49)
- jQuery插件收集 (55)
- Javascript (145)
- PHP (77)
- REST&WebService (18)
- BIRT (27)
- .NET (7)
- Database (105)
- 设计模式 (16)
- 自动化和测试 (19)
- Maven&Ant (43)
- 工作流 (36)
- 开源应用 (156)
- 其他 (16)
- 前台&美工 (119)
- 工作积累 (0)
- OS&Docker (83)
- Python&爬虫 (28)
- 工具软件 (157)
- 问题收集 (61)
- OFbiz (6)
- noSQL (12)
最新评论
-
HEZR曾嶸:
你好博主,这个不是很理解,能解释一下嘛//左边+1,上边+1, ...
java 两字符串相似度计算算法 -
天使建站:
写得不错,可以看这里,和这里的这篇文章一起看,有 ...
jquery 遍历对象、数组、集合 -
xue88ming:
很有用,谢谢
@PathVariable映射出现错误: Name for argument type -
jnjeC:
厉害,困扰了我很久
MyBatis排序时使用order by 动态参数时需要注意,用$而不是# -
TopLongMan:
非常好,很实用啊。。
PostgreSQL递归查询实现树状结构查询
apache shiro集群实现(一) session共享 http://blog.csdn.net/michaelliuyang/article/details/8819852
apache shiro集群实现(二)— cache共享 http://blog.csdn.net/michaelliuyang/article/details/8820390
Redis整合Spring结合使用缓存实例 http://blog.csdn.net/evankaka/article/details/50396325
原文的修改: 很多人留言希望提供基础代码, 但原文的作者不愿意提供基础代码, 让人很纳闷, 所以自己找了很久, 决定替换和修改原文的代码
针对redis的session共享的配置或者源码
针对redis的cache的配置或源码
RedisUtil.java参考: http://panyongzheng.iteye.com/blog/2295435
apache shiro集群实现(二)— cache共享 http://blog.csdn.net/michaelliuyang/article/details/8820390
Redis整合Spring结合使用缓存实例 http://blog.csdn.net/evankaka/article/details/50396325
原文的修改: 很多人留言希望提供基础代码, 但原文的作者不愿意提供基础代码, 让人很纳闷, 所以自己找了很久, 决定替换和修改原文的代码
针对redis的session共享的配置或者源码
<bean id="jdkSerializationRedisSerializer" class="org.springframework.data.redis.serializer.JdkSerializationRedisSerializer"/> <bean id="stringRedisSerializer" class="org.springframework.data.redis.serializer.StringRedisSerializer"/> <bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig"></bean> <bean id="jedisConnectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"> <property name="hostName" value="192.168.0.198"/> <property name="port" value="6379"/> <property name="password" value="12345"/> <property name="timeout" value="1000"/> <property name="poolConfig" ref="jedisPoolConfig"/> <property name="usePool" value="true"/> </bean> <!-- GenericToStringSerializer: 可以将任何对象泛化为字符串并序列化 Jackson2JsonRedisSerializer: 跟JacksonJsonRedisSerializer实际上是一样的 JacksonJsonRedisSerializer: 序列化object对象为json字符串 JdkSerializationRedisSerializer: 序列化java对象 StringRedisSerializer: 简单的字符串序列化 --> <bean id="redisTemplate" class="org.springframework.data.redis.core.StringRedisTemplate"> <property name="connectionFactory" ref="jedisConnectionFactory"/> <property name="defaultSerializer" ref="jdkSerializationRedisSerializer" /> <property name="keySerializer" ref="stringRedisSerializer"/> <property name="hashKeySerializer" ref="stringRedisSerializer"/> <property name="valueSerializer" ref="jdkSerializationRedisSerializer"/> <property name="hashValueSerializer" ref="jdkSerializationRedisSerializer"/> </bean> <bean id="redisUtil" class="com.pandy.framework.base.redis.utils.RedisUtil"> <property name="redisTemplate" ref="redisTemplate"/> </bean>
package com.pandy.framework.base.shiro.session.dao.impl; import com.pandy.framework.base.redis.utils.RedisUtil; import com.pandy.framework.base.shiro.session.dao.ShiroSessionRepository; import org.apache.shiro.session.Session; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.Serializable; import java.util.Collection; import java.util.HashSet; import java.util.Iterator; import java.util.Set; /** * Created by pandy on 16-5-3. */ public class JedisShiroSessionRepository implements ShiroSessionRepository { private Logger logger = LoggerFactory.getLogger(JedisShiroSessionRepository.class); private RedisUtil redisUtil; /** * redis session key前缀 */ private final String REDIS_SHIRO_SESSION = "PANDY-WP-FRAMEWORK-SESSION"; private String redisShiroSessionPre; public void saveSession(Session session) { if (session == null || session.getId() == null) { logger.error("session或者session id为空"); return; } redisUtil.set(getRedisSessionKey(session.getId()), session); } public void deleteSession(Serializable id) { if (id == null) { logger.error("id为空"); return; } redisUtil.remove(getRedisSessionKey(id)); } public Session getSession(Serializable id) { if (id == null) { logger.error("id为空"); return null; } Session session = redisUtil.get(getRedisSessionKey(id), Session.class); return session; } public Collection<Session> getAllSessions() { Set<Session> sessions = new HashSet<Session>(); Set<String> set = redisUtil.getPatternKey("*"); if (set == null || set.size() == 0) return sessions; Iterator<String> it = set.iterator(); while (it.hasNext()) { try { String key = it.next(); if(key!=null && key.indexOf(REDIS_SHIRO_SESSION)>=0){ Session session = redisUtil.get(key, Session.class); sessions.add(session); } }catch (Exception e){ e.printStackTrace(); } } return sessions; } /** * 获取redis中的session key * * @param sessionId * @return */ private String getRedisSessionKey(Serializable sessionId) { return getRedisShiroSessionPre() + sessionId; } public RedisUtil getRedisUtil() { return redisUtil; } public void setRedisUtil(RedisUtil redisUtil) { this.redisUtil = redisUtil; } public String getRedisShiroSessionPre() { if (redisShiroSessionPre == null || redisShiroSessionPre.trim().length() == 0) { return REDIS_SHIRO_SESSION + ":"; } return REDIS_SHIRO_SESSION + "-" + redisShiroSessionPre + ":"; } public void setRedisShiroSessionPre(String redisShiroSessionPre) { this.redisShiroSessionPre = redisShiroSessionPre; } }
<!-- 使用redis处理会话DAO --> <bean id="jedisShiroSessionRepository" class="com.pandy.framework.base.shiro.session.dao.impl.JedisShiroSessionRepository"> <property name="redisUtil" ref="redisUtil"/> <property name="redisShiroSessionPre" value="PANDY_WEB_APP_SESSION"/> </bean> <bean id="sessionDAO" class="com.pandy.framework.base.shiro.session.dao.impl.CustomShiroSessionDAO"> <property name="shiroSessionRepository" ref="jedisShiroSessionRepository" /> <property name="sessionIdGenerator" ref="sessionIdGenerator"/> </bean>
针对redis的cache的配置或源码
package com.pandy.framework.base.shiro.cache; import com.pandy.framework.base.redis.utils.RedisUtil; import org.apache.shiro.cache.Cache; /** * Created by pandy on 16-5-4. */ public class JedisShiroCacheManager implements ShiroCacheManager { private RedisUtil redisUtil; private String redisShiroCachePre; public <K, V> Cache<K, V> getCache(String name) { return new JedisShiroCache<K, V>(name, redisUtil, getRedisShiroCachePre()); } public void destroy() { //jedisCacheManager.getJedis().shutdown(); throw new RuntimeException("这里要怎么实现啊,还不知道怎么实现"); } public RedisUtil getRedisUtil() { return redisUtil; } public void setRedisUtil(RedisUtil redisUtil) { this.redisUtil = redisUtil; } public String getRedisShiroCachePre() { return redisShiroCachePre; } public void setRedisShiroCachePre(String redisShiroCachePre) { this.redisShiroCachePre = redisShiroCachePre; } }
package com.pandy.framework.base.shiro.cache; import org.apache.shiro.cache.Cache; import org.apache.shiro.cache.CacheException; import org.apache.shiro.cache.CacheManager; import org.apache.shiro.util.Destroyable; /** * Created by pandy on 16-5-4. */ public class CustomShiroCacheManager implements CacheManager, Destroyable { private ShiroCacheManager shiroCacheManager; public ShiroCacheManager getShiroCacheManager() { return shiroCacheManager; } public void setShiroCacheManager(ShiroCacheManager shiroCacheManager) { this.shiroCacheManager = shiroCacheManager; } public <K, V> Cache<K, V> getCache(String name) throws CacheException { return getShiroCacheManager().getCache(name); } public void destroy() throws Exception { shiroCacheManager.destroy(); } }
package com.pandy.framework.base.shiro.cache; import com.pandy.framework.base.redis.utils.RedisUtil; import com.pandy.framework.base.utils.SerializeUtil; import org.apache.shiro.cache.Cache; import org.apache.shiro.cache.CacheException; import java.util.*; /** * Created by pandy on 16-5-4. */ public class JedisShiroCache<K, V> implements Cache<K, V> { private RedisUtil redisUtil; private final String REDIS_SHIRO_CACHE = "PANDY-WP-FRAMEWORK-CACHE"; private String redisShiroCachePre; private String name; public JedisShiroCache(String name, RedisUtil redisUtil, String redisShiroCachePre) { this.name = name; this.redisUtil = redisUtil; this.redisShiroCachePre = redisShiroCachePre; } /** * 自定义relm中的授权/认证的类名加上授权/认证英文名字 * * @return */ public String getName() { if (name == null) return ""; return name; } public void setName(String name) { this.name = name; } public V get(K key) throws CacheException { byte[] byteKey = SerializeUtil.serialize(getCacheKey(key)); //byte[] byteValue = redisUtil.get(getCacheKey(key)); Object byteValue = redisUtil.get(getCacheKey(key)); return (V) byteValue; } public V put(K key, V value) throws CacheException { V previos = get(key); redisUtil.set(getCacheKey(key), value); return previos; } public V remove(K key) throws CacheException { V previos = get(key); redisUtil.remove(getCacheKey(key)); return previos; } public void clear() throws CacheException { byte[] keysPattern = SerializeUtil.serialize(this.REDIS_SHIRO_CACHE + "*"); redisUtil.removePattern(getCacheKey(keysPattern)); } public int size() { if (keys() == null) return 0; return keys().size(); } public Set<K> keys() { Set<K> set = (Set<K>) redisUtil.getPatternKey("*"); return set; } public Collection<V> values() { List<V> result = new LinkedList<V>(); return result; } private String getCacheKey(Object key) { if (redisShiroCachePre == null || redisShiroCachePre.trim().length() == 0) return this.REDIS_SHIRO_CACHE + getName() + ":" + key; else return this.REDIS_SHIRO_CACHE + "-" + redisShiroCachePre + getName() + ":" + key; } }
<!-- 使用redis缓存管理器 --> <bean id="jedisShiroCacheManager" class="com.pandy.framework.base.shiro.cache.JedisShiroCacheManager"> <property name="redisUtil" ref="redisUtil" /> <property name="redisShiroCachePre" value="PANDY_WEB_APP_CACHE"/> </bean> <bean id="cacheManagerWrapper" class="com.pandy.framework.base.shiro.cache.CustomShiroCacheManager"> <property name="shiroCacheManager" ref="jedisShiroCacheManager" /> </bean>
RedisUtil.java参考: http://panyongzheng.iteye.com/blog/2295435
发表评论
-
分布式存储系统GlusterFS安装配置
2016-06-27 14:51 993http://navyaijm.blog.51cto.com/ ... -
分布式查询 presto 入门安装使用
2016-06-24 15:44 2467http://my.oschina.net/chengxiao ... -
跟我学习dubbo
2016-06-17 15:20 1032跟我学习dubbo-目录 http://bluereader. ... -
JavaMelody监控web服务器
2016-06-17 14:20 1145JavaMelody监控web服务器 http://my.os ... -
freemarker使用记录
2016-06-08 16:24 1279freeMarker语法 http://uule.iteye. ... -
freemarker判断是否为空
2016-06-08 16:03 2http://www.oschina.net/code/sni ... -
ehcache 分布式支持
2016-06-05 22:26 1057原文 http://my.oschina.net/glenxu ... -
Intellij IDEA插件开发入门
2016-05-26 11:42 2841原文: http://blog.csdn.net/dc_726 ... -
阿里巴巴Druid数据源的配置与使用
2016-05-24 17:42 1495http://my.oschina.net/wjme/blog ... -
分布式任务调度组件 Uncode-Schedule
2016-05-13 14:47 2240http://www.oschina.net/p/uncode ... -
mysql中间件研究(Atlas,cobar,TDDL), 分库分表插件
2016-05-09 14:15 3390http://www.guokr.com/blog/47576 ... -
Fedora安装Redis
2016-05-04 08:56 1378管理工具: centos6.3下安装phpredisadmin ... -
redis-install.sh
2016-05-04 08:56 4#!/bin/bash # From here: http: ... -
redis 集群中Session解决方案之Spring Session
2016-05-04 08:54 1272集群中Session解决方案之Spring Session h ... -
使用Spring-data进行Redis操作
2016-05-04 08:54 4732使用Spring-data进行Redis操作 http://z ... -
spring 注解方式下使用commons-validator 验证表单
2016-05-03 11:08 3036原文: http://www.programgo.com/ar ... -
Apache Lucene 5.x版本 示例
2016-04-28 15:46 1098http://blog.csdn.net/isea533/ar ... -
Hessian 二进制RPC协议整合到SpringMVC
2016-04-27 09:47 1704SpringMVC集成Hessianhttp://blog.c ... -
shiro过滤器过滤属性含义
2016-04-21 13:51 1274http://my.oschina.net/cng1985/b ... -
Hadoop 2.6.4分布式集群环境搭建
2016-04-13 11:45 711http://my.oschina.net/jackieyea ...
相关推荐
springboot +shiro+redis实现session共享(方案二)1
Shiro结合Redis
springboot 整合shiro的认证,redis实现session共享案例
基于ssm+shiro+redis+nginx tomcat服务器集群管理项目.zip基于ssm+shiro+redis+nginx tomcat服务器集群管理项目.zip基于ssm+shiro+redis+nginx tomcat服务器集群管理项目.zip基于ssm+shiro+redis+nginx tomcat服务器...
本篇文章主要介绍了spring boot整合redis实现shiro的分布式session共享的方法,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
前后端分离,前端系统只有html、js 权限管理为shiro,缓存为redis集群 策略:sessionid不随机生成,使用url+用户名作为sessionId
redis:Nosql数据库,搭配shiro的会话管理功能将session存入redis中,实现tomcat多服务器集群的session共享 nginx:反向代理服务器,用来调度多台tomcat h2:内存数据库,用于测试 开发环境 ==== jdk...
Nginx+Tomcat+Redis实现session共享,通过Nginx作为前端的负载,把请求分发到后端的Tomcat服务器上,提高并发数;但是单纯的通过Nginx的ip_hash负载是很多问题的。只要用户一切换网络或者后端Tomcat主机宕机session就...
SpringBoot整合Shiro、JWT和Redis实现token登录授权验证以及token刷新 前端代码为一个博客页面,使用了Semantic UI框架结合thymeleaf模板 SpringBoot结合JWT+Shiro+Redis实现token无状态登录授权 [TOC] 一、引言 ...
为实现Web应用的分布式集群部署,要解决登录session的统一。本文利用shiro做权限控制,redis做session存储,结合spring boot快速配置实现session共享。
使用redis作为shiro实现集群会话管理
10、后台权限采用流行的shiro权限管理框架,通过本项目可以深入了解shiro权限框架的应用及原理。 11、项目部署采用tomcat+Nginx的集群部署方式,在部署过程中可以深刻体会到nginx在负载均衡中发挥的优势。
NULL 博文链接:https://yuhuiblog695685688425687986842568269.iteye.com/blog/2400472
后台管理模块用于银行工作人员对本系统业务处理过程的管理与监控,前端采用 SpringBoot默认支持的Thymeleaf模板引擎渲染页面,后端通过Shiro进行身份权限 的认证,采取Restfill风格实现定时任务、日志的管理以及...
NumberOne SpringBoot 是一个 Java EE 企业级快速开发平台,基于经典技术组合(Spring Boot、Apache Shiro、MyBatis、Thymeleaf、Bootstrap、Hplus),内置模块如:部门管理、角色用户、菜单及按钮授权、数据权限、...
主要介绍了spring cloud gateway整合sentinel实现网关限流,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
1、项目整合redis存储,shiro可使用redisSession可使用于集群访问 2、项目增加jwt模式 3、增加默认启动模式为开发模式 4、优化已知BUG SpringBootAdmin 微服务快速开发脚手架 平台简介 SpringBootAdmin是基于多个...
该项目包含helloworld(快速入门)、web(ssh项目快速搭建)、aop(切面编程)、data-redis(redis缓存)、quartz(集群任务实现)、shiro(权限管理)、oauth2(四种认证模式)、shign(接口参数防篡改重放)、encoder(用户...
42、shiro框架具体怎么使用? 46、hashMap的底层、子类与基类的继承关系?hashmap的扩容机制? 48、JVM工作原理?Jvm优化? 57、SpringCloud原理?Lambda?数据库数据大小? 59、excel表头打印从a到zzz怎么做? ...
该物联网云平台使用Java语言、经典技术组合(MQTT、Spring Boot、Shiro、MyBatis、Druid、Thymeleaf、Bootstrap、Swagger)开发,支持集群,支持多数据源,支持分布式事务。 1、全套源码、设备模块,包含单片机源码...