Rename SessionIdGenerationStrategy to SessionIdGenerator
Closes gh-2391
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user