Rename SessionIdGenerationStrategy to SessionIdGenerator

Closes gh-2391
This commit is contained in:
Marcus Da Coregio
2023-08-03 13:44:42 -03:00
parent b2615c2010
commit 2d4233fcfd
38 changed files with 269 additions and 286 deletions

View File

@@ -74,8 +74,7 @@ public final class MapSession implements Session, Serializable {
*/
private Duration maxInactiveInterval = DEFAULT_MAX_INACTIVE_INTERVAL;
private transient SessionIdGenerationStrategy sessionIdGenerationStrategy = UuidSessionIdGenerationStrategy
.getInstance();
private transient SessionIdGenerator sessionIdGenerator = UuidSessionIdGenerator.getInstance();
/**
* Creates a new instance with a secure randomly generated identifier.
@@ -85,14 +84,14 @@ public final class MapSession implements Session, Serializable {
}
/**
* Creates a new instance using the specified {@link SessionIdGenerationStrategy} to
* generate the session id.
* @param sessionIdGenerationStrategy the {@link SessionIdGenerationStrategy} to use.
* Creates a new instance using the specified {@link SessionIdGenerator} to generate
* the session id.
* @param sessionIdGenerator the {@link SessionIdGenerator} to use.
* @since 3.2
*/
public MapSession(SessionIdGenerationStrategy sessionIdGenerationStrategy) {
this(sessionIdGenerationStrategy.generate());
this.sessionIdGenerationStrategy = sessionIdGenerationStrategy;
public MapSession(SessionIdGenerator sessionIdGenerator) {
this(sessionIdGenerator.generate());
this.sessionIdGenerator = sessionIdGenerator;
}
/**
@@ -155,7 +154,7 @@ public final class MapSession implements Session, Serializable {
@Override
public String changeSessionId() {
String changedId = this.sessionIdGenerationStrategy.generate();
String changedId = this.sessionIdGenerator.generate();
setId(changedId);
return changedId;
}
@@ -247,13 +246,12 @@ public final class MapSession implements Session, Serializable {
}
/**
* Sets the {@link SessionIdGenerationStrategy} to use when generating a new session
* id.
* @param sessionIdGenerationStrategy the {@link SessionIdGenerationStrategy} to use.
* Sets the {@link SessionIdGenerator} to use when generating a new session id.
* @param sessionIdGenerator the {@link SessionIdGenerator} to use.
* @since 3.2
*/
public void setSessionIdGenerationStrategy(SessionIdGenerationStrategy sessionIdGenerationStrategy) {
this.sessionIdGenerationStrategy = sessionIdGenerationStrategy;
public void setSessionIdGenerator(SessionIdGenerator sessionIdGenerator) {
this.sessionIdGenerator = sessionIdGenerator;
}
private static final long serialVersionUID = 7160779239673823561L;

View File

@@ -43,7 +43,7 @@ public class MapSessionRepository implements SessionRepository<MapSession> {
private final Map<String, Session> sessions;
private SessionIdGenerationStrategy sessionIdGenerationStrategy = UuidSessionIdGenerationStrategy.getInstance();
private SessionIdGenerator sessionIdGenerator = UuidSessionIdGenerator.getInstance();
/**
* Creates a new instance backed by the provided {@link java.util.Map}. This allows
@@ -74,7 +74,7 @@ public class MapSessionRepository implements SessionRepository<MapSession> {
this.sessions.remove(session.getOriginalId());
}
MapSession saved = new MapSession(session);
saved.setSessionIdGenerationStrategy(this.sessionIdGenerationStrategy);
saved.setSessionIdGenerator(this.sessionIdGenerator);
this.sessions.put(session.getId(), saved);
}
@@ -89,7 +89,7 @@ public class MapSessionRepository implements SessionRepository<MapSession> {
return null;
}
MapSession result = new MapSession(saved);
result.setSessionIdGenerationStrategy(this.sessionIdGenerationStrategy);
result.setSessionIdGenerator(this.sessionIdGenerator);
return result;
}
@@ -100,14 +100,14 @@ public class MapSessionRepository implements SessionRepository<MapSession> {
@Override
public MapSession createSession() {
MapSession result = new MapSession(this.sessionIdGenerationStrategy);
MapSession result = new MapSession(this.sessionIdGenerator);
result.setMaxInactiveInterval(this.defaultMaxInactiveInterval);
return result;
}
public void setSessionIdGenerationStrategy(SessionIdGenerationStrategy sessionIdGenerationStrategy) {
Assert.notNull(sessionIdGenerationStrategy, "sessionIdGenerationStrategy cannot be null");
this.sessionIdGenerationStrategy = sessionIdGenerationStrategy;
public void setSessionIdGenerator(SessionIdGenerator sessionIdGenerator) {
Assert.notNull(sessionIdGenerator, "sessionIdGenerator cannot be null");
this.sessionIdGenerator = sessionIdGenerator;
}
}

View File

@@ -45,7 +45,7 @@ public class ReactiveMapSessionRepository implements ReactiveSessionRepository<M
private final Map<String, Session> sessions;
private SessionIdGenerationStrategy sessionIdGenerationStrategy = UuidSessionIdGenerationStrategy.getInstance();
private SessionIdGenerator sessionIdGenerator = UuidSessionIdGenerator.getInstance();
/**
* Creates a new instance backed by the provided {@link Map}. This allows injecting a
@@ -86,7 +86,7 @@ public class ReactiveMapSessionRepository implements ReactiveSessionRepository<M
return Mono.defer(() -> Mono.justOrEmpty(this.sessions.get(id))
.filter((session) -> !session.isExpired())
.map(MapSession::new)
.doOnNext((session) -> session.setSessionIdGenerationStrategy(this.sessionIdGenerationStrategy))
.doOnNext((session) -> session.setSessionIdGenerator(this.sessionIdGenerator))
.switchIfEmpty(deleteById(id).then(Mono.empty())));
// @formatter:on
}
@@ -99,21 +99,20 @@ public class ReactiveMapSessionRepository implements ReactiveSessionRepository<M
@Override
public Mono<MapSession> createSession() {
return Mono.defer(() -> {
MapSession result = new MapSession(this.sessionIdGenerationStrategy);
MapSession result = new MapSession(this.sessionIdGenerator);
result.setMaxInactiveInterval(this.defaultMaxInactiveInterval);
return Mono.just(result);
});
}
/**
* Sets the {@link SessionIdGenerationStrategy} to use.
* @param sessionIdGenerationStrategy the non-null {@link SessionIdGenerationStrategy}
* to use
* Sets the {@link SessionIdGenerator} to use.
* @param sessionIdGenerator the non-null {@link SessionIdGenerator} to use
* @since 3.2
*/
public void setSessionIdGenerationStrategy(SessionIdGenerationStrategy sessionIdGenerationStrategy) {
Assert.notNull(sessionIdGenerationStrategy, "sessionIdGenerationStrategy cannot be null");
this.sessionIdGenerationStrategy = sessionIdGenerationStrategy;
public void setSessionIdGenerator(SessionIdGenerator sessionIdGenerator) {
Assert.notNull(sessionIdGenerator, "sessionIdGenerator cannot be null");
this.sessionIdGenerator = sessionIdGenerator;
}
}

View File

@@ -24,7 +24,7 @@ import org.springframework.lang.NonNull;
* @author Marcus da Coregio
* @since 3.2
*/
public interface SessionIdGenerationStrategy {
public interface SessionIdGenerator {
@NonNull
String generate();

View File

@@ -21,17 +21,16 @@ import java.util.UUID;
import org.springframework.lang.NonNull;
/**
* A {@link SessionIdGenerationStrategy} that generates a random UUID to be used as the
* session id.
* A {@link SessionIdGenerator} that generates a random UUID to be used as the session id.
*
* @author Marcus da Coregio
* @since 3.2
*/
public final class UuidSessionIdGenerationStrategy implements SessionIdGenerationStrategy {
public final class UuidSessionIdGenerator implements SessionIdGenerator {
private static final UuidSessionIdGenerationStrategy INSTANCE = new UuidSessionIdGenerationStrategy();
private static final UuidSessionIdGenerator INSTANCE = new UuidSessionIdGenerator();
private UuidSessionIdGenerationStrategy() {
private UuidSessionIdGenerator() {
}
@Override
@@ -41,10 +40,10 @@ public final class UuidSessionIdGenerationStrategy implements SessionIdGeneratio
}
/**
* Returns the singleton instance of {@link UuidSessionIdGenerationStrategy}.
* @return the singleton instance of {@link UuidSessionIdGenerationStrategy}
* Returns the singleton instance of {@link UuidSessionIdGenerator}.
* @return the singleton instance of {@link UuidSessionIdGenerator}
*/
public static UuidSessionIdGenerationStrategy getInstance() {
public static UuidSessionIdGenerator getInstance() {
return INSTANCE;
}

View File

@@ -45,7 +45,7 @@ class MapSessionTests {
@Test
void constructorWhenSessionIdGenerationStrategyThenUsesStrategy() {
MapSession session = new MapSession(new FixedSessionIdGenerationStrategy("my-id"));
MapSession session = new MapSession(new FixedSessionIdGenerator("my-id"));
assertThat(session.getId()).isEqualTo("my-id");
}
@@ -159,18 +159,18 @@ class MapSessionTests {
@Test
void changeSessionIdWhenSessionIdStrategyThenUsesStrategy() {
MapSession session = new MapSession(new IncrementalSessionIdGenerationStrategy());
MapSession session = new MapSession(new IncrementalSessionIdGenerator());
String idBeforeChange = session.getId();
String idAfterChange = session.changeSessionId();
assertThat(idBeforeChange).isEqualTo("1");
assertThat(idAfterChange).isEqualTo("2");
}
static class FixedSessionIdGenerationStrategy implements SessionIdGenerationStrategy {
static class FixedSessionIdGenerator implements SessionIdGenerator {
private final String id;
FixedSessionIdGenerationStrategy(String id) {
FixedSessionIdGenerator(String id) {
this.id = id;
}
@@ -181,7 +181,7 @@ class MapSessionTests {
}
static class IncrementalSessionIdGenerationStrategy implements SessionIdGenerationStrategy {
static class IncrementalSessionIdGenerator implements SessionIdGenerator {
private int counter = 1;

View File

@@ -154,7 +154,7 @@ class ReactiveMapSessionRepositoryTests {
@Test
void createSessionWhenSessionIdGenerationStrategyThenUses() {
this.repository.setSessionIdGenerationStrategy(() -> "test");
this.repository.setSessionIdGenerator(() -> "test");
MapSession session = this.repository.createSession().block();
assertThat(session.getId()).isEqualTo("test");
assertThat(session.changeSessionId()).isEqualTo("test");
@@ -162,13 +162,13 @@ class ReactiveMapSessionRepositoryTests {
@Test
void setSessionIdGenerationStrategyWhenNullThenThrowsException() {
assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setSessionIdGenerationStrategy(null))
.withMessage("sessionIdGenerationStrategy cannot be null");
assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setSessionIdGenerator(null))
.withMessage("sessionIdGenerator cannot be null");
}
@Test
void findByIdWhenChangeSessionIdThenUsesSessionIdGenerationStrategy() {
this.repository.setSessionIdGenerationStrategy(() -> "test");
this.repository.setSessionIdGenerator(() -> "test");
MapSession session = this.repository.createSession().block();
this.repository.save(session).block();

View File

@@ -36,8 +36,8 @@ import org.springframework.data.mongodb.core.index.IndexOperations;
import org.springframework.lang.Nullable;
import org.springframework.session.FindByIndexNameSessionRepository;
import org.springframework.session.MapSession;
import org.springframework.session.SessionIdGenerationStrategy;
import org.springframework.session.UuidSessionIdGenerationStrategy;
import org.springframework.session.SessionIdGenerator;
import org.springframework.session.UuidSessionIdGenerator;
import org.springframework.session.events.SessionCreatedEvent;
import org.springframework.session.events.SessionDeletedEvent;
import org.springframework.session.events.SessionExpiredEvent;
@@ -83,7 +83,7 @@ public class MongoIndexedSessionRepository
private ApplicationEventPublisher eventPublisher;
private SessionIdGenerationStrategy sessionIdGenerationStrategy = UuidSessionIdGenerationStrategy.getInstance();
private SessionIdGenerator sessionIdGenerator = UuidSessionIdGenerator.getInstance();
public MongoIndexedSessionRepository(MongoOperations mongoOperations) {
this.mongoOperations = mongoOperations;
@@ -92,7 +92,7 @@ public class MongoIndexedSessionRepository
@Override
public MongoSession createSession() {
MongoSession session = new MongoSession(this.sessionIdGenerationStrategy);
MongoSession session = new MongoSession(this.sessionIdGenerator);
session.setMaxInactiveInterval(this.defaultMaxInactiveInterval);
@@ -126,7 +126,7 @@ public class MongoIndexedSessionRepository
deleteById(id);
return null;
}
session.setSessionIdGenerationStrategy(this.sessionIdGenerationStrategy);
session.setSessionIdGenerator(this.sessionIdGenerator);
}
return session;
@@ -147,7 +147,7 @@ public class MongoIndexedSessionRepository
.map((query) -> this.mongoOperations.find(query, Document.class, this.collectionName))
.orElse(Collections.emptyList()).stream()
.map((dbSession) -> MongoSessionUtils.convertToSession(this.mongoSessionConverter, dbSession))
.peek((session) -> session.setSessionIdGenerationStrategy(this.sessionIdGenerationStrategy))
.peek((session) -> session.setSessionIdGenerator(this.sessionIdGenerator))
.collect(Collectors.toMap(MongoSession::getId, (mapSession) -> mapSession));
}
@@ -225,13 +225,13 @@ public class MongoIndexedSessionRepository
}
/**
* Set the {@link SessionIdGenerationStrategy} to use to generate session ids.
* @param sessionIdGenerationStrategy the {@link SessionIdGenerationStrategy} to use
* Set the {@link SessionIdGenerator} to use to generate session ids.
* @param sessionIdGenerator the {@link SessionIdGenerator} to use
* @since 3.2
*/
public void setSessionIdGenerationStrategy(SessionIdGenerationStrategy sessionIdGenerationStrategy) {
Assert.notNull(sessionIdGenerationStrategy, "sessionIdGenerationStrategy cannot be null");
this.sessionIdGenerationStrategy = sessionIdGenerationStrategy;
public void setSessionIdGenerator(SessionIdGenerator sessionIdGenerator) {
Assert.notNull(sessionIdGenerator, "sessionIdGenerator cannot be null");
this.sessionIdGenerator = sessionIdGenerator;
}
}

View File

@@ -28,8 +28,8 @@ import java.util.stream.Collectors;
import org.springframework.lang.Nullable;
import org.springframework.session.MapSession;
import org.springframework.session.Session;
import org.springframework.session.SessionIdGenerationStrategy;
import org.springframework.session.UuidSessionIdGenerationStrategy;
import org.springframework.session.SessionIdGenerator;
import org.springframework.session.UuidSessionIdGenerator;
import org.springframework.util.Assert;
/**
@@ -68,8 +68,7 @@ class MongoSession implements Session {
private Map<String, Object> attrs = new HashMap<>();
private transient SessionIdGenerationStrategy sessionIdGenerationStrategy = UuidSessionIdGenerationStrategy
.getInstance();
private transient SessionIdGenerator sessionIdGenerator = UuidSessionIdGenerator.getInstance();
/**
* Constructs a new instance using the provided session id.
@@ -85,7 +84,7 @@ class MongoSession implements Session {
}
MongoSession(long maxInactiveIntervalInSeconds) {
this(UuidSessionIdGenerationStrategy.getInstance().generate(), maxInactiveIntervalInSeconds);
this(UuidSessionIdGenerator.getInstance().generate(), maxInactiveIntervalInSeconds);
}
MongoSession(String id, long maxInactiveIntervalInSeconds) {
@@ -97,25 +96,25 @@ class MongoSession implements Session {
}
/**
* Constructs a new instance using the provided {@link SessionIdGenerationStrategy}.
* @param sessionIdGenerationStrategy the {@link SessionIdGenerationStrategy} to use
* Constructs a new instance using the provided {@link SessionIdGenerator}.
* @param sessionIdGenerator the {@link SessionIdGenerator} to use
* @since 3.2
*/
MongoSession(SessionIdGenerationStrategy sessionIdGenerationStrategy) {
this(sessionIdGenerationStrategy.generate(), MapSession.DEFAULT_MAX_INACTIVE_INTERVAL_SECONDS);
this.sessionIdGenerationStrategy = sessionIdGenerationStrategy;
MongoSession(SessionIdGenerator sessionIdGenerator) {
this(sessionIdGenerator.generate(), MapSession.DEFAULT_MAX_INACTIVE_INTERVAL_SECONDS);
this.sessionIdGenerator = sessionIdGenerator;
}
/**
* Constructs a new instance using the provided {@link SessionIdGenerationStrategy}
* and max inactive interval.
* @param sessionIdGenerationStrategy the {@link SessionIdGenerationStrategy} to use
* Constructs a new instance using the provided {@link SessionIdGenerator} and max
* inactive interval.
* @param sessionIdGenerator the {@link SessionIdGenerator} to use
* @param maxInactiveIntervalInSeconds the max inactive interval in seconds
* @since 3.2
*/
MongoSession(SessionIdGenerationStrategy sessionIdGenerationStrategy, long maxInactiveIntervalInSeconds) {
this(sessionIdGenerationStrategy.generate(), maxInactiveIntervalInSeconds);
this.sessionIdGenerationStrategy = sessionIdGenerationStrategy;
MongoSession(SessionIdGenerator sessionIdGenerator, long maxInactiveIntervalInSeconds) {
this(sessionIdGenerator.generate(), maxInactiveIntervalInSeconds);
this.sessionIdGenerator = sessionIdGenerator;
}
static String coverDot(String attributeName) {
@@ -129,7 +128,7 @@ class MongoSession implements Session {
@Override
public String changeSessionId() {
String changedId = this.sessionIdGenerationStrategy.generate();
String changedId = this.sessionIdGenerator.generate();
this.id = changedId;
return changedId;
}
@@ -245,13 +244,13 @@ class MongoSession implements Session {
}
/**
* Sets the {@link SessionIdGenerationStrategy} to use.
* @param sessionIdGenerationStrategy the {@link SessionIdGenerationStrategy} to use
* Sets the {@link SessionIdGenerator} to use.
* @param sessionIdGenerator the {@link SessionIdGenerator} to use
* @since 3.2
*/
void setSessionIdGenerationStrategy(SessionIdGenerationStrategy sessionIdGenerationStrategy) {
Assert.notNull(sessionIdGenerationStrategy, "sessionIdGenerationStrategy cannot be null");
this.sessionIdGenerationStrategy = sessionIdGenerationStrategy;
void setSessionIdGenerator(SessionIdGenerator sessionIdGenerator) {
Assert.notNull(sessionIdGenerator, "sessionIdGenerator cannot be null");
this.sessionIdGenerator = sessionIdGenerator;
}
}

View File

@@ -35,8 +35,8 @@ import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.session.MapSession;
import org.springframework.session.ReactiveSessionRepository;
import org.springframework.session.SessionIdGenerationStrategy;
import org.springframework.session.UuidSessionIdGenerationStrategy;
import org.springframework.session.SessionIdGenerator;
import org.springframework.session.UuidSessionIdGenerator;
import org.springframework.session.events.SessionCreatedEvent;
import org.springframework.session.events.SessionDeletedEvent;
import org.springframework.util.Assert;
@@ -79,7 +79,7 @@ public class ReactiveMongoSessionRepository
private ApplicationEventPublisher eventPublisher;
private SessionIdGenerationStrategy sessionIdGenerationStrategy = UuidSessionIdGenerationStrategy.getInstance();
private SessionIdGenerator sessionIdGenerator = UuidSessionIdGenerator.getInstance();
public ReactiveMongoSessionRepository(ReactiveMongoOperations mongoOperations) {
this.mongoOperations = mongoOperations;
@@ -99,13 +99,13 @@ public class ReactiveMongoSessionRepository
@Override
public Mono<MongoSession> createSession() {
// @formatter:off
return Mono.fromSupplier(() -> this.sessionIdGenerationStrategy.generate())
return Mono.fromSupplier(() -> this.sessionIdGenerator.generate())
.map(MongoSession::new)
.doOnNext((mongoSession) -> mongoSession.setMaxInactiveInterval(this.defaultMaxInactiveInterval))
.doOnNext(
(mongoSession) -> mongoSession.setSessionIdGenerationStrategy(this.sessionIdGenerationStrategy))
(mongoSession) -> mongoSession.setSessionIdGenerator(this.sessionIdGenerator))
.doOnNext((mongoSession) -> publishEvent(new SessionCreatedEvent(this, mongoSession)))
.switchIfEmpty(Mono.just(new MongoSession(this.sessionIdGenerationStrategy)))
.switchIfEmpty(Mono.just(new MongoSession(this.sessionIdGenerator)))
.subscribeOn(Schedulers.boundedElastic())
.publishOn(Schedulers.parallel());
// @formatter:on
@@ -138,8 +138,7 @@ public class ReactiveMongoSessionRepository
return findSession(id) //
.map((document) -> MongoSessionUtils.convertToSession(this.mongoSessionConverter, document)) //
.filter((mongoSession) -> !mongoSession.isExpired()) //
.doOnNext(
(mongoSession) -> mongoSession.setSessionIdGenerationStrategy(this.sessionIdGenerationStrategy))
.doOnNext((mongoSession) -> mongoSession.setSessionIdGenerator(this.sessionIdGenerator))
.switchIfEmpty(Mono.defer(() -> this.deleteById(id).then(Mono.empty())));
}
@@ -229,9 +228,9 @@ public class ReactiveMongoSessionRepository
this.blockingMongoOperations = blockingMongoOperations;
}
public void setSessionIdGenerationStrategy(SessionIdGenerationStrategy sessionIdGenerationStrategy) {
Assert.notNull(sessionIdGenerationStrategy, "sessionIdGenerationStrategy cannot be null");
this.sessionIdGenerationStrategy = sessionIdGenerationStrategy;
public void setSessionIdGenerator(SessionIdGenerator sessionIdGenerator) {
Assert.notNull(sessionIdGenerator, "sessionIdGenerator cannot be null");
this.sessionIdGenerator = sessionIdGenerator;
}
}

View File

@@ -36,8 +36,8 @@ import org.springframework.data.mongodb.core.MongoOperations;
import org.springframework.session.IndexResolver;
import org.springframework.session.MapSession;
import org.springframework.session.Session;
import org.springframework.session.SessionIdGenerationStrategy;
import org.springframework.session.UuidSessionIdGenerationStrategy;
import org.springframework.session.SessionIdGenerator;
import org.springframework.session.UuidSessionIdGenerator;
import org.springframework.session.config.SessionRepositoryCustomizer;
import org.springframework.session.config.annotation.web.http.SpringHttpSessionConfiguration;
import org.springframework.session.data.mongo.AbstractMongoSessionConverter;
@@ -72,7 +72,7 @@ public class MongoHttpSessionConfiguration implements BeanClassLoaderAware, Embe
private IndexResolver<Session> indexResolver;
private SessionIdGenerationStrategy sessionIdGenerationStrategy = UuidSessionIdGenerationStrategy.getInstance();
private SessionIdGenerator sessionIdGenerator = UuidSessionIdGenerator.getInstance();
@Bean
public MongoIndexedSessionRepository mongoSessionRepository(MongoOperations mongoOperations) {
@@ -102,7 +102,7 @@ public class MongoHttpSessionConfiguration implements BeanClassLoaderAware, Embe
if (StringUtils.hasText(this.collectionName)) {
repository.setCollectionName(this.collectionName);
}
repository.setSessionIdGenerationStrategy(this.sessionIdGenerationStrategy);
repository.setSessionIdGenerator(this.sessionIdGenerator);
this.sessionRepositoryCustomizers
.forEach((sessionRepositoryCustomizer) -> sessionRepositoryCustomizer.customize(repository));
@@ -166,8 +166,8 @@ public class MongoHttpSessionConfiguration implements BeanClassLoaderAware, Embe
}
@Autowired(required = false)
public void setSessionIdGenerationStrategy(SessionIdGenerationStrategy sessionIdGenerationStrategy) {
this.sessionIdGenerationStrategy = sessionIdGenerationStrategy;
public void setSessionIdGenerator(SessionIdGenerator sessionIdGenerator) {
this.sessionIdGenerator = sessionIdGenerator;
}
}

View File

@@ -37,8 +37,8 @@ import org.springframework.data.mongodb.core.ReactiveMongoOperations;
import org.springframework.session.IndexResolver;
import org.springframework.session.MapSession;
import org.springframework.session.Session;
import org.springframework.session.SessionIdGenerationStrategy;
import org.springframework.session.UuidSessionIdGenerationStrategy;
import org.springframework.session.SessionIdGenerator;
import org.springframework.session.UuidSessionIdGenerator;
import org.springframework.session.config.ReactiveSessionRepositoryCustomizer;
import org.springframework.session.config.annotation.web.server.SpringWebSessionConfiguration;
import org.springframework.session.data.mongo.AbstractMongoSessionConverter;
@@ -76,7 +76,7 @@ public class ReactiveMongoWebSessionConfiguration
private IndexResolver<Session> indexResolver;
private SessionIdGenerationStrategy sessionIdGenerationStrategy = UuidSessionIdGenerationStrategy.getInstance();
private SessionIdGenerator sessionIdGenerator = UuidSessionIdGenerator.getInstance();
@Bean
public ReactiveMongoSessionRepository reactiveMongoSessionRepository(ReactiveMongoOperations operations) {
@@ -116,7 +116,7 @@ public class ReactiveMongoWebSessionConfiguration
this.sessionRepositoryCustomizers
.forEach((sessionRepositoryCustomizer) -> sessionRepositoryCustomizer.customize(repository));
repository.setSessionIdGenerationStrategy(this.sessionIdGenerationStrategy);
repository.setSessionIdGenerator(this.sessionIdGenerator);
return repository;
}
@@ -187,8 +187,8 @@ public class ReactiveMongoWebSessionConfiguration
}
@Autowired(required = false)
public void setSessionIdGenerationStrategy(SessionIdGenerationStrategy sessionIdGenerationStrategy) {
this.sessionIdGenerationStrategy = sessionIdGenerationStrategy;
public void setSessionIdGenerator(SessionIdGenerator sessionIdGenerator) {
this.sessionIdGenerator = sessionIdGenerator;
}
}

View File

@@ -34,7 +34,7 @@ import org.springframework.data.mongodb.core.MongoOperations;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.session.FindByIndexNameSessionRepository;
import org.springframework.session.MapSession;
import org.springframework.session.SessionIdGenerationStrategy;
import org.springframework.session.SessionIdGenerator;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
@@ -213,7 +213,7 @@ public class MongoIndexedSessionRepositoryTest {
@Test
void createSessionWhenSessionIdGenerationStrategyThenUses() {
this.repository.setSessionIdGenerationStrategy(new FixedSessionIdGenerationStrategy("123"));
this.repository.setSessionIdGenerator(new FixedSessionIdGenerator("123"));
MongoSession session = this.repository.createSession();
assertThat(session.getId()).isEqualTo("123");
assertThat(session.changeSessionId()).isEqualTo("123");
@@ -221,12 +221,12 @@ public class MongoIndexedSessionRepositoryTest {
@Test
void setSessionIdGenerationStrategyWhenNullThenThrowsException() {
assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setSessionIdGenerationStrategy(null));
assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setSessionIdGenerator(null));
}
@Test
void findByIdWhenChangeSessionIdThenUsesSessionIdGenerationStrategy() {
this.repository.setSessionIdGenerationStrategy(new FixedSessionIdGenerationStrategy("456"));
this.repository.setSessionIdGenerator(new FixedSessionIdGenerator("456"));
Document sessionDocument = new Document();
@@ -244,11 +244,11 @@ public class MongoIndexedSessionRepositoryTest {
assertThat(newSessionId).isEqualTo("456");
}
static class FixedSessionIdGenerationStrategy implements SessionIdGenerationStrategy {
static class FixedSessionIdGenerator implements SessionIdGenerator {
private final String id;
FixedSessionIdGenerationStrategy(String id) {
FixedSessionIdGenerator(String id) {
this.id = id;
}

View File

@@ -213,7 +213,7 @@ public class ReactiveMongoSessionRepositoryTest {
@Test
void createSessionWhenSessionIdGenerationStrategyThenUses() {
this.repository.setSessionIdGenerationStrategy(() -> "test");
this.repository.setSessionIdGenerator(() -> "test");
this.repository.createSession().as(StepVerifier::create).assertNext((mongoSession) -> {
assertThat(mongoSession.getId()).isEqualTo("test");
@@ -223,13 +223,13 @@ public class ReactiveMongoSessionRepositoryTest {
@Test
void setSessionIdGenerationStrategyWhenNullThenThrowsException() {
assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setSessionIdGenerationStrategy(null))
.withMessage("sessionIdGenerationStrategy cannot be null");
assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setSessionIdGenerator(null))
.withMessage("sessionIdGenerator cannot be null");
}
@Test
void findByIdWhenChangeSessionIdThenUsesSessionIdGenerationStrategy() {
this.repository.setSessionIdGenerationStrategy(() -> "test");
this.repository.setSessionIdGenerator(() -> "test");
String sessionId = UUID.randomUUID().toString();
Document sessionDocument = new Document();

View File

@@ -34,8 +34,8 @@ import org.springframework.data.mongodb.core.index.IndexOperations;
import org.springframework.mock.env.MockEnvironment;
import org.springframework.session.IndexResolver;
import org.springframework.session.Session;
import org.springframework.session.SessionIdGenerationStrategy;
import org.springframework.session.UuidSessionIdGenerationStrategy;
import org.springframework.session.SessionIdGenerator;
import org.springframework.session.UuidSessionIdGenerator;
import org.springframework.session.config.SessionRepositoryCustomizer;
import org.springframework.session.data.mongo.AbstractMongoSessionConverter;
import org.springframework.session.data.mongo.JacksonMongoSessionConverter;
@@ -206,16 +206,14 @@ public class MongoHttpSessionConfigurationTest {
void registerWhenSessionIdGenerationStrategyBeanThenUses() {
registerAndRefresh(SessionIdGenerationStrategyConfiguration.class);
MongoIndexedSessionRepository sessionRepository = this.context.getBean(MongoIndexedSessionRepository.class);
assertThat(sessionRepository).extracting("sessionIdGenerationStrategy")
.isInstanceOf(TestSessionIdGenerationStrategy.class);
assertThat(sessionRepository).extracting("sessionIdGenerator").isInstanceOf(TestSessionIdGenerator.class);
}
@Test
void registerWhenNoSessionIdGenerationStrategyBeanThenDefault() {
registerAndRefresh(DefaultConfiguration.class);
MongoIndexedSessionRepository sessionRepository = this.context.getBean(MongoIndexedSessionRepository.class);
assertThat(sessionRepository).extracting("sessionIdGenerationStrategy")
.isInstanceOf(UuidSessionIdGenerationStrategy.class);
assertThat(sessionRepository).extracting("sessionIdGenerator").isInstanceOf(UuidSessionIdGenerator.class);
}
private void registerAndRefresh(Class<?>... annotatedClasses) {
@@ -374,13 +372,13 @@ public class MongoHttpSessionConfigurationTest {
static class SessionIdGenerationStrategyConfiguration {
@Bean
SessionIdGenerationStrategy sessionIdGenerationStrategy() {
return new TestSessionIdGenerationStrategy();
SessionIdGenerator sessionIdGenerationStrategy() {
return new TestSessionIdGenerator();
}
}
static class TestSessionIdGenerationStrategy implements SessionIdGenerationStrategy {
static class TestSessionIdGenerator implements SessionIdGenerator {
@Override
public String generate() {

View File

@@ -35,8 +35,8 @@ import org.springframework.data.mongodb.core.index.IndexOperations;
import org.springframework.session.IndexResolver;
import org.springframework.session.ReactiveSessionRepository;
import org.springframework.session.Session;
import org.springframework.session.SessionIdGenerationStrategy;
import org.springframework.session.UuidSessionIdGenerationStrategy;
import org.springframework.session.SessionIdGenerator;
import org.springframework.session.UuidSessionIdGenerator;
import org.springframework.session.config.ReactiveSessionRepositoryCustomizer;
import org.springframework.session.config.annotation.web.server.EnableSpringWebSession;
import org.springframework.session.data.mongo.AbstractMongoSessionConverter;
@@ -228,16 +228,14 @@ public class ReactiveMongoWebSessionConfigurationTest {
void registerWhenSessionIdGenerationStrategyBeanThenUses() {
registerAndRefresh(GoodConfig.class, SessionIdGenerationStrategyConfiguration.class);
ReactiveMongoSessionRepository sessionRepository = this.context.getBean(ReactiveMongoSessionRepository.class);
assertThat(sessionRepository).extracting("sessionIdGenerationStrategy")
.isInstanceOf(TestSessionIdGenerationStrategy.class);
assertThat(sessionRepository).extracting("sessionIdGenerator").isInstanceOf(TestSessionIdGenerator.class);
}
@Test
void registerWhenNoSessionIdGenerationStrategyBeanThenDefault() {
registerAndRefresh(GoodConfig.class);
ReactiveMongoSessionRepository sessionRepository = this.context.getBean(ReactiveMongoSessionRepository.class);
assertThat(sessionRepository).extracting("sessionIdGenerationStrategy")
.isInstanceOf(UuidSessionIdGenerationStrategy.class);
assertThat(sessionRepository).extracting("sessionIdGenerator").isInstanceOf(UuidSessionIdGenerator.class);
}
private void registerAndRefresh(Class<?>... annotatedClasses) {
@@ -439,13 +437,13 @@ public class ReactiveMongoWebSessionConfigurationTest {
static class SessionIdGenerationStrategyConfiguration {
@Bean
SessionIdGenerationStrategy sessionIdGenerationStrategy() {
return new TestSessionIdGenerationStrategy();
SessionIdGenerator sessionIdGenerationStrategy() {
return new TestSessionIdGenerator();
}
}
static class TestSessionIdGenerationStrategy implements SessionIdGenerationStrategy {
static class TestSessionIdGenerator implements SessionIdGenerator {
@Override
public String generate() {

View File

@@ -31,8 +31,8 @@ import org.springframework.session.MapSession;
import org.springframework.session.ReactiveSessionRepository;
import org.springframework.session.SaveMode;
import org.springframework.session.Session;
import org.springframework.session.SessionIdGenerationStrategy;
import org.springframework.session.UuidSessionIdGenerationStrategy;
import org.springframework.session.SessionIdGenerator;
import org.springframework.session.UuidSessionIdGenerator;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
@@ -63,7 +63,7 @@ public class ReactiveRedisSessionRepository
private SaveMode saveMode = SaveMode.ON_SET_ATTRIBUTE;
private SessionIdGenerationStrategy sessionIdGenerationStrategy = UuidSessionIdGenerationStrategy.getInstance();
private SessionIdGenerator sessionIdGenerator = UuidSessionIdGenerator.getInstance();
/**
* Create a new {@link ReactiveRedisSessionRepository} instance.
@@ -124,7 +124,7 @@ public class ReactiveRedisSessionRepository
@Override
public Mono<RedisSession> createSession() {
return Mono.defer(() -> {
MapSession cached = new MapSession(this.sessionIdGenerationStrategy);
MapSession cached = new MapSession(this.sessionIdGenerator);
cached.setMaxInactiveInterval(this.defaultMaxInactiveInterval);
RedisSession session = new RedisSession(cached, true);
return Mono.just(session);
@@ -172,13 +172,13 @@ public class ReactiveRedisSessionRepository
}
/**
* Set the {@link SessionIdGenerationStrategy} to use to generate session ids.
* @param sessionIdGenerationStrategy the {@link SessionIdGenerationStrategy} to use
* Set the {@link SessionIdGenerator} to use to generate session ids.
* @param sessionIdGenerator the {@link SessionIdGenerator} to use
* @since 3.2
*/
public void setSessionIdGenerationStrategy(SessionIdGenerationStrategy sessionIdGenerationStrategy) {
Assert.notNull(sessionIdGenerationStrategy, "sessionIdGenerationStrategy cannot be null");
this.sessionIdGenerationStrategy = sessionIdGenerationStrategy;
public void setSessionIdGenerator(SessionIdGenerator sessionIdGenerator) {
Assert.notNull(sessionIdGenerator, "sessionIdGenerator cannot be null");
this.sessionIdGenerator = sessionIdGenerator;
}
/**
@@ -220,7 +220,7 @@ public class ReactiveRedisSessionRepository
@Override
public String changeSessionId() {
String newSessionId = ReactiveRedisSessionRepository.this.sessionIdGenerationStrategy.generate();
String newSessionId = ReactiveRedisSessionRepository.this.sessionIdGenerator.generate();
this.cached.setId(newSessionId);
return newSessionId;
}

View File

@@ -52,8 +52,8 @@ import org.springframework.session.MapSession;
import org.springframework.session.PrincipalNameIndexResolver;
import org.springframework.session.SaveMode;
import org.springframework.session.Session;
import org.springframework.session.SessionIdGenerationStrategy;
import org.springframework.session.UuidSessionIdGenerationStrategy;
import org.springframework.session.SessionIdGenerator;
import org.springframework.session.UuidSessionIdGenerator;
import org.springframework.session.events.SessionCreatedEvent;
import org.springframework.session.events.SessionDeletedEvent;
import org.springframework.session.events.SessionDestroyedEvent;
@@ -324,7 +324,7 @@ public class RedisIndexedSessionRepository
private ThreadPoolTaskScheduler taskScheduler;
private SessionIdGenerationStrategy sessionIdGenerationStrategy = UuidSessionIdGenerationStrategy.getInstance();
private SessionIdGenerator sessionIdGenerator = UuidSessionIdGenerator.getInstance();
/**
* Creates a new instance. For an example, refer to the class level javadoc.
@@ -551,7 +551,7 @@ public class RedisIndexedSessionRepository
@Override
public RedisSession createSession() {
MapSession cached = new MapSession(this.sessionIdGenerationStrategy);
MapSession cached = new MapSession(this.sessionIdGenerator);
cached.setMaxInactiveInterval(this.defaultMaxInactiveInterval);
RedisSession session = new RedisSession(cached, true);
session.flushImmediateIfNecessary();
@@ -721,13 +721,13 @@ public class RedisIndexedSessionRepository
}
/**
* Set the {@link SessionIdGenerationStrategy} to use to generate session ids.
* @param sessionIdGenerationStrategy the {@link SessionIdGenerationStrategy} to use
* Set the {@link SessionIdGenerator} to use to generate session ids.
* @param sessionIdGenerator the {@link SessionIdGenerator} to use
* @since 3.2
*/
public void setSessionIdGenerationStrategy(SessionIdGenerationStrategy sessionIdGenerationStrategy) {
Assert.notNull(sessionIdGenerationStrategy, "sessionIdGenerationStrategy cannot be null");
this.sessionIdGenerationStrategy = sessionIdGenerationStrategy;
public void setSessionIdGenerator(SessionIdGenerator sessionIdGenerator) {
Assert.notNull(sessionIdGenerator, "sessionIdGenerator cannot be null");
this.sessionIdGenerator = sessionIdGenerator;
}
/**
@@ -794,7 +794,7 @@ public class RedisIndexedSessionRepository
@Override
public String changeSessionId() {
String newSessionId = RedisIndexedSessionRepository.this.sessionIdGenerationStrategy.generate();
String newSessionId = RedisIndexedSessionRepository.this.sessionIdGenerator.generate();
this.cached.setId(newSessionId);
return newSessionId;
}

View File

@@ -27,9 +27,9 @@ import org.springframework.session.FlushMode;
import org.springframework.session.MapSession;
import org.springframework.session.SaveMode;
import org.springframework.session.Session;
import org.springframework.session.SessionIdGenerationStrategy;
import org.springframework.session.SessionIdGenerator;
import org.springframework.session.SessionRepository;
import org.springframework.session.UuidSessionIdGenerationStrategy;
import org.springframework.session.UuidSessionIdGenerator;
import org.springframework.util.Assert;
/**
@@ -58,7 +58,7 @@ public class RedisSessionRepository implements SessionRepository<RedisSessionRep
private SaveMode saveMode = SaveMode.ON_SET_ATTRIBUTE;
private SessionIdGenerationStrategy sessionIdGenerationStrategy = UuidSessionIdGenerationStrategy.getInstance();
private SessionIdGenerator sessionIdGenerator = UuidSessionIdGenerator.getInstance();
/**
* Create a new {@link RedisSessionRepository} instance.
@@ -110,7 +110,7 @@ public class RedisSessionRepository implements SessionRepository<RedisSessionRep
@Override
public RedisSession createSession() {
MapSession cached = new MapSession(this.sessionIdGenerationStrategy);
MapSession cached = new MapSession(this.sessionIdGenerator);
cached.setMaxInactiveInterval(this.defaultMaxInactiveInterval);
RedisSession session = new RedisSession(cached, true);
session.flushIfRequired();
@@ -167,13 +167,13 @@ public class RedisSessionRepository implements SessionRepository<RedisSessionRep
}
/**
* Set the {@link SessionIdGenerationStrategy} to use to generate session ids.
* @param sessionIdGenerationStrategy the {@link SessionIdGenerationStrategy} to use
* Set the {@link SessionIdGenerator} to use to generate session ids.
* @param sessionIdGenerator the {@link SessionIdGenerator} to use
* @since 3.2
*/
public void setSessionIdGenerationStrategy(SessionIdGenerationStrategy sessionIdGenerationStrategy) {
Assert.notNull(sessionIdGenerationStrategy, "sessionIdGenerationStrategy cannot be null");
this.sessionIdGenerationStrategy = sessionIdGenerationStrategy;
public void setSessionIdGenerator(SessionIdGenerator sessionIdGenerator) {
Assert.notNull(sessionIdGenerator, "sessionIdGenerator cannot be null");
this.sessionIdGenerator = sessionIdGenerator;
}
/**
@@ -212,7 +212,7 @@ public class RedisSessionRepository implements SessionRepository<RedisSessionRep
@Override
public String changeSessionId() {
String newSessionId = RedisSessionRepository.this.sessionIdGenerationStrategy.generate();
String newSessionId = RedisSessionRepository.this.sessionIdGenerator.generate();
this.cached.setId(newSessionId);
return newSessionId;
}

View File

@@ -28,8 +28,8 @@ import org.springframework.core.annotation.AnnotationAttributes;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.session.SessionIdGenerationStrategy;
import org.springframework.session.UuidSessionIdGenerationStrategy;
import org.springframework.session.SessionIdGenerator;
import org.springframework.session.UuidSessionIdGenerator;
import org.springframework.session.data.redis.RedisSessionRepository;
import org.springframework.session.web.http.SessionRepositoryFilter;
import org.springframework.util.StringUtils;
@@ -52,7 +52,7 @@ public class RedisHttpSessionConfiguration extends AbstractRedisHttpSessionConfi
private StringValueResolver embeddedValueResolver;
private SessionIdGenerationStrategy sessionIdGenerationStrategy = UuidSessionIdGenerationStrategy.getInstance();
private SessionIdGenerator sessionIdGenerator = UuidSessionIdGenerator.getInstance();
@Bean
@Override
@@ -65,7 +65,7 @@ public class RedisHttpSessionConfiguration extends AbstractRedisHttpSessionConfi
}
sessionRepository.setFlushMode(getFlushMode());
sessionRepository.setSaveMode(getSaveMode());
sessionRepository.setSessionIdGenerationStrategy(this.sessionIdGenerationStrategy);
sessionRepository.setSessionIdGenerator(this.sessionIdGenerator);
getSessionRepositoryCustomizers()
.forEach((sessionRepositoryCustomizer) -> sessionRepositoryCustomizer.customize(sessionRepository));
return sessionRepository;
@@ -94,8 +94,8 @@ public class RedisHttpSessionConfiguration extends AbstractRedisHttpSessionConfi
}
@Autowired(required = false)
public void setSessionIdGenerationStrategy(SessionIdGenerationStrategy sessionIdGenerationStrategy) {
this.sessionIdGenerationStrategy = sessionIdGenerationStrategy;
public void setSessionIdGenerator(SessionIdGenerator sessionIdGenerator) {
this.sessionIdGenerator = sessionIdGenerator;
}
}

View File

@@ -44,8 +44,8 @@ import org.springframework.data.redis.listener.PatternTopic;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
import org.springframework.session.IndexResolver;
import org.springframework.session.Session;
import org.springframework.session.SessionIdGenerationStrategy;
import org.springframework.session.UuidSessionIdGenerationStrategy;
import org.springframework.session.SessionIdGenerator;
import org.springframework.session.UuidSessionIdGenerator;
import org.springframework.session.data.redis.RedisIndexedSessionRepository;
import org.springframework.session.data.redis.config.ConfigureNotifyKeyspaceEventsAction;
import org.springframework.session.data.redis.config.ConfigureRedisAction;
@@ -82,7 +82,7 @@ public class RedisIndexedHttpSessionConfiguration
private StringValueResolver embeddedValueResolver;
private SessionIdGenerationStrategy sessionIdGenerationStrategy = UuidSessionIdGenerationStrategy.getInstance();
private SessionIdGenerator sessionIdGenerator = UuidSessionIdGenerator.getInstance();
@Bean
@Override
@@ -105,7 +105,7 @@ public class RedisIndexedHttpSessionConfiguration
sessionRepository.setCleanupCron(this.cleanupCron);
int database = resolveDatabase();
sessionRepository.setDatabase(database);
sessionRepository.setSessionIdGenerationStrategy(this.sessionIdGenerationStrategy);
sessionRepository.setSessionIdGenerator(this.sessionIdGenerator);
getSessionRepositoryCustomizers()
.forEach((sessionRepositoryCustomizer) -> sessionRepositoryCustomizer.customize(sessionRepository));
return sessionRepository;
@@ -210,8 +210,8 @@ public class RedisIndexedHttpSessionConfiguration
}
@Autowired(required = false)
public void setSessionIdGenerationStrategy(SessionIdGenerationStrategy sessionIdGenerationStrategy) {
this.sessionIdGenerationStrategy = sessionIdGenerationStrategy;
public void setSessionIdGenerator(SessionIdGenerator sessionIdGenerator) {
this.sessionIdGenerator = sessionIdGenerator;
}
/**

View File

@@ -39,8 +39,8 @@ import org.springframework.data.redis.serializer.RedisSerializationContext;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.session.MapSession;
import org.springframework.session.SaveMode;
import org.springframework.session.SessionIdGenerationStrategy;
import org.springframework.session.UuidSessionIdGenerationStrategy;
import org.springframework.session.SessionIdGenerator;
import org.springframework.session.UuidSessionIdGenerator;
import org.springframework.session.config.ReactiveSessionRepositoryCustomizer;
import org.springframework.session.config.annotation.web.server.SpringWebSessionConfiguration;
import org.springframework.session.data.redis.ReactiveRedisSessionRepository;
@@ -79,7 +79,7 @@ public class RedisWebSessionConfiguration implements BeanClassLoaderAware, Embed
private StringValueResolver embeddedValueResolver;
private SessionIdGenerationStrategy sessionIdGenerationStrategy = UuidSessionIdGenerationStrategy.getInstance();
private SessionIdGenerator sessionIdGenerator = UuidSessionIdGenerator.getInstance();
@Bean
public ReactiveRedisSessionRepository sessionRepository() {
@@ -90,7 +90,7 @@ public class RedisWebSessionConfiguration implements BeanClassLoaderAware, Embed
sessionRepository.setRedisKeyNamespace(this.redisNamespace);
}
sessionRepository.setSaveMode(this.saveMode);
sessionRepository.setSessionIdGenerationStrategy(this.sessionIdGenerationStrategy);
sessionRepository.setSessionIdGenerator(this.sessionIdGenerator);
this.sessionRepositoryCustomizers
.forEach((sessionRepositoryCustomizer) -> sessionRepositoryCustomizer.customize(sessionRepository));
return sessionRepository;
@@ -174,8 +174,8 @@ public class RedisWebSessionConfiguration implements BeanClassLoaderAware, Embed
}
@Autowired(required = false)
public void setSessionIdGenerationStrategy(SessionIdGenerationStrategy sessionIdGenerationStrategy) {
this.sessionIdGenerationStrategy = sessionIdGenerationStrategy;
public void setSessionIdGenerator(SessionIdGenerator sessionIdGenerator) {
this.sessionIdGenerator = sessionIdGenerator;
}
}

View File

@@ -440,7 +440,7 @@ class ReactiveRedisSessionRepositoryTests {
@Test
void createSessionWhenSessionIdGenerationStrategyThenUses() {
this.repository.setSessionIdGenerationStrategy(() -> "test");
this.repository.setSessionIdGenerator(() -> "test");
this.repository.createSession().as(StepVerifier::create).assertNext((redisSession) -> {
assertThat(redisSession.getId()).isEqualTo("test");
@@ -450,14 +450,14 @@ class ReactiveRedisSessionRepositoryTests {
@Test
void setSessionIdGenerationStrategyWhenNullThenThrowsException() {
assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setSessionIdGenerationStrategy(null))
.withMessage("sessionIdGenerationStrategy cannot be null");
assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setSessionIdGenerator(null))
.withMessage("sessionIdGenerator cannot be null");
}
@Test
@SuppressWarnings("unchecked")
void findByIdWhenChangeSessionIdThenUsesSessionIdGenerationStrategy() {
this.repository.setSessionIdGenerationStrategy(() -> "changed-session-id");
this.repository.setSessionIdGenerator(() -> "changed-session-id");
given(this.redisOperations.opsForHash()).willReturn(this.hashOperations);
String attribute1 = "attribute1";
String attribute2 = "attribute2";

View File

@@ -912,7 +912,7 @@ class RedisIndexedSessionRepositoryTests {
@Test
void createSessionWhenSessionIdGenerationStrategyThenUses() {
this.redisRepository.setSessionIdGenerationStrategy(() -> "test");
this.redisRepository.setSessionIdGenerator(() -> "test");
RedisSession session = this.redisRepository.createSession();
assertThat(session.getId()).isEqualTo("test");
assertThat(session.changeSessionId()).isEqualTo("test");
@@ -920,13 +920,13 @@ class RedisIndexedSessionRepositoryTests {
@Test
void setSessionIdGenerationStrategyWhenNullThenThrowsException() {
assertThatIllegalArgumentException().isThrownBy(() -> this.redisRepository.setSessionIdGenerationStrategy(null))
.withMessage("sessionIdGenerationStrategy cannot be null");
assertThatIllegalArgumentException().isThrownBy(() -> this.redisRepository.setSessionIdGenerator(null))
.withMessage("sessionIdGenerator cannot be null");
}
@Test
void findByIdWhenChangeSessionIdThenUsesSessionIdGenerationStrategy() {
this.redisRepository.setSessionIdGenerationStrategy(() -> "test");
this.redisRepository.setSessionIdGenerator(() -> "test");
String attribute1 = "attribute1";
String attribute2 = "attribute2";
MapSession expected = new MapSession("original");

View File

@@ -375,7 +375,7 @@ class RedisSessionRepositoryTests {
@Test
void createSessionWhenSessionIdGenerationStrategyThenUses() {
this.sessionRepository.setSessionIdGenerationStrategy(() -> "test");
this.sessionRepository.setSessionIdGenerator(() -> "test");
RedisSessionRepository.RedisSession session = this.sessionRepository.createSession();
assertThat(session.getId()).isEqualTo("test");
assertThat(session.changeSessionId()).isEqualTo("test");
@@ -383,14 +383,13 @@ class RedisSessionRepositoryTests {
@Test
void setSessionIdGenerationStrategyWhenNullThenThrowsException() {
assertThatIllegalArgumentException()
.isThrownBy(() -> this.sessionRepository.setSessionIdGenerationStrategy(null))
.withMessage("sessionIdGenerationStrategy cannot be null");
assertThatIllegalArgumentException().isThrownBy(() -> this.sessionRepository.setSessionIdGenerator(null))
.withMessage("sessionIdGenerator cannot be null");
}
@Test
void findByIdWhenChangeSessionIdThenUsesSessionIdGenerationStrategy() {
this.sessionRepository.setSessionIdGenerationStrategy(() -> "test");
this.sessionRepository.setSessionIdGenerator(() -> "test");
Instant now = Instant.now().truncatedTo(ChronoUnit.MILLIS);
given(this.sessionHashOperations.entries(eq(TEST_SESSION_KEY)))
.willReturn(mapOf(RedisSessionMapper.CREATION_TIME_KEY, Instant.EPOCH.toEpochMilli(),

View File

@@ -39,8 +39,8 @@ import org.springframework.data.redis.core.RedisOperations;
import org.springframework.mock.env.MockEnvironment;
import org.springframework.session.FlushMode;
import org.springframework.session.SaveMode;
import org.springframework.session.SessionIdGenerationStrategy;
import org.springframework.session.UuidSessionIdGenerationStrategy;
import org.springframework.session.SessionIdGenerator;
import org.springframework.session.UuidSessionIdGenerator;
import org.springframework.session.config.SessionRepositoryCustomizer;
import org.springframework.session.data.redis.RedisSessionRepository;
import org.springframework.session.data.redis.config.annotation.SpringSessionRedisConnectionFactory;
@@ -212,16 +212,14 @@ class RedisHttpsSessionConfigurationTests {
void registerWhenSessionIdGenerationStrategyBeanThenUses() {
registerAndRefresh(RedisConfig.class, SessionIdGenerationStrategyConfiguration.class);
RedisSessionRepository sessionRepository = this.context.getBean(RedisSessionRepository.class);
assertThat(sessionRepository).extracting("sessionIdGenerationStrategy")
.isInstanceOf(TestSessionIdGenerationStrategy.class);
assertThat(sessionRepository).extracting("sessionIdGenerator").isInstanceOf(TestSessionIdGenerator.class);
}
@Test
void registerWhenNoSessionIdGenerationStrategyBeanThenDefault() {
registerAndRefresh(RedisConfig.class, DefaultConfiguration.class);
RedisSessionRepository sessionRepository = this.context.getBean(RedisSessionRepository.class);
assertThat(sessionRepository).extracting("sessionIdGenerationStrategy")
.isInstanceOf(UuidSessionIdGenerationStrategy.class);
assertThat(sessionRepository).extracting("sessionIdGenerator").isInstanceOf(UuidSessionIdGenerator.class);
}
private void registerAndRefresh(Class<?>... annotatedClasses) {
@@ -404,8 +402,8 @@ class RedisHttpsSessionConfigurationTests {
static class SessionIdGenerationStrategyConfiguration {
@Bean
SessionIdGenerationStrategy sessionIdGenerationStrategy() {
return new TestSessionIdGenerationStrategy();
SessionIdGenerator sessionIdGenerationStrategy() {
return new TestSessionIdGenerator();
}
}
@@ -416,7 +414,7 @@ class RedisHttpsSessionConfigurationTests {
}
static class TestSessionIdGenerationStrategy implements SessionIdGenerationStrategy {
static class TestSessionIdGenerator implements SessionIdGenerator {
@Override
public String generate() {

View File

@@ -43,8 +43,8 @@ import org.springframework.session.FlushMode;
import org.springframework.session.IndexResolver;
import org.springframework.session.SaveMode;
import org.springframework.session.Session;
import org.springframework.session.SessionIdGenerationStrategy;
import org.springframework.session.UuidSessionIdGenerationStrategy;
import org.springframework.session.SessionIdGenerator;
import org.springframework.session.UuidSessionIdGenerator;
import org.springframework.session.config.SessionRepositoryCustomizer;
import org.springframework.session.data.redis.RedisIndexedSessionRepository;
import org.springframework.session.data.redis.config.annotation.SpringSessionRedisConnectionFactory;
@@ -246,16 +246,14 @@ class RedisIndexedHttpSessionConfigurationTests {
void registerWhenSessionIdGenerationStrategyBeanThenUses() {
registerAndRefresh(RedisConfig.class, SessionIdGenerationStrategyConfiguration.class);
RedisIndexedSessionRepository sessionRepository = this.context.getBean(RedisIndexedSessionRepository.class);
assertThat(sessionRepository).extracting("sessionIdGenerationStrategy")
.isInstanceOf(TestSessionIdGenerationStrategy.class);
assertThat(sessionRepository).extracting("sessionIdGenerator").isInstanceOf(TestSessionIdGenerator.class);
}
@Test
void registerWhenNoSessionIdGenerationStrategyBeanThenDefault() {
registerAndRefresh(RedisConfig.class, DefaultConfiguration.class);
RedisIndexedSessionRepository sessionRepository = this.context.getBean(RedisIndexedSessionRepository.class);
assertThat(sessionRepository).extracting("sessionIdGenerationStrategy")
.isInstanceOf(UuidSessionIdGenerationStrategy.class);
assertThat(sessionRepository).extracting("sessionIdGenerator").isInstanceOf(UuidSessionIdGenerator.class);
}
private void registerAndRefresh(Class<?>... annotatedClasses) {
@@ -467,8 +465,8 @@ class RedisIndexedHttpSessionConfigurationTests {
static class SessionIdGenerationStrategyConfiguration {
@Bean
SessionIdGenerationStrategy sessionIdGenerationStrategy() {
return new TestSessionIdGenerationStrategy();
SessionIdGenerator sessionIdGenerationStrategy() {
return new TestSessionIdGenerator();
}
}
@@ -479,7 +477,7 @@ class RedisIndexedHttpSessionConfigurationTests {
}
static class TestSessionIdGenerationStrategy implements SessionIdGenerationStrategy {
static class TestSessionIdGenerator implements SessionIdGenerator {
@Override
public String generate() {

View File

@@ -9,9 +9,9 @@ It contains configuration examples for the following use cases:
[[changing-how-session-ids-are-generated]]
== Changing How Session IDs Are Generated
By default, Spring Session uses `UuidSessionIdGenerationStrategy` which, in turn, uses a `java.util.UUID` to generate a session id.
By default, Spring Session uses `UuidSessionIdGenerator` which, in turn, uses a `java.util.UUID` to generate a session id.
There might be scenarios where it may be better to include other characters to increase entropy, or you may want to use a different algorithm to generate the session id.
To change this, you can provide a custom `SessionIdGenerationStrategy` bean:
To change this, you can provide a custom `SessionIdGenerator` bean:
.Changing How Session IDs Are Generated
[tabs]
@@ -21,11 +21,11 @@ Java::
[source,java,role="primary"]
----
@Bean
public SessionIdGenerationStrategy sessionIdGenerationStrategy() {
return new MySessionIdGenerationStrategy();
public SessionIdGenerator sessionIdGenerator() {
return new MySessionIdGenerator();
}
class MySessionIdGenerationStrategy implements SessionIdGenerationStrategy {
class MySessionIdGenerator implements SessionIdGenerator {
@Override
public String generate() {
@@ -36,11 +36,11 @@ class MySessionIdGenerationStrategy implements SessionIdGenerationStrategy {
----
======
After exposing your `SessionIdGenerationStrategy` bean, Spring Session will use it to generate session ids.
After exposing your `SessionIdGenerator` bean, Spring Session will use it to generate session ids.
If you are manually configuring your `SessionRepository` bean (instead of using `@EnableRedisHttpSession`, for example), you can set the `SessionIdGenerationStrategy` directly on the `SessionRepository` implementation:
If you are manually configuring your `SessionRepository` bean (instead of using `@EnableRedisHttpSession`, for example), you can set the `SessionIdGenerator` directly on the `SessionRepository` implementation:
.Setting `SessionIdGenerationStrategy` directly into `SessionRepository` implementation
.Setting `SessionIdGenerator` directly into `SessionRepository` implementation
[tabs]
======
Java::
@@ -50,7 +50,7 @@ Java::
@Bean
public RedisSessionRepository redisSessionRepository(RedisOperations redisOperations) {
RedisSessionRepository repository = new RedisSessionRepository(redisOperations)
repository.setSessionIdGenerationStrategy(new MySessionIdGenerationStrategy());
repository.setSessionIdGenerator(new MySessionIdGenerator());
return repository;
}
----

View File

@@ -1,3 +1,3 @@
= What's New
- xref:configuration/common.adoc#changing-how-session-ids-are-generated[docs] - https://github.com/spring-projects/spring-session/issues/11[gh-11] - Introduce `SessionIdGenerationStrategy` to allow custom session id generation
- xref:configuration/common.adoc#changing-how-session-ids-are-generated[docs] - https://github.com/spring-projects/spring-session/issues/11[gh-11] - Introduce `SessionIdGenerator` to allow custom session id generation

View File

@@ -48,8 +48,8 @@ import org.springframework.session.MapSession;
import org.springframework.session.PrincipalNameIndexResolver;
import org.springframework.session.SaveMode;
import org.springframework.session.Session;
import org.springframework.session.SessionIdGenerationStrategy;
import org.springframework.session.UuidSessionIdGenerationStrategy;
import org.springframework.session.SessionIdGenerator;
import org.springframework.session.UuidSessionIdGenerator;
import org.springframework.session.events.AbstractSessionEvent;
import org.springframework.session.events.SessionCreatedEvent;
import org.springframework.session.events.SessionDeletedEvent;
@@ -153,7 +153,7 @@ public class HazelcastIndexedSessionRepository
private UUID sessionListenerId;
private SessionIdGenerationStrategy sessionIdGenerationStrategy = UuidSessionIdGenerationStrategy.getInstance();
private SessionIdGenerator sessionIdGenerator = UuidSessionIdGenerator.getInstance();
/**
* Create a new {@link HazelcastIndexedSessionRepository} instance.
@@ -249,7 +249,7 @@ public class HazelcastIndexedSessionRepository
@Override
public HazelcastSession createSession() {
MapSession cached = new MapSession(this.sessionIdGenerationStrategy);
MapSession cached = new MapSession(this.sessionIdGenerator);
cached.setMaxInactiveInterval(this.defaultMaxInactiveInterval);
HazelcastSession session = new HazelcastSession(cached, true);
session.flushImmediateIfNecessary();
@@ -354,13 +354,13 @@ public class HazelcastIndexedSessionRepository
}
/**
* Set the {@link SessionIdGenerationStrategy} to use to generate session ids.
* @param sessionIdGenerationStrategy the {@link SessionIdGenerationStrategy} to use
* Set the {@link SessionIdGenerator} to use to generate session ids.
* @param sessionIdGenerator the {@link SessionIdGenerator} to use
* @since 3.2
*/
public void setSessionIdGenerationStrategy(SessionIdGenerationStrategy sessionIdGenerationStrategy) {
Assert.notNull(sessionIdGenerationStrategy, "sessionIdGenerationStrategy cannot be null");
this.sessionIdGenerationStrategy = sessionIdGenerationStrategy;
public void setSessionIdGenerator(SessionIdGenerator sessionIdGenerator) {
Assert.notNull(sessionIdGenerator, "sessionIdGenerator cannot be null");
this.sessionIdGenerator = sessionIdGenerator;
}
/**
@@ -419,7 +419,7 @@ public class HazelcastIndexedSessionRepository
@Override
public String changeSessionId() {
String newSessionId = HazelcastIndexedSessionRepository.this.sessionIdGenerationStrategy.generate();
String newSessionId = HazelcastIndexedSessionRepository.this.sessionIdGenerator.generate();
this.delegate.setId(newSessionId);
this.sessionIdChanged = true;
return newSessionId;

View File

@@ -38,8 +38,8 @@ import org.springframework.session.IndexResolver;
import org.springframework.session.MapSession;
import org.springframework.session.SaveMode;
import org.springframework.session.Session;
import org.springframework.session.SessionIdGenerationStrategy;
import org.springframework.session.UuidSessionIdGenerationStrategy;
import org.springframework.session.SessionIdGenerator;
import org.springframework.session.UuidSessionIdGenerator;
import org.springframework.session.config.SessionRepositoryCustomizer;
import org.springframework.session.config.annotation.web.http.SpringHttpSessionConfiguration;
import org.springframework.session.hazelcast.HazelcastIndexedSessionRepository;
@@ -77,7 +77,7 @@ public class HazelcastHttpSessionConfiguration implements ImportAware {
private List<SessionRepositoryCustomizer<HazelcastIndexedSessionRepository>> sessionRepositoryCustomizers;
private SessionIdGenerationStrategy sessionIdGenerationStrategy = UuidSessionIdGenerationStrategy.getInstance();
private SessionIdGenerator sessionIdGenerator = UuidSessionIdGenerator.getInstance();
@Bean
public FindByIndexNameSessionRepository<?> sessionRepository() {
@@ -162,15 +162,15 @@ public class HazelcastHttpSessionConfiguration implements ImportAware {
sessionRepository.setDefaultMaxInactiveInterval(this.maxInactiveInterval);
sessionRepository.setFlushMode(this.flushMode);
sessionRepository.setSaveMode(this.saveMode);
sessionRepository.setSessionIdGenerationStrategy(this.sessionIdGenerationStrategy);
sessionRepository.setSessionIdGenerator(this.sessionIdGenerator);
this.sessionRepositoryCustomizers
.forEach((sessionRepositoryCustomizer) -> sessionRepositoryCustomizer.customize(sessionRepository));
return sessionRepository;
}
@Autowired(required = false)
public void setSessionIdGenerationStrategy(SessionIdGenerationStrategy sessionIdGenerationStrategy) {
this.sessionIdGenerationStrategy = sessionIdGenerationStrategy;
public void setSessionIdGenerator(SessionIdGenerator sessionIdGenerator) {
this.sessionIdGenerator = sessionIdGenerator;
}
}

View File

@@ -467,7 +467,7 @@ class HazelcastIndexedSessionRepositoryTests {
@Test
void createSessionWhenSessionIdGenerationStrategyThenUses() {
this.repository.setSessionIdGenerationStrategy(() -> "test");
this.repository.setSessionIdGenerator(() -> "test");
HazelcastSession session = this.repository.createSession();
assertThat(session.getId()).isEqualTo("test");
assertThat(session.changeSessionId()).isEqualTo("test");
@@ -475,13 +475,13 @@ class HazelcastIndexedSessionRepositoryTests {
@Test
void setSessionIdGenerationStrategyWhenNullThenThrowsException() {
assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setSessionIdGenerationStrategy(null))
.withMessage("sessionIdGenerationStrategy cannot be null");
assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setSessionIdGenerator(null))
.withMessage("sessionIdGenerator cannot be null");
}
@Test
void findByIdWhenChangeSessionIdThenUsesSessionIdGenerationStrategy() {
this.repository.setSessionIdGenerationStrategy(() -> "test");
this.repository.setSessionIdGenerator(() -> "test");
MapSession saved = new MapSession("original");
saved.setAttribute("savedName", "savedValue");
given(this.sessions.get(eq(saved.getId()))).willReturn(saved);

View File

@@ -36,8 +36,8 @@ import org.springframework.session.FlushMode;
import org.springframework.session.IndexResolver;
import org.springframework.session.SaveMode;
import org.springframework.session.Session;
import org.springframework.session.SessionIdGenerationStrategy;
import org.springframework.session.UuidSessionIdGenerationStrategy;
import org.springframework.session.SessionIdGenerator;
import org.springframework.session.UuidSessionIdGenerator;
import org.springframework.session.config.SessionRepositoryCustomizer;
import org.springframework.session.hazelcast.HazelcastIndexedSessionRepository;
import org.springframework.session.hazelcast.config.annotation.SpringSessionHazelcastInstance;
@@ -245,8 +245,7 @@ class HazelcastHttpSessionConfigurationTests {
registerAndRefresh(DefaultConfiguration.class, SessionIdGenerationStrategyConfiguration.class);
HazelcastIndexedSessionRepository sessionRepository = this.context
.getBean(HazelcastIndexedSessionRepository.class);
assertThat(sessionRepository).extracting("sessionIdGenerationStrategy")
.isInstanceOf(TestSessionIdGenerationStrategy.class);
assertThat(sessionRepository).extracting("sessionIdGenerator").isInstanceOf(TestSessionIdGenerator.class);
}
@Test
@@ -254,8 +253,7 @@ class HazelcastHttpSessionConfigurationTests {
registerAndRefresh(DefaultConfiguration.class);
HazelcastIndexedSessionRepository sessionRepository = this.context
.getBean(HazelcastIndexedSessionRepository.class);
assertThat(sessionRepository).extracting("sessionIdGenerationStrategy")
.isInstanceOf(UuidSessionIdGenerationStrategy.class);
assertThat(sessionRepository).extracting("sessionIdGenerator").isInstanceOf(UuidSessionIdGenerator.class);
}
private void registerAndRefresh(Class<?>... annotatedClasses) {
@@ -489,13 +487,13 @@ class HazelcastHttpSessionConfigurationTests {
static class SessionIdGenerationStrategyConfiguration {
@Bean
SessionIdGenerationStrategy sessionIdGenerationStrategy() {
return new TestSessionIdGenerationStrategy();
SessionIdGenerator sessionIdGenerationStrategy() {
return new TestSessionIdGenerator();
}
}
static class TestSessionIdGenerationStrategy implements SessionIdGenerationStrategy {
static class TestSessionIdGenerator implements SessionIdGenerator {
@Override
public String generate() {

View File

@@ -62,8 +62,8 @@ import org.springframework.session.MapSession;
import org.springframework.session.PrincipalNameIndexResolver;
import org.springframework.session.SaveMode;
import org.springframework.session.Session;
import org.springframework.session.SessionIdGenerationStrategy;
import org.springframework.session.UuidSessionIdGenerationStrategy;
import org.springframework.session.SessionIdGenerator;
import org.springframework.session.UuidSessionIdGenerator;
import org.springframework.transaction.support.TransactionOperations;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
@@ -254,7 +254,7 @@ public class JdbcIndexedSessionRepository implements
private ThreadPoolTaskScheduler taskScheduler;
private SessionIdGenerationStrategy sessionIdGenerationStrategy = UuidSessionIdGenerationStrategy.getInstance();
private SessionIdGenerator sessionIdGenerator = UuidSessionIdGenerator.getInstance();
/**
* Create a new {@link JdbcIndexedSessionRepository} instance which uses the provided
@@ -465,7 +465,7 @@ public class JdbcIndexedSessionRepository implements
@Override
public JdbcSession createSession() {
MapSession delegate = new MapSession(this.sessionIdGenerationStrategy);
MapSession delegate = new MapSession(this.sessionIdGenerator);
delegate.setMaxInactiveInterval(this.defaultMaxInactiveInterval);
JdbcSession session = new JdbcSession(delegate, UUID.randomUUID().toString(), true);
session.flushIfRequired();
@@ -691,13 +691,13 @@ public class JdbcIndexedSessionRepository implements
}
/**
* Set the {@link SessionIdGenerationStrategy} to use to generate session ids.
* @param sessionIdGenerationStrategy the {@link SessionIdGenerationStrategy} to use
* Set the {@link SessionIdGenerator} to use to generate session ids.
* @param sessionIdGenerator the {@link SessionIdGenerator} to use
* @since 3.2
*/
public void setSessionIdGenerationStrategy(SessionIdGenerationStrategy sessionIdGenerationStrategy) {
Assert.notNull(sessionIdGenerationStrategy, "sessionIdGenerationStrategy cannot be null");
this.sessionIdGenerationStrategy = sessionIdGenerationStrategy;
public void setSessionIdGenerator(SessionIdGenerator sessionIdGenerator) {
Assert.notNull(sessionIdGenerator, "sessionIdGenerator cannot be null");
this.sessionIdGenerator = sessionIdGenerator;
}
private enum DeltaValue {
@@ -787,7 +787,7 @@ public class JdbcIndexedSessionRepository implements
@Override
public String changeSessionId() {
this.changed = true;
String newSessionId = JdbcIndexedSessionRepository.this.sessionIdGenerationStrategy.generate();
String newSessionId = JdbcIndexedSessionRepository.this.sessionIdGenerator.generate();
this.delegate.setId(newSessionId);
return newSessionId;
}

View File

@@ -50,8 +50,8 @@ import org.springframework.session.IndexResolver;
import org.springframework.session.MapSession;
import org.springframework.session.SaveMode;
import org.springframework.session.Session;
import org.springframework.session.SessionIdGenerationStrategy;
import org.springframework.session.UuidSessionIdGenerationStrategy;
import org.springframework.session.SessionIdGenerator;
import org.springframework.session.UuidSessionIdGenerator;
import org.springframework.session.config.SessionRepositoryCustomizer;
import org.springframework.session.config.annotation.web.http.SpringHttpSessionConfiguration;
import org.springframework.session.jdbc.JdbcIndexedSessionRepository;
@@ -111,7 +111,7 @@ public class JdbcHttpSessionConfiguration implements BeanClassLoaderAware, Embed
private StringValueResolver embeddedValueResolver;
private SessionIdGenerationStrategy sessionIdGenerationStrategy = UuidSessionIdGenerationStrategy.getInstance();
private SessionIdGenerator sessionIdGenerator = UuidSessionIdGenerator.getInstance();
@Bean
public JdbcIndexedSessionRepository sessionRepository() {
@@ -148,7 +148,7 @@ public class JdbcHttpSessionConfiguration implements BeanClassLoaderAware, Embed
else {
sessionRepository.setConversionService(createConversionServiceWithBeanClassLoader(this.classLoader));
}
sessionRepository.setSessionIdGenerationStrategy(this.sessionIdGenerationStrategy);
sessionRepository.setSessionIdGenerator(this.sessionIdGenerator);
this.sessionRepositoryCustomizers
.forEach((sessionRepositoryCustomizer) -> sessionRepositoryCustomizer.customize(sessionRepository));
return sessionRepository;
@@ -241,8 +241,8 @@ public class JdbcHttpSessionConfiguration implements BeanClassLoaderAware, Embed
}
@Autowired(required = false)
public void setSessionIdGenerationStrategy(SessionIdGenerationStrategy sessionIdGenerationStrategy) {
this.sessionIdGenerationStrategy = sessionIdGenerationStrategy;
public void setSessionIdGenerator(SessionIdGenerator sessionIdGenerator) {
this.sessionIdGenerator = sessionIdGenerator;
}
@Override

View File

@@ -16,13 +16,13 @@
package org.springframework.session.jdbc;
import org.springframework.session.SessionIdGenerationStrategy;
import org.springframework.session.SessionIdGenerator;
public class FixedSessionIdGenerationStrategy implements SessionIdGenerationStrategy {
public class FixedSessionIdGenerator implements SessionIdGenerator {
private final String id;
public FixedSessionIdGenerationStrategy(String id) {
public FixedSessionIdGenerator(String id) {
this.id = id;
}

View File

@@ -265,8 +265,8 @@ class JdbcIndexedSessionRepositoryTests {
@Test
void setSessionIdGenerationStrategyWhenNullThenException() {
assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setSessionIdGenerationStrategy(null))
.withMessage("sessionIdGenerationStrategy cannot be null");
assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setSessionIdGenerator(null))
.withMessage("sessionIdGenerator cannot be null");
}
@Test
@@ -777,7 +777,7 @@ class JdbcIndexedSessionRepositoryTests {
@Test
void createSessionWhenSessionIdGenerationStrategyThenUses() {
this.repository.setSessionIdGenerationStrategy(() -> "test");
this.repository.setSessionIdGenerator(() -> "test");
JdbcSession session = this.repository.createSession();
assertThat(session.getId()).isEqualTo("test");
assertThat(session.changeSessionId()).isEqualTo("test");
@@ -785,13 +785,13 @@ class JdbcIndexedSessionRepositoryTests {
@Test
void setSessionIdGenerationStrategyWhenNullThenThrowsException() {
assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setSessionIdGenerationStrategy(null))
.withMessage("sessionIdGenerationStrategy cannot be null");
assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setSessionIdGenerator(null))
.withMessage("sessionIdGenerator cannot be null");
}
@Test
void findByIdWhenChangeSessionIdThenUsesSessionIdGenerationStrategy() {
this.repository.setSessionIdGenerationStrategy(() -> "test");
this.repository.setSessionIdGenerator(() -> "test");
Session saved = this.repository.new JdbcSession(new MapSession(), "primaryKey", false);
saved.setAttribute("savedName", "savedValue");
given(this.jdbcOperations.query(isA(String.class), isA(PreparedStatementSetter.class),

View File

@@ -43,10 +43,10 @@ import org.springframework.session.FlushMode;
import org.springframework.session.IndexResolver;
import org.springframework.session.SaveMode;
import org.springframework.session.Session;
import org.springframework.session.SessionIdGenerationStrategy;
import org.springframework.session.UuidSessionIdGenerationStrategy;
import org.springframework.session.SessionIdGenerator;
import org.springframework.session.UuidSessionIdGenerator;
import org.springframework.session.config.SessionRepositoryCustomizer;
import org.springframework.session.jdbc.FixedSessionIdGenerationStrategy;
import org.springframework.session.jdbc.FixedSessionIdGenerator;
import org.springframework.session.jdbc.JdbcIndexedSessionRepository;
import org.springframework.session.jdbc.config.annotation.SpringSessionDataSource;
import org.springframework.test.util.ReflectionTestUtils;
@@ -325,18 +325,18 @@ class JdbcHttpSessionConfigurationTests {
void sessionIdGenerationStrategyWhenCustomBeanThenUses() {
registerAndRefresh(DataSourceConfiguration.class, CustomSessionIdGenerationStrategyConfiguration.class);
JdbcIndexedSessionRepository sessionRepository = this.context.getBean(JdbcIndexedSessionRepository.class);
SessionIdGenerationStrategy sessionIdGenerationStrategy = (SessionIdGenerationStrategy) ReflectionTestUtils
.getField(sessionRepository, "sessionIdGenerationStrategy");
assertThat(sessionIdGenerationStrategy).isInstanceOf(FixedSessionIdGenerationStrategy.class);
SessionIdGenerator sessionIdGenerator = (SessionIdGenerator) ReflectionTestUtils.getField(sessionRepository,
"sessionIdGenerator");
assertThat(sessionIdGenerator).isInstanceOf(FixedSessionIdGenerator.class);
}
@Test
void sessionIdGenerationStrategyWhenNoBeanThenDefault() {
registerAndRefresh(DataSourceConfiguration.class, DefaultConfiguration.class);
JdbcIndexedSessionRepository sessionRepository = this.context.getBean(JdbcIndexedSessionRepository.class);
SessionIdGenerationStrategy sessionIdGenerationStrategy = (SessionIdGenerationStrategy) ReflectionTestUtils
.getField(sessionRepository, "sessionIdGenerationStrategy");
assertThat(sessionIdGenerationStrategy).isInstanceOf(UuidSessionIdGenerationStrategy.class);
SessionIdGenerator sessionIdGenerator = (SessionIdGenerator) ReflectionTestUtils.getField(sessionRepository,
"sessionIdGenerator");
assertThat(sessionIdGenerator).isInstanceOf(UuidSessionIdGenerator.class);
}
private void registerAndRefresh(Class<?>... annotatedClasses) {
@@ -349,8 +349,8 @@ class JdbcHttpSessionConfigurationTests {
static class CustomSessionIdGenerationStrategyConfiguration {
@Bean
SessionIdGenerationStrategy sessionIdGenerationStrategy() {
return new FixedSessionIdGenerationStrategy("my-id");
SessionIdGenerator sessionIdGenerationStrategy() {
return new FixedSessionIdGenerator("my-id");
}
}