From 24dd0035e33982cb0a23aad254d10307e8909e27 Mon Sep 17 00:00:00 2001 From: lprimak Date: Tue, 7 Jul 2026 15:08:54 -0500 Subject: [PATCH] enh: added new constructors to be able to set host and start timestamp --- .../apache/shiro/session/mgt/SimpleSession.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/org/apache/shiro/session/mgt/SimpleSession.java b/core/src/main/java/org/apache/shiro/session/mgt/SimpleSession.java index 71664758d6..a76e4bf07c 100644 --- a/core/src/main/java/org/apache/shiro/session/mgt/SimpleSession.java +++ b/core/src/main/java/org/apache/shiro/session/mgt/SimpleSession.java @@ -18,6 +18,7 @@ */ package org.apache.shiro.session.mgt; +import lombok.NonNull; import org.apache.shiro.session.ExpiredSessionException; import org.apache.shiro.session.InvalidSessionException; import org.apache.shiro.session.StoppedSessionException; @@ -102,9 +103,13 @@ public class SimpleSession implements ValidatingSession, Serializable { private transient volatile Map attributes; public SimpleSession() { + this(new Date()); + } + + public SimpleSession(Date startTimestamp) { //TODO - remove concrete reference to DefaultSessionManager this.timeout = new AtomicLong(DefaultSessionManager.DEFAULT_GLOBAL_SESSION_TIMEOUT); - this.startTimestamp = new Date(); + this.startTimestamp = startTimestamp; this.stopTimestamp = new AtomicReference<>(); this.lastAccessTime = new AtomicReference<>(this.startTimestamp); } @@ -114,6 +119,15 @@ public SimpleSession(String host) { this.host = host; } + /** + * @param host null allowed + * @param startTimestamp null not allowed + */ + public SimpleSession(String host, @NonNull Date startTimestamp) { + this(startTimestamp); + this.host = host; + } + @Override public Serializable getId() { return this.id;