diff --git a/spring-session-core/src/main/java/org/springframework/session/MapSession.java b/spring-session-core/src/main/java/org/springframework/session/MapSession.java index 1b1d91b10..00b2a92d4 100644 --- a/spring-session-core/src/main/java/org/springframework/session/MapSession.java +++ b/spring-session-core/src/main/java/org/springframework/session/MapSession.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2022 the original author or authors. + * Copyright 2014-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,7 +23,6 @@ import java.util.HashSet; import java.util.Map; import java.util.Set; -import java.util.UUID; /** *

@@ -44,6 +43,7 @@ * * @author Rob Winch * @author Vedran Pavic + * @author Yanming Zhou * @since 1.0 */ public final class MapSession implements Session, Serializable { @@ -81,7 +81,7 @@ public final class MapSession implements Session, Serializable { * Creates a new instance with a secure randomly generated identifier. */ public MapSession() { - this(generateId()); + this(UuidSessionIdGenerationStrategy.getInstance()); } /** @@ -242,10 +242,6 @@ public int hashCode() { return this.id.hashCode(); } - private static String generateId() { - return UUID.randomUUID().toString(); - } - /** * Sets the {@link SessionIdGenerationStrategy} to use when generating a new session * id. diff --git a/spring-session-jdbc/src/main/java/org/springframework/session/jdbc/JdbcIndexedSessionRepository.java b/spring-session-jdbc/src/main/java/org/springframework/session/jdbc/JdbcIndexedSessionRepository.java index 5c40be5ca..e8d42dd07 100644 --- a/spring-session-jdbc/src/main/java/org/springframework/session/jdbc/JdbcIndexedSessionRepository.java +++ b/spring-session-jdbc/src/main/java/org/springframework/session/jdbc/JdbcIndexedSessionRepository.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2022 the original author or authors. + * Copyright 2014-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,7 +27,6 @@ import java.util.List; import java.util.Map; import java.util.Set; -import java.util.UUID; import java.util.function.Supplier; import java.util.stream.Collectors; @@ -136,6 +135,7 @@ * * @author Vedran Pavic * @author Craig Andrews + * @author Yanming Zhou * @since 2.2.0 */ public class JdbcIndexedSessionRepository implements @@ -467,7 +467,7 @@ public void setCleanupCron(String cleanupCron) { public JdbcSession createSession() { MapSession delegate = new MapSession(this.sessionIdGenerationStrategy); delegate.setMaxInactiveInterval(this.defaultMaxInactiveInterval); - JdbcSession session = new JdbcSession(delegate, UUID.randomUUID().toString(), true); + JdbcSession session = new JdbcSession(delegate, delegate.getId(), true); session.flushIfRequired(); return session; }