From 009cb5b5926f2838dcb3d43a28f3eaab2412af8d Mon Sep 17 00:00:00 2001 From: Vedran Pavic Date: Fri, 7 Oct 2022 11:14:01 +0200 Subject: [PATCH] Fix max inactive interval setters backwards compatibility This commit restores integer based max inactive interval setters across all session repositories, that were migrated to java.time in 6d74cf5f. This change caused problems building our Spring Boot based samples, as Spring Boot auto-configuration has move to session repository customizer based approach and is therefore using max inactive interval setters directly on session repository implementations. --- .../data/mongo/MongoIndexedSessionRepository.java | 13 +++++++++++++ .../data/mongo/ReactiveMongoSessionRepository.java | 13 +++++++++++++ .../data/redis/ReactiveRedisSessionRepository.java | 13 +++++++++++++ .../data/redis/RedisIndexedSessionRepository.java | 13 +++++++++++++ .../HazelcastIndexedSessionRepository.java | 13 +++++++++++++ .../session/jdbc/JdbcIndexedSessionRepository.java | 13 +++++++++++++ 6 files changed, 78 insertions(+) diff --git a/spring-session-data-mongodb/src/main/java/org/springframework/session/data/mongo/MongoIndexedSessionRepository.java b/spring-session-data-mongodb/src/main/java/org/springframework/session/data/mongo/MongoIndexedSessionRepository.java index 8a7b4ec4..301eacaf 100644 --- a/spring-session-data-mongodb/src/main/java/org/springframework/session/data/mongo/MongoIndexedSessionRepository.java +++ b/spring-session-data-mongodb/src/main/java/org/springframework/session/data/mongo/MongoIndexedSessionRepository.java @@ -193,6 +193,19 @@ public class MongoIndexedSessionRepository this.defaultMaxInactiveInterval = defaultMaxInactiveInterval; } + /** + * Set the maximum inactive interval in seconds between requests before newly created + * sessions will be invalidated. A negative time indicates that the session will never + * time out. The default is 1800 (30 minutes). + * @param defaultMaxInactiveInterval the default maxInactiveInterval in seconds + * @deprecated since 3.0.0, in favor of + * {@link #setDefaultMaxInactiveInterval(Duration)} + */ + @Deprecated(since = "3.0.0") + public void setMaxInactiveIntervalInSeconds(Integer defaultMaxInactiveInterval) { + setDefaultMaxInactiveInterval(Duration.ofSeconds(defaultMaxInactiveInterval)); + } + public void setCollectionName(final String collectionName) { this.collectionName = collectionName; } diff --git a/spring-session-data-mongodb/src/main/java/org/springframework/session/data/mongo/ReactiveMongoSessionRepository.java b/spring-session-data-mongodb/src/main/java/org/springframework/session/data/mongo/ReactiveMongoSessionRepository.java index fc6bf62f..71c06c35 100644 --- a/spring-session-data-mongodb/src/main/java/org/springframework/session/data/mongo/ReactiveMongoSessionRepository.java +++ b/spring-session-data-mongodb/src/main/java/org/springframework/session/data/mongo/ReactiveMongoSessionRepository.java @@ -187,6 +187,19 @@ public class ReactiveMongoSessionRepository this.defaultMaxInactiveInterval = defaultMaxInactiveInterval; } + /** + * Set the maximum inactive interval in seconds between requests before newly created + * sessions will be invalidated. A negative time indicates that the session will never + * time out. The default is 1800 (30 minutes). + * @param defaultMaxInactiveInterval the default maxInactiveInterval in seconds + * @deprecated since 3.0.0, in favor of + * {@link #setDefaultMaxInactiveInterval(Duration)} + */ + @Deprecated(since = "3.0.0") + public void setMaxInactiveIntervalInSeconds(Integer defaultMaxInactiveInterval) { + setDefaultMaxInactiveInterval(Duration.ofSeconds(defaultMaxInactiveInterval)); + } + public String getCollectionName() { return this.collectionName; } diff --git a/spring-session-data-redis/src/main/java/org/springframework/session/data/redis/ReactiveRedisSessionRepository.java b/spring-session-data-redis/src/main/java/org/springframework/session/data/redis/ReactiveRedisSessionRepository.java index f91015ca..0ffb43e3 100644 --- a/spring-session-data-redis/src/main/java/org/springframework/session/data/redis/ReactiveRedisSessionRepository.java +++ b/spring-session-data-redis/src/main/java/org/springframework/session/data/redis/ReactiveRedisSessionRepository.java @@ -85,6 +85,19 @@ public class ReactiveRedisSessionRepository this.defaultMaxInactiveInterval = defaultMaxInactiveInterval; } + /** + * Set the maximum inactive interval in seconds between requests before newly created + * sessions will be invalidated. A negative time indicates that the session will never + * time out. The default is 1800 (30 minutes). + * @param defaultMaxInactiveInterval the default maxInactiveInterval in seconds + * @deprecated since 3.0.0, in favor of + * {@link #setDefaultMaxInactiveInterval(Duration)} + */ + @Deprecated(since = "3.0.0") + public void setDefaultMaxInactiveInterval(int defaultMaxInactiveInterval) { + setDefaultMaxInactiveInterval(Duration.ofSeconds(defaultMaxInactiveInterval)); + } + /** * Set the save mode. * @param saveMode the save mode diff --git a/spring-session-data-redis/src/main/java/org/springframework/session/data/redis/RedisIndexedSessionRepository.java b/spring-session-data-redis/src/main/java/org/springframework/session/data/redis/RedisIndexedSessionRepository.java index 3c03beb0..6456811d 100644 --- a/spring-session-data-redis/src/main/java/org/springframework/session/data/redis/RedisIndexedSessionRepository.java +++ b/spring-session-data-redis/src/main/java/org/springframework/session/data/redis/RedisIndexedSessionRepository.java @@ -379,6 +379,19 @@ public class RedisIndexedSessionRepository this.defaultMaxInactiveInterval = defaultMaxInactiveInterval; } + /** + * Set the maximum inactive interval in seconds between requests before newly created + * sessions will be invalidated. A negative time indicates that the session will never + * time out. The default is 1800 (30 minutes). + * @param defaultMaxInactiveInterval the default maxInactiveInterval in seconds + * @deprecated since 3.0.0, in favor of + * {@link #setDefaultMaxInactiveInterval(Duration)} + */ + @Deprecated(since = "3.0.0") + public void setDefaultMaxInactiveInterval(int defaultMaxInactiveInterval) { + setDefaultMaxInactiveInterval(Duration.ofSeconds(defaultMaxInactiveInterval)); + } + /** * Set the {@link IndexResolver} to use. * @param indexResolver the index resolver diff --git a/spring-session-hazelcast/src/main/java/org/springframework/session/hazelcast/HazelcastIndexedSessionRepository.java b/spring-session-hazelcast/src/main/java/org/springframework/session/hazelcast/HazelcastIndexedSessionRepository.java index 851197d3..d9be431b 100644 --- a/spring-session-hazelcast/src/main/java/org/springframework/session/hazelcast/HazelcastIndexedSessionRepository.java +++ b/spring-session-hazelcast/src/main/java/org/springframework/session/hazelcast/HazelcastIndexedSessionRepository.java @@ -194,6 +194,19 @@ public class HazelcastIndexedSessionRepository this.defaultMaxInactiveInterval = defaultMaxInactiveInterval; } + /** + * Set the maximum inactive interval in seconds between requests before newly created + * sessions will be invalidated. A negative time indicates that the session will never + * time out. The default is 1800 (30 minutes). + * @param defaultMaxInactiveInterval the default maxInactiveInterval in seconds + * @deprecated since 3.0.0, in favor of + * {@link #setDefaultMaxInactiveInterval(Duration)} + */ + @Deprecated(since = "3.0.0") + public void setDefaultMaxInactiveInterval(Integer defaultMaxInactiveInterval) { + setDefaultMaxInactiveInterval(Duration.ofSeconds(defaultMaxInactiveInterval)); + } + /** * Set the {@link IndexResolver} to use. * @param indexResolver the index resolver 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 3a2e929e..1d12c160 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 @@ -390,6 +390,19 @@ public class JdbcIndexedSessionRepository implements this.defaultMaxInactiveInterval = defaultMaxInactiveInterval; } + /** + * Set the maximum inactive interval in seconds between requests before newly created + * sessions will be invalidated. A negative time indicates that the session will never + * time out. The default is 1800 (30 minutes). + * @param defaultMaxInactiveInterval the default maxInactiveInterval in seconds + * @deprecated since 3.0.0, in favor of + * {@link #setDefaultMaxInactiveInterval(Duration)} + */ + @Deprecated(since = "3.0.0") + public void setDefaultMaxInactiveInterval(Integer defaultMaxInactiveInterval) { + setDefaultMaxInactiveInterval(Duration.ofSeconds(defaultMaxInactiveInterval)); + } + /** * Set the {@link IndexResolver} to use. * @param indexResolver the index resolver