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

@@ -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() {