Shiro HttpSession in SessionListener?

I am trying to replace the session management (currently managed by Katalina / Tomcat) of my webapp to manage my own shiro sessions.

This should be a fairly simple task, as it is advertised on the siro website:

Transparent support for HttpSession - if you use the native language of Shiro sessions, we have implemented the HTTP Session API and Servlet 2.5 API so you do not need to change any existing web code to use Shiro.

So, you replaced the Shiro local session manager, DefaultWebSessionManagereverything should work out of the box.

This also applies to my webapp, with the exception of a few javax.servlet.http.HttpSessionListener. This listener no longer accepts events because it uses Shiro session management.

Do not worry, I thought! Shiro offers its own interface org.apache.shiro.session.SessionListenerthat can be associated with the session manager.

However, this interface is very different from javax.servlet.http.HttpSessionListener. No more HttpSessionobjects are transferred , instead the Ciro listener passes its own org.apache.shiro.session.Sessionobjects with events.

My existing implementation only works with objects, of course HttpSession. I found out that Shiro Sessioncan be converted to HttpSession:

// HttpServletRequest currentRequest;
// ServletContext servletContext;
// Session session;
HttpSession httpSession = new ShiroHttpSession(session, currentRequest, servletContext);

However, there is no way to access the HttpServletRequest and servletContext from Shiro SessionListener.

Any ideas how to solve this problem, for example. can you answer one of these two questions?

  • Why javax.servlet.http.HttpSessionListenerdoes the old one no longer work called?
  • How to convert Shiro objects Sessionto HttpSession objects in the Syro SessionListener?
+4
1

javax.servlet.http.HttpSessionListener ?

, Shiro, Servlet. , HttpSessionListener , Servlet HttpSession HttpSessionListener.

Shiro Session HttpSession SessionListener?

, .

, HttpSession, .

+3

All Articles