From 2c6f327395ac5631dd6145e5d1f7666b69f0a5c1 Mon Sep 17 00:00:00 2001 From: Nikita Koksharov Date: Mon, 7 Jan 2019 10:53:40 +0300 Subject: [PATCH] Fixed - Spring Session changeSessionId method doesn't change session id. #1813 --- .../session/RedissonSessionRepository.java | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/redisson/src/main/java/org/redisson/spring/session/RedissonSessionRepository.java b/redisson/src/main/java/org/redisson/spring/session/RedissonSessionRepository.java index d22c7d6c7..c81cfb5df 100644 --- a/redisson/src/main/java/org/redisson/spring/session/RedissonSessionRepository.java +++ b/redisson/src/main/java/org/redisson/spring/session/RedissonSessionRepository.java @@ -58,7 +58,7 @@ public class RedissonSessionRepository implements FindByIndexNameSessionReposito private final MapSession delegate; private RMap map; - public RedissonSession(String keyPrefix) { + public RedissonSession() { this.delegate = new MapSession(); map = redisson.getMap(keyPrefix + delegate.getId()); principalName = resolvePrincipal(delegate); @@ -82,7 +82,7 @@ public class RedissonSessionRepository implements FindByIndexNameSessionReposito } } - public RedissonSession(String keyPrefix, String sessionId) { + public RedissonSession(String sessionId) { this.delegate = new MapSession(sessionId); map = redisson.getMap(keyPrefix + sessionId); principalName = resolvePrincipal(delegate); @@ -214,7 +214,9 @@ public class RedissonSessionRepository implements FindByIndexNameSessionReposito @Override public String changeSessionId() { - return delegate.changeSessionId(); + String id = delegate.changeSessionId(); + map.rename(keyPrefix + id); + return id; } } @@ -259,7 +261,7 @@ public class RedissonSessionRepository implements FindByIndexNameSessionReposito } String id = body.split(":")[1]; - RedissonSession session = new RedissonSession(keyPrefix, id); + RedissonSession session = new RedissonSession(id); if (session.load()) { session.clearPrincipal(); } @@ -270,7 +272,7 @@ public class RedissonSessionRepository implements FindByIndexNameSessionReposito } String id = body.split(":")[1]; - RedissonSession session = new RedissonSession(keyPrefix, id); + RedissonSession session = new RedissonSession(id); if (session.load()) { session.clearPrincipal(); } @@ -292,7 +294,7 @@ public class RedissonSessionRepository implements FindByIndexNameSessionReposito @Override public RedissonSession createSession() { - RedissonSession session = new RedissonSession(keyPrefix); + RedissonSession session = new RedissonSession(); if (defaultMaxInactiveInterval != null) { session.setMaxInactiveInterval(Duration.ofSeconds(defaultMaxInactiveInterval)); } @@ -306,7 +308,7 @@ public class RedissonSessionRepository implements FindByIndexNameSessionReposito @Override public RedissonSession findById(String id) { - RedissonSession session = new RedissonSession(keyPrefix, id); + RedissonSession session = new RedissonSession(id); if (!session.load() || session.isExpired()) { return null; }