Skip to content

Commit 288d0e3

Browse files
author
Keith R. Gustafson
committed
When invalidating the session make it possible to start using a new one
Fix an issue where logout would correctly invalidate the session, but the Context.session remained the invalidated one so any subsequent changes to session values during that response would be lost. This change clears Context.session so a new session is created as needed and available for use during this response, instead of needing to wait for a subsequent request for the new session to be available.
1 parent e5d408f commit 288d0e3

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

gemini/src/main/java/com/techempower/gemini/Context.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,20 @@ public Session getSession(boolean create)
386386
return this.session;
387387
}
388388

389+
/**
390+
* In addition to invalidating the session, also sets the Context.session member variable to null
391+
* so it is re-created as needed and is available for immediate use.
392+
*/
393+
public void invalidateSession()
394+
{
395+
if (this.session != null)
396+
{
397+
this.session.invalidate();
398+
}
399+
// Rely on getSession() to create a new session as needed.
400+
this.session = null;
401+
}
402+
389403
/**
390404
* Gets the full standard (non-secure) URL to the Servlet.
391405
*/

gemini/src/main/java/com/techempower/gemini/context/SessionNamedValues.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -306,11 +306,7 @@ public SessionNamedValues clear()
306306
*/
307307
public SessionNamedValues invalidate()
308308
{
309-
final Session session = context.getSession(false);
310-
if (session != null)
311-
{
312-
session.invalidate();
313-
}
309+
context.invalidateSession();
314310
return this;
315311
}
316312

0 commit comments

Comments
 (0)