Skip to content

Optimize the usage of JacksonMongoSessionConverter to prevent duplica… #3186

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 132 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
132 commits
Select commit Hold shift + click to select a range
4395179
Prepare for 3.4
marcusdacoregio Jun 3, 2024
df62015
Bump spring-io/spring-doc-actions
dependabot[bot] May 27, 2024
a1af0ad
Merge branch '3.3.x'
marcusdacoregio Jun 4, 2024
77b3366
Bump io.spring.javaformat:spring-javaformat-gradle-plugin
dependabot[bot] Jun 10, 2024
2ceb6cb
Bump io.spring.javaformat:spring-javaformat-checkstyle
dependabot[bot] Jun 10, 2024
44b083e
Bump org.jfrog.buildinfo:build-info-extractor-gradle
dependabot[bot] Jun 10, 2024
e0e4c78
Merge branch '3.2.x'
github-actions[bot] Jun 10, 2024
1023b12
Merge branch '3.3.x'
github-actions[bot] Jun 10, 2024
c3cfa2e
Bump io.projectreactor:reactor-core from 3.6.6 to 3.6.7
dependabot[bot] Jun 12, 2024
180cf31
Bump io.projectreactor:reactor-bom from 2023.0.6 to 2023.0.7
dependabot[bot] Jun 12, 2024
622e4f8
Merge branch '3.3.x'
github-actions[bot] Jun 12, 2024
45d684c
Merge branch '3.3.x'
github-actions[bot] Jun 12, 2024
7305712
Merge branch '3.3.x'
github-actions[bot] Jun 13, 2024
0c1c0eb
Merge branch '3.3.x'
github-actions[bot] Jun 13, 2024
f6ca2c4
Bump com.gradle.develocity from 3.17.4 to 3.17.5
dependabot[bot] Jun 13, 2024
60efefd
Upgrade to Spring Framework 6.2.0-M4
marcusdacoregio Jun 13, 2024
5dc161d
Add Partitioned Cookie Support to DefaultCookieSerializer
marcusdacoregio Jun 13, 2024
30a08ef
Merge branch '3.3.x'
github-actions[bot] Jun 14, 2024
7a628e2
Merge branch '3.3.x'
github-actions[bot] Jun 14, 2024
dd88ca9
Merge branch '3.3.x'
github-actions[bot] Jun 17, 2024
9471efb
Merge branch '3.3.x'
github-actions[bot] Jun 17, 2024
3bf3468
Fix javadoc
marcusdacoregio Jun 17, 2024
a7fe5e1
Make MongoSession public final
Jun 17, 2024
c121166
Merge branch '3.3.x'
github-actions[bot] Jun 18, 2024
66d876a
Merge branch '3.3.x'
github-actions[bot] Jun 18, 2024
1130bec
Merge branch '3.3.x'
github-actions[bot] Jun 18, 2024
6dd7ed1
Include 3.3.x in release-scheduler.yml
marcusdacoregio Jun 18, 2024
3733807
Merge branch '3.3.x'
marcusdacoregio Jun 18, 2024
834a803
Merge branch '3.3.x'
marcusdacoregio Jun 18, 2024
95de201
Include npm updates for docs-build
marcusdacoregio Jun 18, 2024
e8aab30
Merge branch '3.3.x'
github-actions[bot] Jun 20, 2024
c926d45
Merge branch '3.3.x'
github-actions[bot] Jun 20, 2024
b8a633f
Merge branch '3.3.x'
github-actions[bot] Jun 21, 2024
330656e
Merge branch '3.3.x'
github-actions[bot] Jun 21, 2024
8f7aa95
Merge branch '3.3.x'
github-actions[bot] Jun 24, 2024
7b88ac0
Merge branch '3.3.x'
github-actions[bot] Jun 24, 2024
a8f8a54
Update to Spring Security 6.4.0-SNAPSHOT
marcusdacoregio Jun 25, 2024
8bcabe5
Bump org.springframework.data:spring-data-bom from 2024.0.0 to 2024.0.1
dependabot[bot] Jun 25, 2024
cb92fe6
Bump org.skyscreamer:jsonassert from 1.5.1 to 1.5.2
dependabot[bot] Jun 26, 2024
06d29ac
Merge branch '3.3.x'
github-actions[bot] Jun 28, 2024
c413705
Bump org.junit:junit-bom from 5.10.2 to 5.10.3
dependabot[bot] Jun 28, 2024
fbdd6d3
Bump org-springframework-boot from 3.2.6 to 3.2.7
dependabot[bot] Jun 28, 2024
9c5299c
Bump org.skyscreamer:jsonassert from 1.5.2 to 1.5.3
dependabot[bot] Jul 1, 2024
fac2f86
Merge branch '3.3.x'
github-actions[bot] Jul 1, 2024
96c4b4c
Bump spring-io/spring-doc-actions
dependabot[bot] Jun 28, 2024
5d6540b
Bump org.jfrog.buildinfo:build-info-extractor-gradle
dependabot[bot] Jun 28, 2024
da14f79
Merge branch '3.3.x'
github-actions[bot] Jul 8, 2024
7356a9a
Bump com.fasterxml.jackson:jackson-bom from 2.17.1 to 2.17.2
dependabot[bot] Jul 8, 2024
e4945d2
Bump com.github.spullara.mustache.java:compiler from 0.9.13 to 0.9.14
dependabot[bot] Jul 8, 2024
0f44f59
Bump com.fasterxml.jackson.core:jackson-databind from 2.17.1 to 2.17.2
dependabot[bot] Jul 8, 2024
0f9c9cc
Merge branch '3.3.x'
github-actions[bot] Jul 8, 2024
887b69c
Merge branch '3.3.x'
github-actions[bot] Jul 8, 2024
16f9c4c
Bump io.spring.gradle:dependency-management-plugin from 1.1.5 to 1.1.6
dependabot[bot] Jul 9, 2024
d5ab618
Merge branch '3.3.x'
github-actions[bot] Jul 10, 2024
613077a
Bump io.projectreactor:reactor-bom from 2023.0.7 to 2023.0.8
dependabot[bot] Jul 10, 2024
ff6dbf5
Bump io.projectreactor:reactor-core from 3.6.7 to 3.6.8
dependabot[bot] Jul 10, 2024
3d47cb0
Merge branch '3.3.x'
github-actions[bot] Jul 10, 2024
f2c9df9
Merge branch '3.3.x'
github-actions[bot] Jul 10, 2024
5f65ff9
Merge branch '3.3.x'
marcusdacoregio Jul 10, 2024
62f7d71
Merge branch '3.3.x'
github-actions[bot] Jul 12, 2024
be530f9
Merge branch '3.3.x'
github-actions[bot] Jul 12, 2024
c8b50fb
Merge branch '3.3.x'
github-actions[bot] Jul 12, 2024
f15cf20
Merge branch '3.3.x'
github-actions[bot] Jul 15, 2024
6721b80
Bump org.springframework.data:spring-data-bom from 2024.0.1 to 2024.0.2
dependabot[bot] Jul 15, 2024
640032f
Merge branch '3.3.x'
github-actions[bot] Jul 15, 2024
9c487a5
Release 3.4.0-M1
github-actions[bot] Jul 16, 2024
6c49206
Revert "Release 3.4.0-M1"
marcusdacoregio Jul 16, 2024
8cf11eb
Update to Spring Security 6.4.0-M1
marcusdacoregio Jul 16, 2024
9dc7716
Release 3.4.0-M1
marcusdacoregio Jul 16, 2024
2e7b968
Next development version
github-actions[bot] Jul 16, 2024
a86bcf8
Bump org.springframework.security:spring-security-bom
dependabot[bot] Jul 17, 2024
212e316
Merge branch '3.3.x'
github-actions[bot] Jul 18, 2024
490c3ae
Bump org-springframework-boot from 3.2.7 to 3.2.8
dependabot[bot] Jul 19, 2024
230a9f1
Merge branch '3.3.x'
github-actions[bot] Jul 19, 2024
e53b9ec
Merge branch '3.3.x'
github-actions[bot] Jul 19, 2024
733aafc
Bump com.gradle.develocity from 3.17.5 to 3.17.6
dependabot[bot] Jul 23, 2024
4c7ce0b
Merge branch '3.3.x'
github-actions[bot] Jul 23, 2024
f55e673
Merge branch '3.3.x'
marcusdacoregio Jul 26, 2024
79f5b5f
Merge branch '3.3.x'
github-actions[bot] Aug 5, 2024
4ebfd6b
Merge branch '3.3.x'
github-actions[bot] Aug 7, 2024
abef70e
Bump org-slf4j from 2.0.13 to 2.0.14
dependabot[bot] Aug 7, 2024
7f97f67
Merge branch '3.3.x'
github-actions[bot] Aug 7, 2024
38a3b31
Update to Spring Boot 3.3.1
marcusdacoregio Aug 5, 2024
c58065f
Bump org-springframework-boot from 3.3.1 to 3.3.2
dependabot[bot] Aug 8, 2024
d31d5f9
Merge branch '3.3.x'
github-actions[bot] Aug 8, 2024
b56a37c
Merge branch '3.3.x'
github-actions[bot] Aug 9, 2024
c50a34f
Bump org-slf4j from 2.0.14 to 2.0.15
dependabot[bot] Aug 9, 2024
af27c22
Merge branch '3.3.x'
github-actions[bot] Aug 9, 2024
a3f1141
Bump org.awaitility:awaitility from 4.2.1 to 4.2.2
dependabot[bot] Aug 9, 2024
4536030
Merge branch '3.3.x'
github-actions[bot] Aug 12, 2024
5ff6501
Merge branch '3.3.x'
github-actions[bot] Aug 12, 2024
af37d93
Allow minor version updates
marcusdacoregio Aug 12, 2024
84f4afc
Introduce RedisSessionExpirationStore
marcusdacoregio Aug 5, 2024
78784e7
Merge branch '3.3.x'
github-actions[bot] Aug 14, 2024
b3d20e8
Merge branch '3.3.x'
github-actions[bot] Aug 14, 2024
f5b00fc
Merge branch '3.3.x'
github-actions[bot] Aug 14, 2024
6a9c906
Bump io.projectreactor:reactor-bom from 2023.0.8 to 2023.0.9
dependabot[bot] Aug 14, 2024
20df163
Bump io.spring.javaformat:spring-javaformat-gradle-plugin
dependabot[bot] Aug 14, 2024
6553415
Merge branch '3.3.x'
github-actions[bot] Aug 15, 2024
bdd5501
Merge branch '3.3.x'
github-actions[bot] Aug 15, 2024
58e67fb
Bump io.projectreactor:reactor-core from 3.6.8 to 3.6.9
dependabot[bot] Aug 15, 2024
2b845ef
Merge branch '3.3.x'
marcusdacoregio Aug 15, 2024
d3a759d
Merge branch '3.3.x'
github-actions[bot] Aug 15, 2024
0a2751c
Bump jakarta.servlet.jsp.jstl:jakarta.servlet.jsp.jstl-api
dependabot[bot] Aug 15, 2024
d7a7ce6
Bump ch-qos-logback from 1.5.6 to 1.5.7
dependabot[bot] Aug 16, 2024
5306b32
Merge branch '3.3.x'
github-actions[bot] Aug 16, 2024
aa5f203
Bump org.springframework.data:spring-data-bom from 2024.0.2 to 2024.0.3
dependabot[bot] Aug 19, 2024
e38ce2f
Bump org-slf4j from 2.0.15 to 2.0.16
dependabot[bot] Aug 19, 2024
b4b43f6
Merge branch '3.3.x'
github-actions[bot] Aug 19, 2024
bbdbecd
Merge branch '3.3.x'
github-actions[bot] Aug 19, 2024
f606445
Merge branch '3.3.x'
github-actions[bot] Aug 20, 2024
f02cc18
Merge branch '3.3.x'
github-actions[bot] Aug 20, 2024
520abe5
Release 3.4.0-M2
github-actions[bot] Aug 20, 2024
77ef35e
Revert "Release 3.4.0-M2"
marcusdacoregio Aug 20, 2024
a2ad277
Update to Spring Security 6.4.0-M2
marcusdacoregio Aug 20, 2024
5a40c5b
Release 3.4.0-M2
marcusdacoregio Aug 20, 2024
fad05fa
Next development version
github-actions[bot] Aug 20, 2024
60a02c6
Merge branch '3.3.x'
marcusdacoregio Aug 20, 2024
4fbd3ee
Bump org.springframework.security:spring-security-bom
dependabot[bot] Aug 21, 2024
54cfc8a
Merge branch '3.3.x'
marcusdacoregio Aug 21, 2024
89920ab
Merge branch '3.3.x'
marcusdacoregio Aug 21, 2024
ce4226c
Bump org.jfrog.buildinfo:build-info-extractor-gradle
dependabot[bot] Aug 22, 2024
48d91c9
Merge branch '3.3.x'
github-actions[bot] Aug 22, 2024
31fc862
Merge branch '3.3.x'
github-actions[bot] Aug 22, 2024
3ad62d7
Merge branch '3.3.x'
github-actions[bot] Aug 23, 2024
2a1be4a
Bump org.postgresql:postgresql from 42.7.3 to 42.7.4
dependabot[bot] Aug 23, 2024
23beb0f
Bump org-springframework-boot from 3.3.2 to 3.3.3
dependabot[bot] Aug 23, 2024
1ba3836
Merge branch '3.3.x'
github-actions[bot] Aug 23, 2024
31e5799
Bump jakarta.servlet.jsp.jstl:jakarta.servlet.jsp.jstl-api
dependabot[bot] Aug 27, 2024
a4279a3
Merge branch '3.3.x'
github-actions[bot] Aug 27, 2024
225af4a
Merge branch '3.3.x'
github-actions[bot] Aug 27, 2024
848d7c1
Optimize the usage of JacksonMongoSessionConverter to prevent duplica…
xiaoquanidea Sep 2, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ updates:

