I'm trying to replace the session management (Currently handled by Catalina/Tomcat) of my webapp to shiro native session management.
This should be a fairly easy job, as is adverted by the shiro website:
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.
So after, you replaced the local Session Manager with Shiro's DefaultWebSessionManager
everything should work out of the box.
This is also the case for my webapp, except for a certain javax.servlet.http.HttpSessionListener
. This Listener no longer gets events since using Shiro's session management.
No worries I thought! Shiro offers it's own org.apache.shiro.session.SessionListener
interface that can be linked to the session manager.
However, this interface differs a lot from javax.servlet.http.HttpSessionListener
. There are no longer HttpSession
objects passed, instead the Shiro Listener passes it's own org.apache.shiro.session.Session
objects with the events.
My existing implementation works ofcourse only with HttpSession
objects. I found out that a Shiro Session
can be transformed to a HttpSession
:
// HttpServletRequest currentRequest;
// ServletContext servletContext;
// Session session;
HttpSession httpSession = new ShiroHttpSession(session, currentRequest, servletContext);
However there is no way to acces the HttpServletRequest and servletContext from the Shiro SessionListener
.
Any ideas how to solve this problem, e.g. can you answer one of these two question?
- Why is the old
javax.servlet.http.HttpSessionListener
no longer called? - How do I transform Shiro
Session
objects toHttpSession
objects in the shiroSessionListener
?