From 42934abcc1efa8887a592696adb8e65dec2a1532 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 8a7b4ec48..301eacaf2 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 void setDefaultMaxInactiveInterval(Duration defaultMaxInactiveInterval) { 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 fc6bf62fb..71c06c351 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 void setDefaultMaxInactiveInterval(Duration defaultMaxInactiveInterval) { 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 f91015ca0..0ffb43e38 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 void setDefaultMaxInactiveInterval(Duration defaultMaxInactiveInterval) { 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 3c03beb07..6456811d4 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 void setDefaultMaxInactiveInterval(Duration defaultMaxInactiveInterval) { 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 851197d3a..d9be431ba 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 void setDefaultMaxInactiveInterval(Duration defaultMaxInactiveInterval) { 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 3a2e929ea..1d12c1607 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 void setDefaultMaxInactiveInterval(Duration defaultMaxInactiveInterval) { 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