有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

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

你能回答这两个问题中的一个吗

  1. 为什么旧的javax.servlet.http.HttpSessionListener不再存在 打电话
  2. 如何将ShiroSession对象转换为HttpSession shiro SessionListener中的对象

共 (1) 个答案

  1. # 1 楼答案

    Why is the old javax.servlet.http.HttpSessionListener no longer called?

    正如您所解释的,会话管理现在通过Shiro处理,而不是通过Servlet容器。因此,即使注册了HttpSessionListener,Servlet容器也不会创建任何HttpSession对象,因此不会使用任何HttpSessionListener回调

    How do I transform Shiro Session objects to HttpSession objects in the shiro SessionListener?

    你没有,也不应该

    如果你解释一下你想用HttpSession做什么,我们也许能找到替代品