0

I am doing an PoC of Spring Session to implement the complete Lifecycle management of (HTTP) Session. While doing so, i want to write a listener which can get notified when the Spring Session gets Auto expired.

In this listener, i want to do some clean-up activities.

How can i write a listener or does one already exists for Spring Session which can get invoked during it's Auto expiry ?

yathirigan
  • 5,619
  • 22
  • 66
  • 104
  • From the little I know about Spring Session, it actually replaces the default HttpSession implementation. Given that, I'd expect you can just register the standard HttpSessionListener in your web.xml and listen for sessionDestroyed events. – kaqqao Mar 10 '15 at 16:33
  • thank you.. i just discovered this thread discussing the same http://stackoverflow.com/questions/19534502/listener-for-session-expiration-in-spring , will try it now and post the results.. – yathirigan Mar 10 '15 at 16:46
  • That thread seems to be talking about invalidating the session as soon as the browser is closed, which is an unusual requirement. Normally, you just let the session expire in those cases, and normal expiration should trigger the event. – kaqqao Mar 10 '15 at 17:51
  • sorry i was about to correct the link.. here is the correct link which i am going to try http://stackoverflow.com/questions/27753111/perform-custom-event-before-session-expiry-in-spring/27753299#comment46186788_27753299 , do you think the solution recommended here would be the right one ? – yathirigan Mar 10 '15 at 17:54
  • Seems similar to my suggestion, so yeah, it think this should be fine. Note, though, that I haven't actually used Spring Session and am only concluding based on the stuff I've read. – kaqqao Mar 10 '15 at 18:26
  • during the Session Destroy event in my Spring Boot application, i am able to see the applicationEvent is only and instanceof SessionDestroyedEvent , instead of HttpSessionDestroyedEvent as mentioned in your solution. What difference is that ? – yathirigan Mar 10 '15 at 20:29

1 Answers1

0

Spring Session does not currently support HttpSessionListener. See spring-session/gh-4

You can listen to SessionDestroyedEvent's

They differ from the HttpSessionDestroyedEvent in that Spring Security will fire the HttpSessionDestroyedEvent based on the HttpSessionEventPublisher (an implementation of HttpSessonListener). Thus HttpSessionDestroyedEvent will not get fired when using Spring Session since there is no support for HttpSessionListener.

Rob Winch
  • 21,440
  • 2
  • 59
  • 76