@@ -44,6 +43,7 @@
*
* @author Rob Winch
* @author Vedran Pavic
+ * @author Jakub Maciej
* @since 1.0
*/
public final class MapSession implements Session, Serializable {
@@ -68,13 +68,6 @@ public final class MapSession implements Session, Serializable {
*/
private Duration maxInactiveInterval = Duration.ofSeconds(DEFAULT_MAX_INACTIVE_INTERVAL_SECONDS);
- /**
- * Creates a new instance with a secure randomly generated identifier.
- */
- public MapSession() {
- this(generateId());
- }
-
/**
* Creates a new instance with the specified id. This is preferred to the default
* constructor when the id is known to prevent unnecessary consumption on entropy
@@ -124,22 +117,20 @@ public String getId() {
return this.id;
}
+ @Override
+ public void changeSessionId(final String id) {
+ setId(id);
+ }
+
/**
* Get the original session id.
* @return the original session id
- * @see #changeSessionId()
+ * @see #changeSessionId(String changedId)
*/
public String getOriginalId() {
return this.originalId;
}
- @Override
- public String changeSessionId() {
- String changedId = generateId();
- setId(changedId);
- return changedId;
- }
-
@Override
public Instant getLastAccessedTime() {
return this.lastAccessedTime;
@@ -222,10 +213,6 @@ public int hashCode() {
return this.id.hashCode();
}
- private static String generateId() {
- return UUID.randomUUID().toString();
- }
-
private static final long serialVersionUID = 7160779239673823561L;
}
diff --git a/spring-session-core/src/main/java/org/springframework/session/MapSessionRepository.java b/spring-session-core/src/main/java/org/springframework/session/MapSessionRepository.java
index 373c01824..44858a9c4 100644
--- a/spring-session-core/src/main/java/org/springframework/session/MapSessionRepository.java
+++ b/spring-session-core/src/main/java/org/springframework/session/MapSessionRepository.java
@@ -21,6 +21,7 @@
import org.springframework.session.events.SessionDeletedEvent;
import org.springframework.session.events.SessionExpiredEvent;
+import org.springframework.util.Assert;
/**
* A {@link SessionRepository} backed by a {@link java.util.Map} and that uses a
@@ -34,6 +35,7 @@
*
*
* @author Rob Winch
+ * @author Jakub Maciej
* @since 1.0
*/
public class MapSessionRepository implements SessionRepository {
@@ -46,6 +48,8 @@ public class MapSessionRepository implements SessionRepository {
private final Map sessions;
+ private SessionIdStrategy sessionIdStrategy = SessionIdStrategy.getDefault();
+
/**
* Creates a new instance backed by the provided {@link java.util.Map}. This allows
* injecting a distributed {@link java.util.Map}.
@@ -94,13 +98,30 @@ public void deleteById(String id) {
this.sessions.remove(id);
}
+ @Override
+ public String changeSessionId(final MapSession session) {
+ String newId = this.sessionIdStrategy.createSessionId();
+ session.changeSessionId(newId);
+ return newId;
+ }
+
@Override
public MapSession createSession() {
- MapSession result = new MapSession();
+ MapSession result = new MapSession(this.sessionIdStrategy.createSessionId());
if (this.defaultMaxInactiveInterval != null) {
result.setMaxInactiveInterval(Duration.ofSeconds(this.defaultMaxInactiveInterval));
}
return result;
}
+ /**
+ * Allows override of default session id generation strategy.
+ * @param sessionIdStrategy session id generation strategy to be used with this
+ * repository
+ */
+ public void setSessionIdStrategy(final SessionIdStrategy sessionIdStrategy) {
+ Assert.notNull(sessionIdStrategy, "sessionIdStrategy must not be null");
+ this.sessionIdStrategy = sessionIdStrategy;
+ }
+
}
diff --git a/spring-session-core/src/main/java/org/springframework/session/ReactiveMapSessionRepository.java b/spring-session-core/src/main/java/org/springframework/session/ReactiveMapSessionRepository.java
index ed3d843fd..a01ddf3cf 100644
--- a/spring-session-core/src/main/java/org/springframework/session/ReactiveMapSessionRepository.java
+++ b/spring-session-core/src/main/java/org/springframework/session/ReactiveMapSessionRepository.java
@@ -23,6 +23,7 @@
import org.springframework.session.events.SessionDeletedEvent;
import org.springframework.session.events.SessionExpiredEvent;
+import org.springframework.util.Assert;
/**
* A {@link ReactiveSessionRepository} backed by a {@link Map} and that uses a
@@ -36,10 +37,13 @@
*
*
* @author Rob Winch
+ * @author Jakub Maciej
* @since 2.0
*/
public class ReactiveMapSessionRepository implements ReactiveSessionRepository {
+ private SessionIdStrategy sessionIdStrategy = SessionIdStrategy.getDefault();
+
/**
* If non-null, this value is used to override
* {@link Session#setMaxInactiveInterval(Duration)}.
@@ -98,7 +102,7 @@ public Mono deleteById(String id) {
@Override
public Mono createSession() {
return Mono.defer(() -> {
- MapSession result = new MapSession();
+ MapSession result = new MapSession(this.sessionIdStrategy.createSessionId());
if (this.defaultMaxInactiveInterval != null) {
result.setMaxInactiveInterval(Duration.ofSeconds(this.defaultMaxInactiveInterval));
}
@@ -106,4 +110,14 @@ public Mono createSession() {
});
}
+ /**
+ * Allows override of default session id generation strategy.
+ * @param sessionIdStrategy session id generation strategy to be used with this
+ * repository
+ */
+ public void setSessionIdStrategy(final SessionIdStrategy sessionIdStrategy) {
+ Assert.notNull(sessionIdStrategy, "sessionIdStrategy must not be null");
+ this.sessionIdStrategy = sessionIdStrategy;
+ }
+
}
diff --git a/spring-session-core/src/main/java/org/springframework/session/Session.java b/spring-session-core/src/main/java/org/springframework/session/Session.java
index 6be3445cc..34683832e 100644
--- a/spring-session-core/src/main/java/org/springframework/session/Session.java
+++ b/spring-session-core/src/main/java/org/springframework/session/Session.java
@@ -26,6 +26,7 @@
*
* @author Rob Winch
* @author Vedran Pavic
+ * @author Jakub Maciej
* @since 1.0
*/
public interface Session {
@@ -39,9 +40,9 @@ public interface Session {
/**
* Changes the session id. After invoking the {@link #getId()} will return a new
* identifier.
- * @return the new session id which {@link #getId()} will now return
+ * @param id desired new sessionId
*/
- String changeSessionId();
+ void changeSessionId(String id);
/**
* Gets the Object associated with the specified name or null if no Object is
diff --git a/spring-session-core/src/main/java/org/springframework/session/SessionIdStrategy.java b/spring-session-core/src/main/java/org/springframework/session/SessionIdStrategy.java
new file mode 100644
index 000000000..f7b00c1ad
--- /dev/null
+++ b/spring-session-core/src/main/java/org/springframework/session/SessionIdStrategy.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2014-2019 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.session;
+
+/**
+ * Provides a common interface for id generation strategy. Allows customization of session
+ * id creation process.
+ *
+ * @author Jakub Maciej
+ */
+public interface SessionIdStrategy {
+
+ /**
+ * Gets a unique string that identifies the {@link Session}.
+ * @return a unique string that identifies the {@link Session}
+ */
+ String createSessionId();
+
+ /**
+ * Gets default strategy used to generate session id {@link SessionIdStrategy}.
+ * @return gets default strategy used to generate session id {@link SessionIdStrategy}
+ */
+ static SessionIdStrategy getDefault() {
+ return new UUIDSessionIdStrategy();
+ }
+
+}
diff --git a/spring-session-core/src/main/java/org/springframework/session/SessionRepository.java b/spring-session-core/src/main/java/org/springframework/session/SessionRepository.java
index 7efe2f995..bbc79d821 100644
--- a/spring-session-core/src/main/java/org/springframework/session/SessionRepository.java
+++ b/spring-session-core/src/main/java/org/springframework/session/SessionRepository.java
@@ -21,6 +21,7 @@
*
* @param the {@link Session} type
* @author Rob Winch
+ * @author Jakub Maciej
* @since 1.0
*/
public interface SessionRepository {
@@ -68,4 +69,11 @@ public interface SessionRepository {
*/
void deleteById(String id);
+ /**
+ * Changes the session id.
+ * @param session which id should be changed
+ * @return new session id
+ */
+ String changeSessionId(S session);
+
}
diff --git a/spring-session-core/src/main/java/org/springframework/session/UUIDSessionIdStrategy.java b/spring-session-core/src/main/java/org/springframework/session/UUIDSessionIdStrategy.java
new file mode 100644
index 000000000..3a16e766a
--- /dev/null
+++ b/spring-session-core/src/main/java/org/springframework/session/UUIDSessionIdStrategy.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2014-2019 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.session;
+
+import java.util.UUID;
+
+/**
+ * UUID based session generation strategy. This is default strategy for session id
+ * generation.
+ *
+ * @author Jakub Maciej
+ */
+public class UUIDSessionIdStrategy implements SessionIdStrategy {
+
+ @Override
+ public String createSessionId() {
+ return UUID.randomUUID().toString();
+ }
+
+}
diff --git a/spring-session-core/src/main/java/org/springframework/session/web/http/SessionRepositoryFilter.java b/spring-session-core/src/main/java/org/springframework/session/web/http/SessionRepositoryFilter.java
index c12e80081..b5e91b6b8 100644
--- a/spring-session-core/src/main/java/org/springframework/session/web/http/SessionRepositoryFilter.java
+++ b/spring-session-core/src/main/java/org/springframework/session/web/http/SessionRepositoryFilter.java
@@ -75,6 +75,7 @@
* @author Rob Winch
* @author Vedran Pavic
* @author Josh Cummings
+ * @author Jakub Maciej
*/
@Order(SessionRepositoryFilter.DEFAULT_ORDER)
public class SessionRepositoryFilter extends OncePerRequestFilter {
@@ -254,7 +255,7 @@ public String changeSessionId() {
"Cannot change session ID. There is no session associated with this request.");
}
- return getCurrentSession().getSession().changeSessionId();
+ return SessionRepositoryFilter.this.sessionRepository.changeSessionId(getCurrentSession().getSession());
}
@Override
diff --git a/spring-session-core/src/main/java/org/springframework/session/web/server/session/SpringSessionWebSessionStore.java b/spring-session-core/src/main/java/org/springframework/session/web/server/session/SpringSessionWebSessionStore.java
index 97e0d9103..ab472e61e 100644
--- a/spring-session-core/src/main/java/org/springframework/session/web/server/session/SpringSessionWebSessionStore.java
+++ b/spring-session-core/src/main/java/org/springframework/session/web/server/session/SpringSessionWebSessionStore.java
@@ -35,6 +35,7 @@
import org.springframework.lang.Nullable;
import org.springframework.session.ReactiveSessionRepository;
import org.springframework.session.Session;
+import org.springframework.session.SessionIdStrategy;
import org.springframework.util.Assert;
import org.springframework.web.server.WebSession;
import org.springframework.web.server.session.WebSessionStore;
@@ -47,12 +48,15 @@
* @param the {@link Session} type
* @author Rob Winch
* @author Vedran Pavic
+ * @author Jakub Maciej
* @since 2.0
*/
public class SpringSessionWebSessionStore implements WebSessionStore {
private final ReactiveSessionRepository sessions;
+ private SessionIdStrategy sessionIdStrategy = SessionIdStrategy.getDefault();
+
private Clock clock = Clock.system(ZoneOffset.UTC);
public SpringSessionWebSessionStore(ReactiveSessionRepository reactiveSessionRepository) {
@@ -108,6 +112,16 @@ private SpringSessionWebSession existingSession(S session) {
return new SpringSessionWebSession(session, State.STARTED);
}
+ /**
+ * Allows override of default session id generation strategy.
+ * @param sessionIdStrategy session id generation strategy to be used with this
+ * repository
+ */
+ public void setSessionIdStrategy(final SessionIdStrategy sessionIdStrategy) {
+ Assert.notNull(sessionIdStrategy, "sessionIdStrategy must not be null");
+ this.sessionIdStrategy = sessionIdStrategy;
+ }
+
/**
* Adapts Spring Session's {@link Session} to a {@link WebSession}.
*/
@@ -134,7 +148,7 @@ public String getId() {
@Override
public Mono changeSessionId() {
return Mono.defer(() -> {
- this.session.changeSessionId();
+ this.session.changeSessionId(SpringSessionWebSessionStore.this.sessionIdStrategy.createSessionId());
return save();
});
}
diff --git a/spring-session-core/src/test/java/org/springframework/session/DelegatingIndexResolverTests.java b/spring-session-core/src/test/java/org/springframework/session/DelegatingIndexResolverTests.java
index f5e243391..430ecaeba 100644
--- a/spring-session-core/src/test/java/org/springframework/session/DelegatingIndexResolverTests.java
+++ b/spring-session-core/src/test/java/org/springframework/session/DelegatingIndexResolverTests.java
@@ -40,7 +40,7 @@ void setUp() {
@Test
void resolve() {
- MapSession session = new MapSession();
+ MapSession session = new MapSession("1");
session.setAttribute("one", "first");
session.setAttribute("two", "second");
Map indexes = this.indexResolver.resolveIndexesFor(session);
diff --git a/spring-session-core/src/test/java/org/springframework/session/MapSessionRepositoryTests.java b/spring-session-core/src/test/java/org/springframework/session/MapSessionRepositoryTests.java
index ede43f20d..b25b7c4fa 100644
--- a/spring-session-core/src/test/java/org/springframework/session/MapSessionRepositoryTests.java
+++ b/spring-session-core/src/test/java/org/springframework/session/MapSessionRepositoryTests.java
@@ -38,7 +38,7 @@ class MapSessionRepositoryTests {
@BeforeEach
void setup() {
this.repository = new MapSessionRepository(new ConcurrentHashMap<>());
- this.session = new MapSession();
+ this.session = new MapSession("1");
}
@Test
@@ -55,12 +55,12 @@ void createSessionDefaultExpiration() {
Session session = this.repository.createSession();
assertThat(session).isInstanceOf(MapSession.class);
- assertThat(session.getMaxInactiveInterval()).isEqualTo(new MapSession().getMaxInactiveInterval());
+ assertThat(session.getMaxInactiveInterval()).isEqualTo(new MapSession("1").getMaxInactiveInterval());
}
@Test
void createSessionCustomDefaultExpiration() {
- final Duration expectedMaxInterval = new MapSession().getMaxInactiveInterval().plusSeconds(10);
+ final Duration expectedMaxInterval = new MapSession("1").getMaxInactiveInterval().plusSeconds(10);
this.repository.setDefaultMaxInactiveInterval((int) expectedMaxInterval.getSeconds());
Session session = this.repository.createSession();
@@ -73,7 +73,7 @@ void changeSessionIdWhenNotYetSaved() {
MapSession createSession = this.repository.createSession();
String originalId = createSession.getId();
- createSession.changeSessionId();
+ createSession.changeSessionId("1");
this.repository.save(createSession);
@@ -88,7 +88,7 @@ void changeSessionIdWhenSaved() {
this.repository.save(createSession);
String originalId = createSession.getId();
- createSession.changeSessionId();
+ createSession.changeSessionId("1");
this.repository.save(createSession);
diff --git a/spring-session-core/src/test/java/org/springframework/session/MapSessionTests.java b/spring-session-core/src/test/java/org/springframework/session/MapSessionTests.java
index 36221f5e9..ea944b3fd 100644
--- a/spring-session-core/src/test/java/org/springframework/session/MapSessionTests.java
+++ b/spring-session-core/src/test/java/org/springframework/session/MapSessionTests.java
@@ -32,7 +32,7 @@ class MapSessionTests {
@BeforeEach
void setup() {
- this.session = new MapSession();
+ this.session = new MapSession("1");
this.session.setLastAccessedTime(Instant.ofEpochMilli(1413258262962L));
}
@@ -151,7 +151,7 @@ public Instant getCreationTime() {
}
@Override
- public String changeSessionId() {
+ public void changeSessionId(String id) {
throw new UnsupportedOperationException();
}
diff --git a/spring-session-core/src/test/java/org/springframework/session/PrincipalNameIndexResolverTests.java b/spring-session-core/src/test/java/org/springframework/session/PrincipalNameIndexResolverTests.java
index aec43d1c6..d469d73ee 100644
--- a/spring-session-core/src/test/java/org/springframework/session/PrincipalNameIndexResolverTests.java
+++ b/spring-session-core/src/test/java/org/springframework/session/PrincipalNameIndexResolverTests.java
@@ -47,7 +47,7 @@ void setUp() {
@Test
void resolveFromPrincipalName() {
- MapSession session = new MapSession();
+ MapSession session = new MapSession("1");
session.setAttribute(FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME, PRINCIPAL_NAME);
assertThat(this.indexResolver.resolveIndexValueFor(session)).isEqualTo(PRINCIPAL_NAME);
}
@@ -58,7 +58,7 @@ void resolveFromSpringSecurityContext() {
AuthorityUtils.createAuthorityList("ROLE_USER"));
SecurityContext context = new SecurityContextImpl();
context.setAuthentication(authentication);
- MapSession session = new MapSession();
+ MapSession session = new MapSession("1");
session.setAttribute(SPRING_SECURITY_CONTEXT, context);
assertThat(this.indexResolver.resolveIndexValueFor(session)).isEqualTo(PRINCIPAL_NAME);
}
diff --git a/spring-session-core/src/test/java/org/springframework/session/ReactiveMapSessionRepositoryTests.java b/spring-session-core/src/test/java/org/springframework/session/ReactiveMapSessionRepositoryTests.java
index 23044fe2e..32bb952d4 100644
--- a/spring-session-core/src/test/java/org/springframework/session/ReactiveMapSessionRepositoryTests.java
+++ b/spring-session-core/src/test/java/org/springframework/session/ReactiveMapSessionRepositoryTests.java
@@ -98,12 +98,12 @@ void createSessionWhenDefaultMaxInactiveIntervalThenDefaultMaxInactiveInterval()
Session session = this.repository.createSession().block();
assertThat(session).isInstanceOf(MapSession.class);
- assertThat(session.getMaxInactiveInterval()).isEqualTo(new MapSession().getMaxInactiveInterval());
+ assertThat(session.getMaxInactiveInterval()).isEqualTo(new MapSession("1").getMaxInactiveInterval());
}
@Test
void createSessionWhenCustomMaxInactiveIntervalThenCustomMaxInactiveInterval() {
- final Duration expectedMaxInterval = new MapSession().getMaxInactiveInterval().plusSeconds(10);
+ final Duration expectedMaxInterval = new MapSession("1").getMaxInactiveInterval().plusSeconds(10);
this.repository.setDefaultMaxInactiveInterval((int) expectedMaxInterval.getSeconds());
Session session = this.repository.createSession().block();
@@ -116,7 +116,7 @@ void changeSessionIdWhenNotYetSaved() {
MapSession createSession = this.repository.createSession().block();
String originalId = createSession.getId();
- createSession.changeSessionId();
+ createSession.changeSessionId("1");
this.repository.save(createSession).block();
@@ -131,7 +131,7 @@ void changeSessionIdWhenSaved() {
this.repository.save(createSession).block();
String originalId = createSession.getId();
- createSession.changeSessionId();
+ createSession.changeSessionId("1");
this.repository.save(createSession).block();
diff --git a/spring-session-core/src/test/java/org/springframework/session/config/annotation/web/http/EnableSpringHttpSessionCustomCookieSerializerTests.java b/spring-session-core/src/test/java/org/springframework/session/config/annotation/web/http/EnableSpringHttpSessionCustomCookieSerializerTests.java
index e36294b7e..4cfe7299b 100644
--- a/spring-session-core/src/test/java/org/springframework/session/config/annotation/web/http/EnableSpringHttpSessionCustomCookieSerializerTests.java
+++ b/spring-session-core/src/test/java/org/springframework/session/config/annotation/web/http/EnableSpringHttpSessionCustomCookieSerializerTests.java
@@ -102,7 +102,7 @@ void usesReadSessionIds() throws Exception {
@Test
void usesWrite() throws Exception {
- given(this.sessionRepository.createSession()).willReturn(new MapSession());
+ given(this.sessionRepository.createSession()).willReturn(new MapSession("1"));
this.sessionRepositoryFilter.doFilter(this.request, this.response, new MockFilterChain() {
diff --git a/spring-session-core/src/test/java/org/springframework/session/web/http/CookieHttpSessionIdResolverTests.java b/spring-session-core/src/test/java/org/springframework/session/web/http/CookieHttpSessionIdResolverTests.java
index 87fdf54a1..cd05ebbc2 100644
--- a/spring-session-core/src/test/java/org/springframework/session/web/http/CookieHttpSessionIdResolverTests.java
+++ b/spring-session-core/src/test/java/org/springframework/session/web/http/CookieHttpSessionIdResolverTests.java
@@ -49,7 +49,7 @@ class CookieHttpSessionIdResolverTests {
@BeforeEach
void setup() {
this.cookieName = "SESSION";
- this.session = new MapSession();
+ this.session = new MapSession("1");
this.request = new MockHttpServletRequest();
this.response = new MockHttpServletResponse();
this.strategy = new CookieHttpSessionIdResolver();
@@ -91,7 +91,7 @@ void onNewSessionTwiceSameId() {
@Test
void onNewSessionTwiceNewId() {
- Session newSession = new MapSession();
+ Session newSession = new MapSession("2");
this.strategy.setSessionId(this.request, this.response, this.session.getId());
this.strategy.setSessionId(this.request, this.response, newSession.getId());
diff --git a/spring-session-core/src/test/java/org/springframework/session/web/http/SessionEventHttpSessionListenerAdapterTests.java b/spring-session-core/src/test/java/org/springframework/session/web/http/SessionEventHttpSessionListenerAdapterTests.java
index 7a2be0ca6..c97819da6 100644
--- a/spring-session-core/src/test/java/org/springframework/session/web/http/SessionEventHttpSessionListenerAdapterTests.java
+++ b/spring-session-core/src/test/java/org/springframework/session/web/http/SessionEventHttpSessionListenerAdapterTests.java
@@ -73,7 +73,7 @@ void setup() {
this.listener = new SessionEventHttpSessionListenerAdapter(Arrays.asList(this.listener1, this.listener2));
this.listener.setServletContext(new MockServletContext());
- Session session = new MapSession();
+ Session session = new MapSession("1");
this.destroyed = new SessionDestroyedEvent(this, session);
this.created = new SessionCreatedEvent(this, session);
}
diff --git a/spring-session-core/src/test/java/org/springframework/session/web/http/SessionRepositoryFilterTests.java b/spring-session-core/src/test/java/org/springframework/session/web/http/SessionRepositoryFilterTests.java
index 2b1a5f843..67ac8c9f6 100644
--- a/spring-session-core/src/test/java/org/springframework/session/web/http/SessionRepositoryFilterTests.java
+++ b/spring-session-core/src/test/java/org/springframework/session/web/http/SessionRepositoryFilterTests.java
@@ -133,7 +133,7 @@ public void doFilter(HttpServletRequest wrappedRequest) {
@Test
void doFilterCreateSetsLastAccessedTime() throws Exception {
- MapSession session = new MapSession();
+ MapSession session = new MapSession("1");
session.setLastAccessedTime(Instant.EPOCH);
this.sessionRepository = spy(this.sessionRepository);
given(this.sessionRepository.createSession()).willReturn(session);
diff --git a/spring-session-data-redis/src/integration-test/java/org/springframework/session/data/redis/ReactiveRedisSessionRepositoryITests.java b/spring-session-data-redis/src/integration-test/java/org/springframework/session/data/redis/ReactiveRedisSessionRepositoryITests.java
index c58a96705..7c36afd09 100644
--- a/spring-session-data-redis/src/integration-test/java/org/springframework/session/data/redis/ReactiveRedisSessionRepositoryITests.java
+++ b/spring-session-data-redis/src/integration-test/java/org/springframework/session/data/redis/ReactiveRedisSessionRepositoryITests.java
@@ -25,6 +25,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.session.Session;
+import org.springframework.session.SessionIdStrategy;
import org.springframework.session.data.redis.ReactiveRedisSessionRepository.RedisSession;
import org.springframework.session.data.redis.config.annotation.web.server.EnableRedisWebSession;
import org.springframework.test.context.ContextConfiguration;
@@ -44,6 +45,8 @@
@WebAppConfiguration
class ReactiveRedisSessionRepositoryITests extends AbstractRedisITests {
+ private final SessionIdStrategy sessionIdStrategy = SessionIdStrategy.getDefault();
+
@Autowired
private ReactiveRedisSessionRepository repository;
@@ -114,7 +117,8 @@ void changeSessionIdWhenOnlyChangeId() {
assertThat(findById.getAttribute(attrName)).isEqualTo(attrValue);
String originalFindById = findById.getId();
- String changeSessionId = findById.changeSessionId();
+ String changeSessionId = this.sessionIdStrategy.createSessionId();
+ findById.changeSessionId(changeSessionId);
this.repository.save(findById).block();
@@ -132,8 +136,10 @@ void changeSessionIdWhenChangeTwice() {
this.repository.save(toSave).block();
String originalId = toSave.getId();
- String changeId1 = toSave.changeSessionId();
- String changeId2 = toSave.changeSessionId();
+ String changeId1 = this.sessionIdStrategy.createSessionId();
+ toSave.changeSessionId(changeId1);
+ String changeId2 = this.sessionIdStrategy.createSessionId();
+ toSave.changeSessionId(changeId2);
this.repository.save(toSave).block();
@@ -156,7 +162,8 @@ void changeSessionIdWhenSetAttributeOnChangedSession() {
findById.setAttribute(attrName, attrValue);
String originalFindById = findById.getId();
- String changeSessionId = findById.changeSessionId();
+ String changeSessionId = this.sessionIdStrategy.createSessionId();
+ findById.changeSessionId(changeSessionId);
this.repository.save(findById).block();
@@ -171,7 +178,7 @@ void changeSessionIdWhenSetAttributeOnChangedSession() {
void changeSessionIdWhenHasNotSaved() {
RedisSession toSave = this.repository.createSession().block();
String originalId = toSave.getId();
- toSave.changeSessionId();
+ toSave.changeSessionId("1");
this.repository.save(toSave).block();
@@ -184,7 +191,7 @@ void changeSessionIdWhenHasNotSaved() {
void changeSessionIdSaveTwice() {
RedisSession toSave = this.repository.createSession().block();
String originalId = toSave.getId();
- toSave.changeSessionId();
+ toSave.changeSessionId("1");
this.repository.save(toSave).block();
this.repository.save(toSave).block();
@@ -202,7 +209,7 @@ void changeSessionSaveOldSessionInstance() {
this.repository.save(toSave).block();
RedisSession session = this.repository.findById(sessionId).block();
- session.changeSessionId();
+ session.changeSessionId("1");
session.setLastAccessedTime(Instant.now());
this.repository.save(session).block();
diff --git a/spring-session-data-redis/src/integration-test/java/org/springframework/session/data/redis/RedisIndexedSessionRepositoryITests.java b/spring-session-data-redis/src/integration-test/java/org/springframework/session/data/redis/RedisIndexedSessionRepositoryITests.java
index a649148f3..acba8860f 100644
--- a/spring-session-data-redis/src/integration-test/java/org/springframework/session/data/redis/RedisIndexedSessionRepositoryITests.java
+++ b/spring-session-data-redis/src/integration-test/java/org/springframework/session/data/redis/RedisIndexedSessionRepositoryITests.java
@@ -36,6 +36,7 @@
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.session.FindByIndexNameSessionRepository;
import org.springframework.session.Session;
+import org.springframework.session.SessionIdStrategy;
import org.springframework.session.data.SessionEventRegistry;
import org.springframework.session.data.redis.RedisIndexedSessionRepository.RedisSession;
import org.springframework.session.data.redis.config.annotation.SpringSessionRedisOperations;
@@ -63,6 +64,8 @@ class RedisIndexedSessionRepositoryITests extends AbstractRedisITests {
private static final String INDEX_NAME = FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME;
+ private final SessionIdStrategy sessionIdStrategy = SessionIdStrategy.getDefault();
+
@Autowired
private RedisIndexedSessionRepository repository;
@@ -487,7 +490,8 @@ void changeSessionIdWhenOnlyChangeId() {
assertThat(findById.getAttribute(attrName)).isEqualTo(attrValue);
String originalFindById = findById.getId();
- String changeSessionId = findById.changeSessionId();
+ String changeSessionId = this.sessionIdStrategy.createSessionId();
+ findById.changeSessionId(changeSessionId);
this.repository.save(findById);
@@ -505,8 +509,10 @@ void changeSessionIdWhenChangeTwice() {
this.repository.save(toSave);
String originalId = toSave.getId();
- String changeId1 = toSave.changeSessionId();
- String changeId2 = toSave.changeSessionId();
+ String changeId1 = this.sessionIdStrategy.createSessionId();
+ toSave.changeSessionId(changeId1);
+ String changeId2 = this.sessionIdStrategy.createSessionId();
+ toSave.changeSessionId(changeId2);
this.repository.save(toSave);
@@ -529,7 +535,8 @@ void changeSessionIdWhenSetAttributeOnChangedSession() {
findById.setAttribute(attrName, attrValue);
String originalFindById = findById.getId();
- String changeSessionId = findById.changeSessionId();
+ String changeSessionId = this.sessionIdStrategy.createSessionId();
+ findById.changeSessionId(changeSessionId);
this.repository.save(findById);
@@ -547,7 +554,7 @@ void changeSessionIdWhenHasNotSaved() {
RedisSession toSave = this.repository.createSession();
String originalId = toSave.getId();
- toSave.changeSessionId();
+ toSave.changeSessionId("1");
this.repository.save(toSave);
@@ -560,7 +567,7 @@ void changeSessionIdWhenHasNotSaved() {
void changeSessionIdSaveTwice() {
RedisSession toSave = this.repository.createSession();
String originalId = toSave.getId();
- toSave.changeSessionId();
+ toSave.changeSessionId("1");
this.repository.save(toSave);
this.repository.save(toSave);
@@ -578,7 +585,7 @@ void changeSessionIdWhenSessionIsDeleted() {
this.repository.deleteById(sessionId);
- toSave.changeSessionId();
+ toSave.changeSessionId("1");
this.repository.save(toSave);
assertThat(this.repository.findById(toSave.getId())).isNull();
@@ -594,9 +601,9 @@ void changeSessionIdSaveConcurrently() {
RedisSession copy1 = this.repository.findById(originalId);
RedisSession copy2 = this.repository.findById(originalId);
- copy1.changeSessionId();
+ copy1.changeSessionId("1");
this.repository.save(copy1);
- copy2.changeSessionId();
+ copy2.changeSessionId("2");
this.repository.save(copy2);
assertThat(this.repository.findById(originalId)).isNull();
diff --git a/spring-session-data-redis/src/integration-test/java/org/springframework/session/data/redis/RedisSessionRepositoryITests.java b/spring-session-data-redis/src/integration-test/java/org/springframework/session/data/redis/RedisSessionRepositoryITests.java
index cc2c0b51b..98ce30d0e 100644
--- a/spring-session-data-redis/src/integration-test/java/org/springframework/session/data/redis/RedisSessionRepositoryITests.java
+++ b/spring-session-data-redis/src/integration-test/java/org/springframework/session/data/redis/RedisSessionRepositoryITests.java
@@ -31,6 +31,7 @@
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.session.MapSession;
+import org.springframework.session.SessionIdStrategy;
import org.springframework.session.config.annotation.web.http.EnableSpringHttpSession;
import org.springframework.session.data.redis.RedisSessionRepository.RedisSession;
import org.springframework.test.context.ContextConfiguration;
@@ -53,6 +54,8 @@ class RedisSessionRepositoryITests extends AbstractRedisITests {
@Autowired
private RedisSessionRepository sessionRepository;
+ private final SessionIdStrategy sessionIdStrategy = SessionIdStrategy.getDefault();
+
@Test
void save_NewSession_ShouldSaveSession() {
RedisSession session = createAndSaveSession(Instant.now());
@@ -98,7 +101,8 @@ void save_ChangeSessionIdAndUpdateAttribute_ShouldChangeSessionId() {
RedisSession session = createAndSaveSession(Instant.now());
String originalSessionId = session.getId();
updateSession(session, Instant.now(), "attribute1", "value2");
- String newSessionId = session.changeSessionId();
+ String newSessionId = this.sessionIdStrategy.createSessionId();
+ session.changeSessionId(newSessionId);
this.sessionRepository.save(session);
RedisSession loaded = this.sessionRepository.findById(newSessionId);
assertThat(loaded).isNotNull();
@@ -111,7 +115,8 @@ void save_ChangeSessionIdAndUpdateAttribute_ShouldChangeSessionId() {
void save_OnlyChangeSessionId_ShouldChangeSessionId() {
RedisSession session = createAndSaveSession(Instant.now());
String originalSessionId = session.getId();
- String newSessionId = session.changeSessionId();
+ String newSessionId = this.sessionIdStrategy.createSessionId();
+ session.changeSessionId(newSessionId);
this.sessionRepository.save(session);
assertThat(this.sessionRepository.findById(newSessionId)).isNotNull();
assertThat(this.sessionRepository.findById(originalSessionId)).isNull();
@@ -122,9 +127,11 @@ void save_ChangeSessionIdTwice_ShouldChangeSessionId() {
RedisSession session = createAndSaveSession(Instant.now());
String originalSessionId = session.getId();
updateSession(session, Instant.now(), "attribute1", "value2");
- String newSessionId1 = session.changeSessionId();
+ String newSessionId1 = this.sessionIdStrategy.createSessionId();
+ session.changeSessionId(newSessionId1);
updateSession(session, Instant.now(), "attribute1", "value3");
- String newSessionId2 = session.changeSessionId();
+ String newSessionId2 = this.sessionIdStrategy.createSessionId();
+ session.changeSessionId(newSessionId2);
this.sessionRepository.save(session);
assertThat(this.sessionRepository.findById(newSessionId1)).isNull();
assertThat(this.sessionRepository.findById(newSessionId2)).isNotNull();
@@ -136,7 +143,8 @@ void save_ChangeSessionIdOnNewSession_ShouldChangeSessionId() {
RedisSession session = this.sessionRepository.createSession();
String originalSessionId = session.getId();
updateSession(session, Instant.now(), "attribute1", "value1");
- String newSessionId = session.changeSessionId();
+ String newSessionId = this.sessionIdStrategy.createSessionId();
+ session.changeSessionId(newSessionId);
this.sessionRepository.save(session);
assertThat(this.sessionRepository.findById(newSessionId)).isNotNull();
assertThat(this.sessionRepository.findById(originalSessionId)).isNull();
@@ -148,7 +156,8 @@ void save_ChangeSessionIdSaveTwice_ShouldChangeSessionId() {
String originalSessionId;
originalSessionId = session.getId();
updateSession(session, Instant.now(), "attribute1", "value1");
- String newSessionId = session.changeSessionId();
+ String newSessionId = this.sessionIdStrategy.createSessionId();
+ session.changeSessionId(newSessionId);
this.sessionRepository.save(session);
this.sessionRepository.save(session);
assertThat(this.sessionRepository.findById(newSessionId)).isNotNull();
@@ -161,7 +170,8 @@ void save_ChangeSessionIdOnDeletedSession_ShouldThrowException() {
String originalSessionId = session.getId();
this.sessionRepository.deleteById(originalSessionId);
updateSession(session, Instant.now(), "attribute1", "value1");
- String newSessionId = session.changeSessionId();
+ String newSessionId = this.sessionIdStrategy.createSessionId();
+ session.changeSessionId(newSessionId);
assertThatIllegalStateException().isThrownBy(() -> this.sessionRepository.save(session))
.withMessage("Session was invalidated");
assertThat(this.sessionRepository.findById(newSessionId)).isNull();
@@ -175,10 +185,12 @@ void save_ChangeSessionIdConcurrent_ShouldThrowException() {
RedisSession copy2 = this.sessionRepository.findById(originalSessionId);
Instant now = Instant.now().truncatedTo(ChronoUnit.MILLIS);
updateSession(copy1, now.plusSeconds(1L), "attribute2", "value2");
- String newSessionId1 = copy1.changeSessionId();
+ String newSessionId1 = this.sessionIdStrategy.createSessionId();
+ copy1.changeSessionId(newSessionId1);
this.sessionRepository.save(copy1);
updateSession(copy2, now.plusSeconds(2L), "attribute3", "value3");
- String newSessionId2 = copy2.changeSessionId();
+ String newSessionId2 = this.sessionIdStrategy.createSessionId();
+ copy2.changeSessionId(newSessionId2);
assertThatIllegalStateException().isThrownBy(() -> this.sessionRepository.save(copy2))
.withMessage("Session was invalidated");
assertThat(this.sessionRepository.findById(newSessionId1)).isNotNull();
diff --git a/spring-session-data-redis/src/main/java/org/springframework/session/data/redis/ReactiveRedisSessionRepository.java b/spring-session-data-redis/src/main/java/org/springframework/session/data/redis/ReactiveRedisSessionRepository.java
index 81e808243..9c07c9207 100644
--- a/spring-session-data-redis/src/main/java/org/springframework/session/data/redis/ReactiveRedisSessionRepository.java
+++ b/spring-session-data-redis/src/main/java/org/springframework/session/data/redis/ReactiveRedisSessionRepository.java
@@ -30,6 +30,7 @@
import org.springframework.session.ReactiveSessionRepository;
import org.springframework.session.SaveMode;
import org.springframework.session.Session;
+import org.springframework.session.SessionIdStrategy;
import org.springframework.util.Assert;
/**
@@ -37,6 +38,7 @@
* {@link ReactiveRedisOperations}.
*
* @author Vedran Pavic
+ * @author Jakub Maciej
* @since 2.2.0
*/
public class ReactiveRedisSessionRepository
@@ -49,6 +51,8 @@ public class ReactiveRedisSessionRepository
private final ReactiveRedisOperations sessionRedisOperations;
+ private SessionIdStrategy sessionIdStrategy = SessionIdStrategy.getDefault();
+
/**
* The namespace for every key used by Spring Session in Redis.
*/
@@ -108,7 +112,7 @@ public ReactiveRedisOperations getSessionRedisOperations() {
@Override
public Mono createSession() {
return Mono.defer(() -> {
- MapSession cached = new MapSession();
+ MapSession cached = new MapSession(this.sessionIdStrategy.createSessionId());
if (this.defaultMaxInactiveInterval != null) {
cached.setMaxInactiveInterval(Duration.ofSeconds(this.defaultMaxInactiveInterval));
}
@@ -157,6 +161,16 @@ private String getSessionKey(String sessionId) {
return this.namespace + "sessions:" + sessionId;
}
+ /**
+ * Allows override of default session id generation strategy.
+ * @param sessionIdStrategy session id generation strategy to be used with this
+ * repository
+ */
+ public void setSessionIdStrategy(final SessionIdStrategy sessionIdStrategy) {
+ Assert.notNull(sessionIdStrategy, "sessionIdStrategy must not be null");
+ this.sessionIdStrategy = sessionIdStrategy;
+ }
+
/**
* A custom implementation of {@link Session} that uses a {@link MapSession} as the
* basis for its mapping. It keeps track of any attributes that have changed. When
@@ -195,8 +209,8 @@ public String getId() {
}
@Override
- public String changeSessionId() {
- return this.cached.changeSessionId();
+ public void changeSessionId(final String id) {
+ this.cached.changeSessionId(id);
}
@Override
diff --git a/spring-session-data-redis/src/main/java/org/springframework/session/data/redis/RedisIndexedSessionRepository.java b/spring-session-data-redis/src/main/java/org/springframework/session/data/redis/RedisIndexedSessionRepository.java
index 46442683e..de1833e93 100644
--- a/spring-session-data-redis/src/main/java/org/springframework/session/data/redis/RedisIndexedSessionRepository.java
+++ b/spring-session-data-redis/src/main/java/org/springframework/session/data/redis/RedisIndexedSessionRepository.java
@@ -44,6 +44,7 @@
import org.springframework.session.PrincipalNameIndexResolver;
import org.springframework.session.SaveMode;
import org.springframework.session.Session;
+import org.springframework.session.SessionIdStrategy;
import org.springframework.session.events.SessionCreatedEvent;
import org.springframework.session.events.SessionDeletedEvent;
import org.springframework.session.events.SessionDestroyedEvent;
@@ -244,6 +245,7 @@
*
* @author Rob Winch
* @author Vedran Pavic
+ * @author Jakub Maciej
* @since 2.2.0
*/
public class RedisIndexedSessionRepository
@@ -263,6 +265,8 @@ public class RedisIndexedSessionRepository
*/
public static final String DEFAULT_NAMESPACE = "spring:session";
+ private SessionIdStrategy sessionIdStrategy = SessionIdStrategy.getDefault();
+
private int database = DEFAULT_DATABASE;
/**
@@ -487,9 +491,16 @@ public void deleteById(String sessionId) {
save(session);
}
+ @Override
+ public String changeSessionId(final RedisSession session) {
+ String newId = this.sessionIdStrategy.createSessionId();
+ session.changeSessionId(newId);
+ return newId;
+ }
+
@Override
public RedisSession createSession() {
- MapSession cached = new MapSession();
+ MapSession cached = new MapSession(this.sessionIdStrategy.createSessionId());
if (this.defaultMaxInactiveInterval != null) {
cached.setMaxInactiveInterval(Duration.ofSeconds(this.defaultMaxInactiveInterval));
}
@@ -659,6 +670,16 @@ static String getSessionAttrNameKey(String attributeName) {
return RedisSessionMapper.ATTRIBUTE_PREFIX + attributeName;
}
+ /**
+ * Allows override of default session id generation strategy.
+ * @param sessionIdStrategy session id generation strategy to be used with this
+ * repository
+ */
+ public void setSessionIdStrategy(final SessionIdStrategy sessionIdStrategy) {
+ Assert.notNull(sessionIdStrategy, "sessionIdStrategy must not be null");
+ this.sessionIdStrategy = sessionIdStrategy;
+ }
+
/**
* A custom implementation of {@link Session} that uses a {@link MapSession} as the
* basis for its mapping. It keeps track of any attributes that have changed. When
@@ -722,8 +743,8 @@ public String getId() {
}
@Override
- public String changeSessionId() {
- return this.cached.changeSessionId();
+ public void changeSessionId(final String id) {
+ this.cached.changeSessionId(id);
}
@Override
diff --git a/spring-session-data-redis/src/main/java/org/springframework/session/data/redis/RedisSessionRepository.java b/spring-session-data-redis/src/main/java/org/springframework/session/data/redis/RedisSessionRepository.java
index cdbb52c9d..14ddf1ef8 100644
--- a/spring-session-data-redis/src/main/java/org/springframework/session/data/redis/RedisSessionRepository.java
+++ b/spring-session-data-redis/src/main/java/org/springframework/session/data/redis/RedisSessionRepository.java
@@ -28,6 +28,7 @@
import org.springframework.session.MapSession;
import org.springframework.session.SaveMode;
import org.springframework.session.Session;
+import org.springframework.session.SessionIdStrategy;
import org.springframework.session.SessionRepository;
import org.springframework.util.Assert;
@@ -38,6 +39,7 @@
* This implementation does not support publishing of session events.
*
* @author Vedran Pavic
+ * @author Jakub Maciej
* @since 2.2.0
*/
public class RedisSessionRepository implements SessionRepository {
@@ -46,6 +48,8 @@ public class RedisSessionRepository implements SessionRepository sessionRedisOperations;
+ private SessionIdStrategy sessionIdStrategy = SessionIdStrategy.getDefault();
+
private Duration defaultMaxInactiveInterval = Duration.ofSeconds(MapSession.DEFAULT_MAX_INACTIVE_INTERVAL_SECONDS);
private String keyNamespace = DEFAULT_KEY_NAMESPACE;
@@ -102,7 +106,7 @@ public void setSaveMode(SaveMode saveMode) {
@Override
public RedisSession createSession() {
- MapSession cached = new MapSession();
+ MapSession cached = new MapSession(this.sessionIdStrategy.createSessionId());
cached.setMaxInactiveInterval(this.defaultMaxInactiveInterval);
RedisSession session = new RedisSession(cached, true);
session.flushIfRequired();
@@ -142,6 +146,11 @@ public void deleteById(String sessionId) {
this.sessionRedisOperations.delete(key);
}
+ @Override
+ public String changeSessionId(final RedisSession session) {
+ return null;
+ }
+
/**
* Returns the {@link RedisOperations} used for sessions.
* @return the {@link RedisOperations} used for sessions
@@ -158,6 +167,16 @@ private static String getAttributeKey(String attributeName) {
return RedisSessionMapper.ATTRIBUTE_PREFIX + attributeName;
}
+ /**
+ * Allows override of default session id generation strategy.
+ * @param sessionIdStrategy session id generation strategy to be used with this
+ * repository
+ */
+ public void setSessionIdStrategy(final SessionIdStrategy sessionIdStrategy) {
+ Assert.notNull(sessionIdStrategy, "sessionIdStrategy must not be null");
+ this.sessionIdStrategy = sessionIdStrategy;
+ }
+
/**
* An internal {@link Session} implementation used by this {@link SessionRepository}.
*/
@@ -193,8 +212,8 @@ public String getId() {
}
@Override
- public String changeSessionId() {
- return this.cached.changeSessionId();
+ public void changeSessionId(final String id) {
+ this.cached.changeSessionId(id);
}
@Override
diff --git a/spring-session-data-redis/src/test/java/org/springframework/session/data/redis/ReactiveRedisSessionRepositoryTests.java b/spring-session-data-redis/src/test/java/org/springframework/session/data/redis/ReactiveRedisSessionRepositoryTests.java
index da58aadf9..de1fee8aa 100644
--- a/spring-session-data-redis/src/test/java/org/springframework/session/data/redis/ReactiveRedisSessionRepositoryTests.java
+++ b/spring-session-data-redis/src/test/java/org/springframework/session/data/redis/ReactiveRedisSessionRepositoryTests.java
@@ -69,7 +69,7 @@ class ReactiveRedisSessionRepositoryTests {
void setUp() {
this.repository = new ReactiveRedisSessionRepository(this.redisOperations);
- this.cached = new MapSession();
+ this.cached = new MapSession("1");
this.cached.setId("session-id");
this.cached.setCreationTime(Instant.ofEpochMilli(1404360000000L));
this.cached.setLastAccessedTime(Instant.ofEpochMilli(1404360000000L));
@@ -131,7 +131,7 @@ void saveNewSession() {
given(this.hashOperations.putAll(anyString(), any())).willReturn(Mono.just(true));
given(this.redisOperations.expire(anyString(), any())).willReturn(Mono.just(true));
- RedisSession newSession = this.repository.new RedisSession(new MapSession(), true);
+ RedisSession newSession = this.repository.new RedisSession(new MapSession("1"), true);
StepVerifier.create(this.repository.save(newSession)).verifyComplete();
verify(this.redisOperations).opsForHash();
@@ -217,7 +217,7 @@ void saveRemoveAttribute() {
given(this.redisOperations.expire(anyString(), any())).willReturn(Mono.just(true));
String attrName = "attrName";
- RedisSession session = this.repository.new RedisSession(new MapSession(), false);
+ RedisSession session = this.repository.new RedisSession(new MapSession("1"), false);
session.removeAttribute(attrName);
StepVerifier.create(this.repository.save(session)).verifyComplete();
@@ -344,7 +344,7 @@ void saveWithSaveModeOnSetAttribute() {
given(this.hashOperations.putAll(anyString(), any())).willReturn(Mono.just(true));
given(this.redisOperations.expire(anyString(), any())).willReturn(Mono.just(true));
this.repository.setSaveMode(SaveMode.ON_SET_ATTRIBUTE);
- MapSession delegate = new MapSession();
+ MapSession delegate = new MapSession("1");
delegate.setAttribute("attribute1", "value1");
delegate.setAttribute("attribute2", "value2");
delegate.setAttribute("attribute3", "value3");
@@ -368,7 +368,7 @@ void saveWithSaveModeOnGetAttribute() {
given(this.hashOperations.putAll(anyString(), any())).willReturn(Mono.just(true));
given(this.redisOperations.expire(anyString(), any())).willReturn(Mono.just(true));
this.repository.setSaveMode(SaveMode.ON_GET_ATTRIBUTE);
- MapSession delegate = new MapSession();
+ MapSession delegate = new MapSession("1");
delegate.setAttribute("attribute1", "value1");
delegate.setAttribute("attribute2", "value2");
delegate.setAttribute("attribute3", "value3");
@@ -392,7 +392,7 @@ void saveWithSaveModeAlways() {
given(this.hashOperations.putAll(anyString(), any())).willReturn(Mono.just(true));
given(this.redisOperations.expire(anyString(), any())).willReturn(Mono.just(true));
this.repository.setSaveMode(SaveMode.ALWAYS);
- MapSession delegate = new MapSession();
+ MapSession delegate = new MapSession("1");
delegate.setAttribute("attribute1", "value1");
delegate.setAttribute("attribute2", "value2");
delegate.setAttribute("attribute3", "value3");
diff --git a/spring-session-data-redis/src/test/java/org/springframework/session/data/redis/RedisIndexedSessionRepositoryTests.java b/spring-session-data-redis/src/test/java/org/springframework/session/data/redis/RedisIndexedSessionRepositoryTests.java
index 658c8a456..89b168dc0 100644
--- a/spring-session-data-redis/src/test/java/org/springframework/session/data/redis/RedisIndexedSessionRepositoryTests.java
+++ b/spring-session-data-redis/src/test/java/org/springframework/session/data/redis/RedisIndexedSessionRepositoryTests.java
@@ -48,6 +48,7 @@
import org.springframework.session.MapSession;
import org.springframework.session.SaveMode;
import org.springframework.session.Session;
+import org.springframework.session.SessionIdStrategy;
import org.springframework.session.data.redis.RedisIndexedSessionRepository.RedisSession;
import org.springframework.session.events.AbstractSessionEvent;
@@ -67,6 +68,8 @@
class RedisIndexedSessionRepositoryTests {
+ private final SessionIdStrategy sessionIdStrategy = SessionIdStrategy.getDefault();
+
@Mock
private RedisOperations