我正在尝试将我的Web应用程序的会话管理(目前由Catalina / Tomcat处理)替换为Shiro本地会话管理。
这应该是一项相当容易的工作,正如Shiro网站所宣传的那样:
透明的HttpSession支持- 如果您正在使用Shiro的本机 会话,我们已经实现了HTTP Session API和Servlet 2.5 API, 因此您无需更改任何现有的Web代码即可使用Shiro。
因此,在您将本地会话管理器替换为Shiro的 DefaultWebSessionManager
之后,一切都应该顺利进行。
对于我的Web应用程序也是如此,但是对于某个javax.servlet.http.HttpSessionListener
,情况并非如此。自从使用Shiro的会话管理以来,此侦听器不再收到事件。
没关系!Shiro提供了自己的org.apache.shiro.session.SessionListener
接口,可以链接到会话管理器。
但是,此接口与javax.servlet.http.HttpSessionListener
大不相同。不再传递HttpSession
对象,而是Shiro侦听器使用其自己的 org.apache.shiro.session.Session
对象传递事件。
我的现有实现当然仅适用于HttpSession
对象。我发现可以将Shiro Session
转换为 HttpSession
:
// HttpServletRequest currentRequest;
// ServletContext servletContext;
// Session session;
HttpSession httpSession = new ShiroHttpSession(session, currentRequest, servletContext);
然而,无法从Shiro SessionListener
访问HttpServletRequest和servletContext。
有什么解决这个问题的想法吗?例如,您能回答以下两个问题之一吗?
- 为什么旧的
javax.servlet.http.HttpSessionListener
不再被调用? - 在shiro
SessionListener
中如何将ShiroSession
对象转换为HttpSession
对象?
HttpSession
方法?Shiro的Session
也有属性设置器和获取器,但很显然这些对JSP等不可用。 - Sotirios Delimanolis