首页 > 一个项目两个web模块会导致shiro的session污染,求助

一个项目两个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


干得漂亮,我做毕业设计的时候就没考虑这个问题,演示的时候同时登管理员和售货员,直接挂了!把管理员和用户分成两个对象存吧!


试试spring-session呢


解决办法:

    <!-- 会话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)


同一个域名服务器在客户端只能存在同一个key名的session或cookie,如果不希望互相干扰,可以把其中一个localhost改为其它名字,如'127.0.0.1'或者你自己的ip地址。

【热门文章】
【热门文章】