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