- package-ecosystem: "gradle"
target-branch: "main"
milestone: 154
directory: "/"
schedule:
interval: "daily"
Expand All @@ -24,11 +23,10 @@ updates:
- dependency-name: "org.mockito:mockito-bom"
update-types: [ "version-update:semver-major" ]
- dependency-name: "*"
update-types: [ "version-update:semver-major", "version-update:semver-minor" ]
update-types: [ "version-update:semver-major" ]

- package-ecosystem: "gradle"
target-branch: "3.2.x"
milestone: 152
target-branch: "3.3.x"
directory: "/"
schedule:
interval: "daily"
Expand All @@ -46,8 +44,7 @@ updates:
update-types: [ "version-update:semver-major", "version-update:semver-minor" ]

- package-ecosystem: "gradle"
target-branch: "3.1.x"
milestone: 151
target-branch: "3.2.x"
directory: "/"
schedule:
interval: "daily"
Expand All @@ -71,13 +68,13 @@ updates:
schedule:
interval: weekly
- package-ecosystem: github-actions
target-branch: "3.2.x"
target-branch: "3.3.x"
milestone: 152
directory: "/"
schedule:
interval: weekly
- package-ecosystem: github-actions
target-branch: "3.1.x"
target-branch: "3.2.x"
milestone: 151
directory: "/"
schedule:
Expand All @@ -87,3 +84,9 @@ updates:
directory: "/"
schedule:
interval: weekly

