Rename expiration key on changeSessionId in RedisOperationsSessionRepository
This commit ensures existing expiration key is renamed on changeSessionId operation in RedisOperationsSessionRepository. Previously, this key wasn't renamed which caused invalid invocations of SessionDestroyedEvent handling when key expired. Closes gh-1029
This commit is contained in:
@@ -808,7 +808,12 @@ public class RedisOperationsSessionRepository implements
|
||||
if (!isNew()) {
|
||||
String originalSessionIdKey = getSessionKey(this.originalSessionId);
|
||||
String sessionIdKey = getSessionKey(sessionId);
|
||||
RedisOperationsSessionRepository.this.sessionRedisOperations.rename(originalSessionIdKey, sessionIdKey);
|
||||
RedisOperationsSessionRepository.this.sessionRedisOperations.rename(
|
||||
originalSessionIdKey, sessionIdKey);
|
||||
String originalExpiredKey = getExpiredKey(this.originalSessionId);
|
||||
String expiredKey = getExpiredKey(sessionId);
|
||||
RedisOperationsSessionRepository.this.sessionRedisOperations.rename(
|
||||
originalExpiredKey, expiredKey);
|
||||
}
|
||||
this.originalSessionId = sessionId;
|
||||
}
|
||||
|
||||
@@ -117,15 +117,46 @@ public class RedisOperationsSessionRepositoryTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void changeSessionId() {
|
||||
public void changeSessionIdWhenNotSaved() {
|
||||
given(this.redisOperations.boundHashOps(anyString()))
|
||||
.willReturn(this.boundHashOperations);
|
||||
given(this.redisOperations.boundSetOps(anyString()))
|
||||
.willReturn(this.boundSetOperations);
|
||||
given(this.redisOperations.boundValueOps(anyString()))
|
||||
.willReturn(this.boundValueOperations);
|
||||
|
||||
RedisSession createSession = this.redisRepository.createSession();
|
||||
String originalId = createSession.getId();
|
||||
String changeSessionId = createSession.changeSessionId();
|
||||
this.redisRepository.save(createSession);
|
||||
|
||||
verify(this.redisOperations, never()).rename(anyString(), anyString());
|
||||
|
||||
assertThat(originalId).isNotEqualTo(changeSessionId);
|
||||
assertThat(createSession.getId()).isEqualTo(createSession.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void changeSessionIdWhenSaved() {
|
||||
given(this.redisOperations.boundHashOps(anyString()))
|
||||
.willReturn(this.boundHashOperations);
|
||||
given(this.redisOperations.boundSetOps(anyString()))
|
||||
.willReturn(this.boundSetOperations);
|
||||
given(this.redisOperations.boundValueOps(anyString()))
|
||||
.willReturn(this.boundValueOperations);
|
||||
|
||||
RedisSession session = this.redisRepository.new RedisSession(this.cached);
|
||||
session.setLastAccessedTime(session.getLastAccessedTime());
|
||||
String originalId = session.getId();
|
||||
String changeSessionId = session.changeSessionId();
|
||||
this.redisRepository.save(session);
|
||||
|
||||
verify(this.redisOperations, times(2)).rename(anyString(), anyString());
|
||||
|
||||
assertThat(originalId).isNotEqualTo(changeSessionId);
|
||||
assertThat(session.getId()).isEqualTo(session.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createSessionDefaultMaxInactiveInterval() throws Exception {
|
||||
Session session = this.redisRepository.createSession();
|
||||
|
||||
Reference in New Issue
Block a user