From 6cbf71bd72187cba3727f6c24ba102c0486b341a Mon Sep 17 00:00:00 2001 From: Gajendra kumar Date: Thu, 29 Dec 2016 08:05:22 +0530 Subject: [PATCH] Allow inject Map into SessionRegistryImpl As principals and sessionIds are set in class itself so one can't share user session count across nodes(Cluster). Using constructor for setting principals and sessionIds we can pass Cache map to constructor which can enable common session count in cluster otherwise user would be allowed to logged in with multiple sessions. There is no point keeping principals and sessionIds completely internal. Fixes gh-4772 --- .../security/core/session/SessionRegistryImpl.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/org/springframework/security/core/session/SessionRegistryImpl.java b/core/src/main/java/org/springframework/security/core/session/SessionRegistryImpl.java index 809eb0c370..e4464bdf45 100644 --- a/core/src/main/java/org/springframework/security/core/session/SessionRegistryImpl.java +++ b/core/src/main/java/org/springframework/security/core/session/SessionRegistryImpl.java @@ -48,13 +48,23 @@ public class SessionRegistryImpl implements SessionRegistry, protected final Log logger = LogFactory.getLog(SessionRegistryImpl.class); /** */ - private final ConcurrentMap> principals = new ConcurrentHashMap>(); + private final ConcurrentMap> principals; /** */ - private final Map sessionIds = new ConcurrentHashMap(); + private final Map sessionIds; // ~ Methods // ======================================================================================================== + public SessionRegistryImpl() { + this.principals = new ConcurrentHashMap>(); + this.sessionIds = new ConcurrentHashMap(); + } + + public SessionRegistryImpl(ConcurrentMap> principals,Map sessionIds) { + this.principals=principals; + this.sessionIds=sessionIds; + } + public List getAllPrincipals() { return new ArrayList(principals.keySet()); }