Skip to content

Commit 2d4233f

Browse files
Rename SessionIdGenerationStrategy to SessionIdGenerator
Closes spring-projectsgh-2391
1 parent b2615c2 commit 2d4233f

File tree

38 files changed

+269
-286
lines changed

38 files changed

+269
-286
lines changed

spring-session-core/src/main/java/org/springframework/session/MapSession.java

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,7 @@ public final class MapSession implements Session, Serializable {
7474
*/
7575
private Duration maxInactiveInterval = DEFAULT_MAX_INACTIVE_INTERVAL;
7676

77-
private transient SessionIdGenerationStrategy sessionIdGenerationStrategy = UuidSessionIdGenerationStrategy
78-
.getInstance();
77+
private transient SessionIdGenerator sessionIdGenerator = UuidSessionIdGenerator.getInstance();
7978

8079
/**
8180
* Creates a new instance with a secure randomly generated identifier.
@@ -85,14 +84,14 @@ public MapSession() {
8584
}
8685

8786
/**
88-
* Creates a new instance using the specified {@link SessionIdGenerationStrategy} to
89-
* generate the session id.
90-
* @param sessionIdGenerationStrategy the {@link SessionIdGenerationStrategy} to use.
87+
* Creates a new instance using the specified {@link SessionIdGenerator} to generate
88+
* the session id.
89+
* @param sessionIdGenerator the {@link SessionIdGenerator} to use.
9190
* @since 3.2
9291
*/
93-
public MapSession(SessionIdGenerationStrategy sessionIdGenerationStrategy) {
94-
this(sessionIdGenerationStrategy.generate());
95-
this.sessionIdGenerationStrategy = sessionIdGenerationStrategy;
92+
public MapSession(SessionIdGenerator sessionIdGenerator) {
93+
this(sessionIdGenerator.generate());
94+
this.sessionIdGenerator = sessionIdGenerator;
9695
}
9796

9897
/**
@@ -155,7 +154,7 @@ public String getOriginalId() {
155154

156155
@Override
157156
public String changeSessionId() {
158-
String changedId = this.sessionIdGenerationStrategy.generate();
157+
String changedId = this.sessionIdGenerator.generate();
159158
setId(changedId);
160159
return changedId;
161160
}
@@ -247,13 +246,12 @@ private static String generateId() {
247246
}
248247

249248
/**
250-
* Sets the {@link SessionIdGenerationStrategy} to use when generating a new session
251-
* id.
252-
* @param sessionIdGenerationStrategy the {@link SessionIdGenerationStrategy} to use.
249+
* Sets the {@link SessionIdGenerator} to use when generating a new session id.
250+
* @param sessionIdGenerator the {@link SessionIdGenerator} to use.
253251
* @since 3.2
254252
*/
255-
public void setSessionIdGenerationStrategy(SessionIdGenerationStrategy sessionIdGenerationStrategy) {
256-
this.sessionIdGenerationStrategy = sessionIdGenerationStrategy;
253+
public void setSessionIdGenerator(SessionIdGenerator sessionIdGenerator) {
254+
this.sessionIdGenerator = sessionIdGenerator;
257255
}
258256

259257
private static final long serialVersionUID = 7160779239673823561L;

spring-session-core/src/main/java/org/springframework/session/MapSessionRepository.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public class MapSessionRepository implements SessionRepository<MapSession> {
4343

4444
private final Map<String, Session> sessions;
4545

46-
private SessionIdGenerationStrategy sessionIdGenerationStrategy = UuidSessionIdGenerationStrategy.getInstance();
46+
private SessionIdGenerator sessionIdGenerator = UuidSessionIdGenerator.getInstance();
4747

4848
/**
4949
* Creates a new instance backed by the provided {@link java.util.Map}. This allows
@@ -74,7 +74,7 @@ public void save(MapSession session) {
7474
this.sessions.remove(session.getOriginalId());
7575
}
7676
MapSession saved = new MapSession(session);
77-
saved.setSessionIdGenerationStrategy(this.sessionIdGenerationStrategy);
77+
saved.setSessionIdGenerator(this.sessionIdGenerator);
7878
this.sessions.put(session.getId(), saved);
7979
}
8080

@@ -89,7 +89,7 @@ public MapSession findById(String id) {
8989
return null;
9090
}
9191
MapSession result = new MapSession(saved);
92-
result.setSessionIdGenerationStrategy(this.sessionIdGenerationStrategy);
92+
result.setSessionIdGenerator(this.sessionIdGenerator);
9393
return result;
9494
}
9595

@@ -100,14 +100,14 @@ public void deleteById(String id) {
100100

101101
@Override
102102
public MapSession createSession() {
103-
MapSession result = new MapSession(this.sessionIdGenerationStrategy);
103+
MapSession result = new MapSession(this.sessionIdGenerator);
104104
result.setMaxInactiveInterval(this.defaultMaxInactiveInterval);
105105
return result;
106106
}
107107

108-
public void setSessionIdGenerationStrategy(SessionIdGenerationStrategy sessionIdGenerationStrategy) {
109-
Assert.notNull(sessionIdGenerationStrategy, "sessionIdGenerationStrategy cannot be null");
110-
this.sessionIdGenerationStrategy = sessionIdGenerationStrategy;
108+
public void setSessionIdGenerator(SessionIdGenerator sessionIdGenerator) {
109+
Assert.notNull(sessionIdGenerator, "sessionIdGenerator cannot be null");
110+
this.sessionIdGenerator = sessionIdGenerator;
111111
}
112112

113113
}

spring-session-core/src/main/java/org/springframework/session/ReactiveMapSessionRepository.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public class ReactiveMapSessionRepository implements ReactiveSessionRepository<M
4545

4646
private final Map<String, Session> sessions;
4747

48-
private SessionIdGenerationStrategy sessionIdGenerationStrategy = UuidSessionIdGenerationStrategy.getInstance();
48+
private SessionIdGenerator sessionIdGenerator = UuidSessionIdGenerator.getInstance();
4949

5050
/**
5151
* Creates a new instance backed by the provided {@link Map}. This allows injecting a
@@ -86,7 +86,7 @@ public Mono<MapSession> findById(String id) {
8686
return Mono.defer(() -> Mono.justOrEmpty(this.sessions.get(id))
8787
.filter((session) -> !session.isExpired())
8888
.map(MapSession::new)
89-
.doOnNext((session) -> session.setSessionIdGenerationStrategy(this.sessionIdGenerationStrategy))
89+
.doOnNext((session) -> session.setSessionIdGenerator(this.sessionIdGenerator))
9090
.switchIfEmpty(deleteById(id).then(Mono.empty())));
9191
// @formatter:on
9292
}
@@ -99,21 +99,20 @@ public Mono<Void> deleteById(String id) {
9999
@Override
100100
public Mono<MapSession> createSession() {
101101
return Mono.defer(() -> {
102-
MapSession result = new MapSession(this.sessionIdGenerationStrategy);
102+
MapSession result = new MapSession(this.sessionIdGenerator);
103103
result.setMaxInactiveInterval(this.defaultMaxInactiveInterval);
104104
return Mono.just(result);
105105
});
106106
}
107107

108108
/**
109-
* Sets the {@link SessionIdGenerationStrategy} to use.
110-
* @param sessionIdGenerationStrategy the non-null {@link SessionIdGenerationStrategy}
111-
* to use
109+
* Sets the {@link SessionIdGenerator} to use.
110+
* @param sessionIdGenerator the non-null {@link SessionIdGenerator} to use
112111
* @since 3.2
113112
*/
114-
public void setSessionIdGenerationStrategy(SessionIdGenerationStrategy sessionIdGenerationStrategy) {
115-
Assert.notNull(sessionIdGenerationStrategy, "sessionIdGenerationStrategy cannot be null");
116-
this.sessionIdGenerationStrategy = sessionIdGenerationStrategy;
113+
public void setSessionIdGenerator(SessionIdGenerator sessionIdGenerator) {
114+
Assert.notNull(sessionIdGenerator, "sessionIdGenerator cannot be null");
115+
this.sessionIdGenerator = sessionIdGenerator;
117116
}
118117

119118
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
* @author Marcus da Coregio
2525
* @since 3.2
2626
*/
27-
public interface SessionIdGenerationStrategy {
27+
public interface SessionIdGenerator {
2828

2929
@NonNull
3030
String generate();
Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,16 @@
2121
import org.springframework.lang.NonNull;
2222

2323
/**
24-
* A {@link SessionIdGenerationStrategy} that generates a random UUID to be used as the
25-
* session id.
24+
* A {@link SessionIdGenerator} that generates a random UUID to be used as the session id.
2625
*
2726
* @author Marcus da Coregio
2827
* @since 3.2
2928
*/
30-
public final class UuidSessionIdGenerationStrategy implements SessionIdGenerationStrategy {
29+
public final class UuidSessionIdGenerator implements SessionIdGenerator {
3130

32-
private static final UuidSessionIdGenerationStrategy INSTANCE = new UuidSessionIdGenerationStrategy();
31+
private static final UuidSessionIdGenerator INSTANCE = new UuidSessionIdGenerator();
3332

34-
private UuidSessionIdGenerationStrategy() {
33+
private UuidSessionIdGenerator() {
3534
}
3635

3736
@Override
@@ -41,10 +40,10 @@ public String generate() {
4140
}
4241

4342
/**
44-
* Returns the singleton instance of {@link UuidSessionIdGenerationStrategy}.
45-
* @return the singleton instance of {@link UuidSessionIdGenerationStrategy}
43+
* Returns the singleton instance of {@link UuidSessionIdGenerator}.
44+
* @return the singleton instance of {@link UuidSessionIdGenerator}
4645
*/
47-
public static UuidSessionIdGenerationStrategy getInstance() {
46+
public static UuidSessionIdGenerator getInstance() {
4847
return INSTANCE;
4948
}
5049

spring-session-core/src/test/java/org/springframework/session/MapSessionTests.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ void constructorNullSession() {
4545

4646
@Test
4747
void constructorWhenSessionIdGenerationStrategyThenUsesStrategy() {
48-
MapSession session = new MapSession(new FixedSessionIdGenerationStrategy("my-id"));
48+
MapSession session = new MapSession(new FixedSessionIdGenerator("my-id"));
4949
assertThat(session.getId()).isEqualTo("my-id");
5050
}
5151

@@ -159,18 +159,18 @@ void getAttributeNamesAndRemove() {
159159

160160
@Test
161161
void changeSessionIdWhenSessionIdStrategyThenUsesStrategy() {
162-
MapSession session = new MapSession(new IncrementalSessionIdGenerationStrategy());
162+
MapSession session = new MapSession(new IncrementalSessionIdGenerator());
163163
String idBeforeChange = session.getId();
164164
String idAfterChange = session.changeSessionId();
165165
assertThat(idBeforeChange).isEqualTo("1");
166166
assertThat(idAfterChange).isEqualTo("2");
167167
}
168168

169-
static class FixedSessionIdGenerationStrategy implements SessionIdGenerationStrategy {
169+
static class FixedSessionIdGenerator implements SessionIdGenerator {
170170

171171
private final String id;
172172

173-
FixedSessionIdGenerationStrategy(String id) {
173+
FixedSessionIdGenerator(String id) {
174174
this.id = id;
175175
}
176176

@@ -181,7 +181,7 @@ public String generate() {
181181

182182
}
183183

184-
static class IncrementalSessionIdGenerationStrategy implements SessionIdGenerationStrategy {
184+
static class IncrementalSessionIdGenerator implements SessionIdGenerator {
185185

186186
private int counter = 1;
187187

spring-session-core/src/test/java/org/springframework/session/ReactiveMapSessionRepositoryTests.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,21 +154,21 @@ void getAttributeNamesAndRemove() {
154154

155155
@Test
156156
void createSessionWhenSessionIdGenerationStrategyThenUses() {
157-
this.repository.setSessionIdGenerationStrategy(() -> "test");
157+
this.repository.setSessionIdGenerator(() -> "test");
158158
MapSession session = this.repository.createSession().block();
159159
assertThat(session.getId()).isEqualTo("test");
160160
assertThat(session.changeSessionId()).isEqualTo("test");
161161
}
162162

163163
@Test
164164
void setSessionIdGenerationStrategyWhenNullThenThrowsException() {
165-
assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setSessionIdGenerationStrategy(null))
166-
.withMessage("sessionIdGenerationStrategy cannot be null");
165+
assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setSessionIdGenerator(null))
166+
.withMessage("sessionIdGenerator cannot be null");
167167
}
168168

169169
@Test
170170
void findByIdWhenChangeSessionIdThenUsesSessionIdGenerationStrategy() {
171-
this.repository.setSessionIdGenerationStrategy(() -> "test");
171+
this.repository.setSessionIdGenerator(() -> "test");
172172

173173
MapSession session = this.repository.createSession().block();
174174
this.repository.save(session).block();

spring-session-data-mongodb/src/main/java/org/springframework/session/data/mongo/MongoIndexedSessionRepository.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@
3636
import org.springframework.lang.Nullable;
3737
import org.springframework.session.FindByIndexNameSessionRepository;
3838
import org.springframework.session.MapSession;
39-
import org.springframework.session.SessionIdGenerationStrategy;
40-
import org.springframework.session.UuidSessionIdGenerationStrategy;
39+
import org.springframework.session.SessionIdGenerator;
40+
import org.springframework.session.UuidSessionIdGenerator;
4141
import org.springframework.session.events.SessionCreatedEvent;
4242
import org.springframework.session.events.SessionDeletedEvent;
4343
import org.springframework.session.events.SessionExpiredEvent;
@@ -83,7 +83,7 @@ public class MongoIndexedSessionRepository
8383

8484
private ApplicationEventPublisher eventPublisher;
8585

86-
private SessionIdGenerationStrategy sessionIdGenerationStrategy = UuidSessionIdGenerationStrategy.getInstance();
86+
private SessionIdGenerator sessionIdGenerator = UuidSessionIdGenerator.getInstance();
8787

8888
public MongoIndexedSessionRepository(MongoOperations mongoOperations) {
8989
this.mongoOperations = mongoOperations;
@@ -92,7 +92,7 @@ public MongoIndexedSessionRepository(MongoOperations mongoOperations) {
9292
@Override
9393
public MongoSession createSession() {
9494

95-
MongoSession session = new MongoSession(this.sessionIdGenerationStrategy);
95+
MongoSession session = new MongoSession(this.sessionIdGenerator);
9696

9797
session.setMaxInactiveInterval(this.defaultMaxInactiveInterval);
9898

@@ -126,7 +126,7 @@ public MongoSession findById(String id) {
126126
deleteById(id);
127127
return null;
128128
}
129-
session.setSessionIdGenerationStrategy(this.sessionIdGenerationStrategy);
129+
session.setSessionIdGenerator(this.sessionIdGenerator);
130130
}
131131

132132
return session;
@@ -147,7 +147,7 @@ public Map<String, MongoSession> findByIndexNameAndIndexValue(String indexName,
147147
.map((query) -> this.mongoOperations.find(query, Document.class, this.collectionName))
148148
.orElse(Collections.emptyList()).stream()
149149
.map((dbSession) -> MongoSessionUtils.convertToSession(this.mongoSessionConverter, dbSession))
150-
.peek((session) -> session.setSessionIdGenerationStrategy(this.sessionIdGenerationStrategy))
150+
.peek((session) -> session.setSessionIdGenerator(this.sessionIdGenerator))
151151
.collect(Collectors.toMap(MongoSession::getId, (mapSession) -> mapSession));
152152
}
153153

@@ -225,13 +225,13 @@ public void setMongoSessionConverter(final AbstractMongoSessionConverter mongoSe
225225
}
226226

227227
/**
228-
* Set the {@link SessionIdGenerationStrategy} to use to generate session ids.
229-
* @param sessionIdGenerationStrategy the {@link SessionIdGenerationStrategy} to use
228+
* Set the {@link SessionIdGenerator} to use to generate session ids.
229+
* @param sessionIdGenerator the {@link SessionIdGenerator} to use
230230
* @since 3.2
231231
*/
232-
public void setSessionIdGenerationStrategy(SessionIdGenerationStrategy sessionIdGenerationStrategy) {
233-
Assert.notNull(sessionIdGenerationStrategy, "sessionIdGenerationStrategy cannot be null");
234-
this.sessionIdGenerationStrategy = sessionIdGenerationStrategy;
232+
public void setSessionIdGenerator(SessionIdGenerator sessionIdGenerator) {
233+
Assert.notNull(sessionIdGenerator, "sessionIdGenerator cannot be null");
234+
this.sessionIdGenerator = sessionIdGenerator;
235235
}
236236

237237
}

0 commit comments

Comments
 (0)