java - 一个项目两个web模块会导致shiro的session污染,求助

查看:133
本文介绍了java - 一个项目两个web模块会导致shiro的session污染,求助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

您好,环境是这样的
模块admin
http://localhost:8081/admin/login 得到sessionid是

22:05:38 DEBUG net.sf.ehcache.Cache - Cache: admin-SessionCache store hit for 1a22b751-0542-4e74-a8e7-59942692f6ae

模块user
http://localhost:8082/user/login 得到sessionid是

22:07:01 DEBUG net.sf.ehcache.Cache - Cache: user-SessionCache store hit for 38c7d0d9-b13c-42f5-9e36-304838838c02

当admin登陆成功后,去刷新user(并不登陆,就在登陆页面刷新)
这个时候admin就会自动退出登陆,且提示

22:13:37 DEBUG o.a.shiro.web.servlet.SimpleCookie - Found 'sid' cookie value [38c7d0d9-b13c-42f5-9e36-304838838c02]
22:13:37 DEBUG net.sf.ehcache.Cache - mx-master-SessionCache cache - Miss
22:13:37 DEBUG o.a.shiro.mgt.DefaultSecurityManager - Resolved SubjectContext context session is invalid.  Ignoring and creating an anonymous (session-less) Subject instance.
org.apache.shiro.session.UnknownSessionException: There is no session with id [38c7d0d9-b13c-42f5-9e36-304838838c02]

user也会报错,提示

22:13:37 DEBUG o.a.shiro.web.servlet.SimpleCookie - Found 'sid' cookie value [1a22b751-0542-4e74-a8e7-59942692f6ae]
22:13:37 DEBUG net.sf.ehcache.Cache - mx-master-SessionCache cache - Miss
22:13:37 DEBUG o.a.shiro.mgt.DefaultSecurityManager - Resolved SubjectContext context session is invalid.  Ignoring and creating an anonymous (session-less) Subject instance.
org.apache.shiro.session.UnknownSessionException: There is no session with id [1a22b751-0542-4e74-a8e7-59942692f6ae]

两个id是串联起来了一样,求解决办法,但是如果这2个模块,在不同浏览器下,就不会出现这个问题,难道是session的name一样导致的吗?
admin覆盖user,或者user覆盖admin

解决方案

解决办法:

    <!-- 会话Cookie模板 -->
    <bean id="sessionIdCookie" class="org.apache.shiro.web.servlet.SimpleCookie">
        <constructor-arg value="sid"/>
        **<!--设置Cookie名字,默认为JSESSIONID-->
        <property name="name" value="WEBSID" />**
    </bean>

2个web模块,分别设置不同的sessionIdCookie的name即可

感谢3楼的哥们(geshiwuyu)

这篇关于java - 一个项目两个web模块会导致shiro的session污染,求助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