- package-ecosystem: npm
target-branch: docs-build
directory: /
schedule:
interval: weekly
2 changes: 1 addition & 1 deletion .github/workflows/release-scheduler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
strategy:
matrix:
# List of active maintenance branches.
branch: [ main, 3.2.x, 3.1.x ]
branch: [ main, 3.3.x, 3.2.x ]
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand Down
2 changes: 1 addition & 1 deletion git/hooks/prepare-forward-merge
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ require 'net/http'
require 'yaml'
require 'logger'

$main_branch = "3.3.x"
$main_branch = "3.4.x"

$log = Logger.new(STDOUT)
$log.level = Logger::WARN
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
org.gradle.jvmargs=-Xmx4g -XX:MaxMetaspaceSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
org.gradle.parallel=true
version=3.3.3-SNAPSHOT
version=3.4.0-SNAPSHOT
6 changes: 3 additions & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ org-mongodb = "5.0.1"
org-seleniumhq-selenium = "4.13.0"
org-slf4j = "2.0.16"
org-testcontainers = "1.19.8"
org-springframework-boot = "3.2.9"
org-springframework-boot = "3.3.3"

[libraries]
ch-qos-logback-logback-classic = { module = "ch.qos.logback:logback-classic", version.ref = "ch-qos-logback" }
Expand Down Expand Up @@ -58,8 +58,8 @@ org-slf4j-jcl-over-slf4j = { module = "org.slf4j:jcl-over-slf4j", version.ref =
org-slf4j-log4j-over-slf4j = { module = "org.slf4j:log4j-over-slf4j", version.ref = "org-slf4j" }
org-slf4j-slf4j-api = { module = "org.slf4j:slf4j-api", version.ref = "org-slf4j" }
org-springframework-data-spring-data-bom = "org.springframework.data:spring-data-bom:2024.0.3"
org-springframework-security-spring-security-bom = "org.springframework.security:spring-security-bom:6.3.3"
org-springframework-spring-framework-bom = "org.springframework:spring-framework-bom:6.1.12"
org-springframework-security-spring-security-bom = "org.springframework.security:spring-security-bom:6.4.0-SNAPSHOT"
org-springframework-spring-framework-bom = "org.springframework:spring-framework-bom:6.2.0-M4"
org-springframework-boot-spring-boot-dependencies = { module = "org.springframework.boot:spring-boot-dependencies", version.ref = "org-springframework-boot" }
org-springframework-boot-spring-boot-gradle-plugin = { module = "org.springframework.boot:spring-boot-gradle-plugin", version.ref = "org-springframework-boot" }
org-testcontainers-testcontainers-bom = { module = "org.testcontainers:testcontainers-bom", version.ref = "org-testcontainers" }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2014-2021 the original author or authors.
* Copyright 2014-2024 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.
Expand Down Expand Up @@ -86,6 +86,8 @@ public class DefaultCookieSerializer implements CookieSerializer {

private String sameSite = "Lax";

private boolean partitioned;

/*
* @see
* org.springframework.session.web.http.CookieSerializer#readCookieValues(jakarta.
Expand Down Expand Up @@ -153,6 +155,9 @@ public void writeCookieValue(CookieValue cookieValue) {
if (this.sameSite != null) {
sb.append("; SameSite=").append(this.sameSite);
}
if (this.partitioned) {
sb.append("; Partitioned");
}
response.addHeader("Set-Cookie", sb.toString());
}

Expand Down Expand Up @@ -444,4 +449,13 @@ public String getRememberMeRequestAttribute() {
return this.rememberMeRequestAttribute;
}

/**
* Allows defining whether the generated cookie carries the Partitioned attribute.
* @param partitioned whether the generate cookie is partitioned
* @since 3.4
*/
public void setPartitioned(boolean partitioned) {
this.partitioned = partitioned;
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2014-2021 the original author or authors.
* Copyright 2014-2024 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.
Expand Down Expand Up @@ -460,6 +460,13 @@ void writeCookieSetSameSiteNull() {
assertThat(getCookie().getSameSite()).isNull();
}

@Test
void writeCookieWhenPartitionedTrueThenSetPartitionedAttribute() {
this.serializer.setPartitioned(true);
this.serializer.writeCookieValue(cookieValue(this.sessionId));
assertThat(getCookie().isPartitioned()).isTrue();
}

void setCookieName(String cookieName) {
this.cookieName = cookieName;
this.serializer.setCookieName(cookieName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@

package org.springframework.session.data.mongo;

import java.io.IOException;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;

import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
Expand All @@ -37,14 +32,18 @@
import org.bson.Document;
import org.bson.json.JsonMode;
import org.bson.json.JsonWriterSettings;

import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.lang.Nullable;
import org.springframework.security.jackson2.SecurityJackson2Modules;
import org.springframework.session.FindByIndexNameSessionRepository;
import org.springframework.util.Assert;

import java.io.IOException;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;

/**
* {@code AbstractMongoSessionConverter} implementation using Jackson.
*
Expand Down Expand Up @@ -76,11 +75,22 @@ public JacksonMongoSessionConverter(Iterable<Module> modules) {
}

public JacksonMongoSessionConverter(ObjectMapper objectMapper) {

Assert.notNull(objectMapper, "ObjectMapper can NOT be null!");
Assert.notNull(objectMapper, "ObjectMapper can not be null!");
this.objectMapper = objectMapper;
}

public JacksonMongoSessionConverter(ObjectMapper objectMapper, boolean copyToUse) {
Assert.notNull(objectMapper, "ObjectMapper can not be null!");
if (!copyToUse) {
configureObjectMapper(objectMapper);
this.objectMapper = objectMapper;
return;
}
var objectMapperCopy = objectMapper.copy();
configureObjectMapper(objectMapperCopy);
this.objectMapper = objectMapperCopy;
}

@Nullable
protected Query getQueryForIndex(String indexName, Object indexValue) {

Expand All @@ -93,9 +103,12 @@ protected Query getQueryForIndex(String indexName, Object indexValue) {
}

private ObjectMapper buildObjectMapper() {

ObjectMapper objectMapper = new ObjectMapper();
this.configureObjectMapper(objectMapper);
return objectMapper;
}

private void configureObjectMapper(ObjectMapper objectMapper) {
// serialize fields instead of properties
objectMapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.NONE);
objectMapper.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY);
Expand All @@ -108,8 +121,6 @@ private ObjectMapper buildObjectMapper() {
objectMapper.registerModules(SecurityJackson2Modules.getModules(getClass().getClassLoader()));
objectMapper.addMixIn(MongoSession.class, MongoSessionMixin.class);
objectMapper.addMixIn(HashMap.class, HashMapMixin.class);

return objectMapper;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
* @author Greg Turnquist
* @since 1.2
*/
class MongoSession implements Session {
public final class MongoSession implements Session {

/**
* Mongo doesn't support {@literal dot} in field names. We replace it with a unicode
Expand Down Expand Up @@ -74,20 +74,19 @@ class MongoSession implements Session {
* @param sessionId the session id to use
* @since 3.2
*/
MongoSession(String sessionId) {
public MongoSession(String sessionId) {
this(sessionId, MapSession.DEFAULT_MAX_INACTIVE_INTERVAL_SECONDS);
}

MongoSession() {
public MongoSession() {
this(MapSession.DEFAULT_MAX_INACTIVE_INTERVAL_SECONDS);
}

MongoSession(long maxInactiveIntervalInSeconds) {
public MongoSession(long maxInactiveIntervalInSeconds) {
this(UuidSessionIdGenerator.getInstance().generate(), maxInactiveIntervalInSeconds);
}

MongoSession(String id, long maxInactiveIntervalInSeconds) {

public MongoSession(String id, long maxInactiveIntervalInSeconds) {
this.id = id;
this.originalSessionId = id;
this.intervalSeconds = maxInactiveIntervalInSeconds;
Expand All @@ -99,7 +98,7 @@ class MongoSession implements Session {
* @param sessionIdGenerator the {@link SessionIdGenerator} to use
* @since 3.2
*/
MongoSession(SessionIdGenerator sessionIdGenerator) {
public MongoSession(SessionIdGenerator sessionIdGenerator) {
this(sessionIdGenerator.generate(), MapSession.DEFAULT_MAX_INACTIVE_INTERVAL_SECONDS);
this.sessionIdGenerator = sessionIdGenerator;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.nio.charset.StandardCharsets;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.TimeUnit;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -135,6 +136,22 @@ void saves() throws InterruptedException {
.isEqualTo(expectedAttributeValue);
}

@Test
void saveThenSaveSessionKeyAndShadowKeyWith5MinutesDifference() {
RedisSession toSave = this.repository.createSession();
String expectedAttributeName = "a";
String expectedAttributeValue = "b";
toSave.setAttribute(expectedAttributeName, expectedAttributeValue);
this.repository.save(toSave);

Long sessionKeyExpire = this.redis.getExpire("RedisIndexedSessionRepositoryITests:sessions:" + toSave.getId(),
TimeUnit.SECONDS);
Long shadowKeyExpire = this.redis
.getExpire("RedisIndexedSessionRepositoryITests:sessions:expires:" + toSave.getId(), TimeUnit.SECONDS);
long differenceInSeconds = sessionKeyExpire - shadowKeyExpire;
assertThat(differenceInSeconds).isEqualTo(300);
}

@Test
void putAllOnSingleAttrDoesNotRemoveOld() {
RedisSession toSave = this.repository.createSession();
Expand Down
Loading