You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Cannot invalidate HTTP session from SessionDestroyListener #6959
In #6763 it's suggested that HttpSession can be invalidated from Vaadin SessionDestroyListener, however, when the listener is executed the wrapped session is null.
Expected behavior:
I should be able to invalidate the HttpSession after some period of inactivity.
Actual behavior
The HttpSession is not available after the Vaadin session has been destroyed.
That's unfortunately true, the wrapped session in destroyed listener is null.
You may use VaadinRequest.getCurrent().getWrappedSession() to access it instead.
But this bug is valid anyway.
I would avoid using Spring to reproduce.
Here is my code which I use to reproduce the issue without Spring:
@WebServlet(asyncSupported = true, urlPatterns = { "/*" }, initParams = {
@WebInitParam(name = "closeIdleSessions", value = "true"),
@WebInitParam(name = "heartbeatInterval", value = "10") })
public class MyServlet extends VaadinServlet {
}
public class VaadinServiceInitListenerImpl
implements VaadinServiceInitListener {
@Override
public void serviceInit(ServiceInitEvent event) {
event.getSource().addSessionInitListener(
ev -> ev.getSession().getSession().setMaxInactiveInterval(30));
event.getSource().addSessionDestroyListener(ev -> {
System.out.println("Vaadin session destroyed");
VaadinSession vsession = ev.getSession();
WrappedSession wsession = vsession.getSession();
if (wsession == null) {
System.out.println("wrapped session is null");
} else {
wsession.invalidate();
}
});
}
}
Also you need src/main/resources/META-INF/services/com.vaadin.flow.server.VaadinServiceInitListener
file with the content: com.vaadin.starter.skeleton.VaadinServiceInitListenerImpl (I'm using plain skeleton-starter project)
Activity
denis-anisimov commentedon Nov 18, 2019
That's unfortunately true, the wrapped session in destroyed listener is
null.You may use
VaadinRequest.getCurrent().getWrappedSession()to access it instead.But this bug is valid anyway.
I would avoid using Spring to reproduce.
Here is my code which I use to reproduce the issue without Spring:
Also you need
src/main/resources/META-INF/services/com.vaadin.flow.server.VaadinServiceInitListenerfile with the content:
com.vaadin.starter.skeleton.VaadinServiceInitListenerImpl(I'm using plainskeleton-starterproject)fix: reset HTTP session on CLOSED state, not immidiately
fix: reset HTTP session on CLOSED state, not immidiately (#11377)
fix: reset HTTP session on CLOSED state, not immidiately (#11377)
fix: reset HTTP session on CLOSED state, not immidiately (#11377) (#1…
fix: reset HTTP session on CLOSED state, not immidiately (#11377)
fix: reset HTTP session on CLOSED state, not immidiately (#11377) (#1…
fix: reset HTTP session on CLOSED state, not immidiately (#11377) (#1…
fix: reset HTTP session on CLOSED state, not immidiately (#11377) (#1…
8 remaining items
fix: reset session field only when HTTP session is invalidated (#11416)…
vaadin-bot commentedon Jul 26, 2021
This ticket/PR has been released with platform 20.0.5. For prerelease versions, it will be included in its final version.
fix: reset session field only when HTTP session is invalidated (#11416)
fix: reset session field only when HTTP session is invalidated (#11416)…
fix: reset session field only when HTTP session is invalidated (#11416)…
fix: reset session field only when HTTP session is invalidated (#11416)…
vaadin-bot commentedon Aug 6, 2021
This ticket/PR has been released with platform 21.0.0.beta1 and is also targeting the upcoming stable 21.0.0 version.
vaadin-bot commentedon Aug 9, 2021
This ticket/PR has been released with platform 14.7.0.alpha3 and is also targeting the upcoming stable 14.7.0 version.
vaadin-bot commentedon Sep 13, 2021
This ticket/PR has been released with platform 14.6.9.