SessionListener中的java Shiro HttpSession?
我正在尝试将我的webapp的会话管理(目前由Catalina/Tomcat处理)替换为shiro本机会话管理
这应该是一项相当容易的工作,正如shiro网站所宣传的:
Transparent HttpSession support - If you are using Shiro's native sessions, we have implemented HTTP Session API and the Servlet 2.5 API so you don't have to change any of your existing web code to use Shiro.
因此,之后,您用Shiro的DefaultWebSessionManager
替换了本地会话管理器,一切都应该开箱即用
我的webapp也是如此,除了某个javax.servlet.http.HttpSessionListener
。自从使用Shiro的会话管理后,此侦听器不再获取事件
不用担心,我想!Shiro提供了自己的org.apache.shiro.session.SessionListener
接口,可以链接到会话管理器
然而,这个接口与javax.servlet.http.HttpSessionListener
有很大不同。不再传递HttpSession
对象,而是Shiro侦听器通过事件传递自己的org.apache.shiro.session.Session
对象
当然,我现有的实现只适用于HttpSession
对象。我发现ShiroSession
可以转换为HttpSession
:
// HttpServletRequest currentRequest;
// ServletContext servletContext;
// Session session;
HttpSession httpSession = new ShiroHttpSession(session, currentRequest, servletContext);
但是,无法从ShiroSessionListener
访问HttpServletRequest和servletContext
你能回答这两个问题中的一个吗
- 为什么旧的
javax.servlet.http.HttpSessionListener
不再存在 打电话李> - 如何将Shiro
Session
对象转换为HttpSession
shiroSessionListener
中的对象李>
# 1 楼答案
正如您所解释的,会话管理现在通过Shiro处理,而不是通过Servlet容器。因此,即使注册了
HttpSessionListener
,Servlet容器也不会创建任何HttpSession
对象,因此不会使用任何HttpSessionListener
回调你没有,也不应该
如果你解释一下你想用
HttpSession
做什么,我们也许能找到替代品