Merge branch '3.0.x' into 3.1.x
Closes gh-2529
This commit is contained in:
@@ -72,7 +72,7 @@ dependencies {
|
|||||||
implementation 'com.apollographql.apollo:apollo-runtime:2.4.5'
|
implementation 'com.apollographql.apollo:apollo-runtime:2.4.5'
|
||||||
implementation 'com.github.ben-manes:gradle-versions-plugin:0.38.0'
|
implementation 'com.github.ben-manes:gradle-versions-plugin:0.38.0'
|
||||||
implementation 'com.github.spullara.mustache.java:compiler:0.9.11'
|
implementation 'com.github.spullara.mustache.java:compiler:0.9.11'
|
||||||
implementation 'io.spring.javaformat:spring-javaformat-gradle-plugin:0.0.34'
|
implementation 'io.spring.javaformat:spring-javaformat-gradle-plugin:0.0.39'
|
||||||
implementation 'io.spring.nohttp:nohttp-gradle:0.0.11'
|
implementation 'io.spring.nohttp:nohttp-gradle:0.0.11'
|
||||||
implementation 'net.sourceforge.htmlunit:htmlunit:2.37.0'
|
implementation 'net.sourceforge.htmlunit:htmlunit:2.37.0'
|
||||||
implementation 'org.hidetake:gradle-ssh-plugin:2.10.1'
|
implementation 'org.hidetake:gradle-ssh-plugin:2.10.1'
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ package io.spring.gradle.convention
|
|||||||
|
|
||||||
import org.gradle.api.Plugin
|
import org.gradle.api.Plugin
|
||||||
import org.gradle.api.Project
|
import org.gradle.api.Project
|
||||||
|
import org.gradle.api.artifacts.VersionCatalogsExtension
|
||||||
import org.gradle.api.plugins.JavaPlugin
|
import org.gradle.api.plugins.JavaPlugin
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -31,12 +32,14 @@ class CheckstylePlugin implements Plugin<Project> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
void apply(Project project) {
|
void apply(Project project) {
|
||||||
|
def versionCatalog = project.rootProject.extensions.getByType(VersionCatalogsExtension.class)
|
||||||
|
.named("libs")
|
||||||
project.plugins.withType(JavaPlugin) {
|
project.plugins.withType(JavaPlugin) {
|
||||||
def checkstyleDir = project.rootProject.file(CHECKSTYLE_DIR)
|
def checkstyleDir = project.rootProject.file(CHECKSTYLE_DIR)
|
||||||
if (checkstyleDir.exists() && checkstyleDir.directory) {
|
if (checkstyleDir.exists() && checkstyleDir.directory) {
|
||||||
project.getPluginManager().apply('checkstyle')
|
project.getPluginManager().apply('checkstyle')
|
||||||
project.dependencies.add('checkstyle', 'io.spring.javaformat:spring-javaformat-checkstyle:0.0.29')
|
project.dependencies.add('checkstyle', versionCatalog.findLibrary('io-spring-javaformat-spring-javaformat-checkstyle').get())
|
||||||
project.dependencies.add('checkstyle', 'io.spring.nohttp:nohttp-checkstyle:0.0.3.RELEASE')
|
project.dependencies.add('checkstyle', versionCatalog.findLibrary('io-spring-nohttp-nohttp-checkstyle').get())
|
||||||
|
|
||||||
project.checkstyle {
|
project.checkstyle {
|
||||||
configDirectory = checkstyleDir
|
configDirectory = checkstyleDir
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ io-lettuce-lettuce-core = "io.lettuce:lettuce-core:6.2.6.RELEASE"
|
|||||||
io-projectreactor-reactor-bom = "io.projectreactor:reactor-bom:2022.0.12"
|
io-projectreactor-reactor-bom = "io.projectreactor:reactor-bom:2022.0.12"
|
||||||
io-projectreactor-reactor-core = { module = "io.projectreactor:reactor-core", version.ref = "io-projectreactor" }
|
io-projectreactor-reactor-core = { module = "io.projectreactor:reactor-core", version.ref = "io-projectreactor" }
|
||||||
io-projectreactor-reactor-test = { module = "io.projectreactor:reactor-test", version.ref = "io-projectreactor" }
|
io-projectreactor-reactor-test = { module = "io.projectreactor:reactor-test", version.ref = "io-projectreactor" }
|
||||||
io-spring-javaformat-spring-javaformat-checkstyle = "io.spring.javaformat:spring-javaformat-checkstyle:0.0.29"
|
io-spring-javaformat-spring-javaformat-checkstyle = "io.spring.javaformat:spring-javaformat-checkstyle:0.0.39"
|
||||||
io-spring-nohttp-nohttp-checkstyle = "io.spring.nohttp:nohttp-checkstyle:0.0.3.RELEASE"
|
io-spring-nohttp-nohttp-checkstyle = "io.spring.nohttp:nohttp-checkstyle:0.0.3.RELEASE"
|
||||||
jakarta-servlet-jakarta-servlet-api = "jakarta.servlet:jakarta.servlet-api:6.0.0"
|
jakarta-servlet-jakarta-servlet-api = "jakarta.servlet:jakarta.servlet-api:6.0.0"
|
||||||
jakarta-servlet-jsp-jstl-jakarta-servlet-jsp-jstl-api = "jakarta.servlet.jsp.jstl:jakarta.servlet.jsp.jstl-api:3.0.0"
|
jakarta-servlet-jsp-jstl-jakarta-servlet-jsp-jstl-api = "jakarta.servlet.jsp.jstl:jakarta.servlet.jsp.jstl-api:3.0.0"
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ public interface FindByIndexNameSessionRepository<S extends Session> extends Ses
|
|||||||
* @since 1.1
|
* @since 1.1
|
||||||
*/
|
*/
|
||||||
String PRINCIPAL_NAME_INDEX_NAME = FindByIndexNameSessionRepository.class.getName()
|
String PRINCIPAL_NAME_INDEX_NAME = FindByIndexNameSessionRepository.class.getName()
|
||||||
.concat(".PRINCIPAL_NAME_INDEX_NAME");
|
.concat(".PRINCIPAL_NAME_INDEX_NAME");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find a {@link Map} of the session id to the {@link Session} of all sessions that
|
* Find a {@link Map} of the session id to the {@link Session} of all sessions that
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ public final class MapSession implements Session, Serializable {
|
|||||||
* Default {@link #setMaxInactiveInterval(Duration)} (30 minutes).
|
* Default {@link #setMaxInactiveInterval(Duration)} (30 minutes).
|
||||||
*/
|
*/
|
||||||
public static final Duration DEFAULT_MAX_INACTIVE_INTERVAL = Duration
|
public static final Duration DEFAULT_MAX_INACTIVE_INTERVAL = Duration
|
||||||
.ofSeconds(DEFAULT_MAX_INACTIVE_INTERVAL_SECONDS);
|
.ofSeconds(DEFAULT_MAX_INACTIVE_INTERVAL_SECONDS);
|
||||||
|
|
||||||
private String id;
|
private String id;
|
||||||
|
|
||||||
|
|||||||
@@ -33,16 +33,17 @@ class CommonSessionRuntimeHints implements RuntimeHintsRegistrar {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
|
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
|
||||||
Arrays.asList(TypeReference.of(String.class), TypeReference.of(ArrayList.class),
|
Arrays
|
||||||
TypeReference.of(TreeSet.class), TypeReference.of(Number.class), TypeReference.of(Long.class),
|
.asList(TypeReference.of(String.class), TypeReference.of(ArrayList.class), TypeReference.of(TreeSet.class),
|
||||||
TypeReference.of(Integer.class), TypeReference.of(StackTraceElement.class),
|
TypeReference.of(Number.class), TypeReference.of(Long.class), TypeReference.of(Integer.class),
|
||||||
TypeReference.of(Throwable.class), TypeReference.of(Exception.class),
|
TypeReference.of(StackTraceElement.class), TypeReference.of(Throwable.class),
|
||||||
TypeReference.of(RuntimeException.class),
|
TypeReference.of(Exception.class), TypeReference.of(RuntimeException.class),
|
||||||
TypeReference.of("java.util.Collections$UnmodifiableCollection"),
|
TypeReference.of("java.util.Collections$UnmodifiableCollection"),
|
||||||
TypeReference.of("java.util.Collections$UnmodifiableList"),
|
TypeReference.of("java.util.Collections$UnmodifiableList"),
|
||||||
TypeReference.of("java.util.Collections$EmptyList"),
|
TypeReference.of("java.util.Collections$EmptyList"),
|
||||||
TypeReference.of("java.util.Collections$UnmodifiableRandomAccessList"),
|
TypeReference.of("java.util.Collections$UnmodifiableRandomAccessList"),
|
||||||
TypeReference.of("java.util.Collections$UnmodifiableSet")).forEach(hints.serialization()::registerType);
|
TypeReference.of("java.util.Collections$UnmodifiableSet"))
|
||||||
|
.forEach(hints.serialization()::registerType);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,34 +53,37 @@ class CommonSessionSecurityRuntimeHints implements RuntimeHintsRegistrar {
|
|||||||
TypeReference.of("org.springframework.security.authentication.CredentialsExpiredException"),
|
TypeReference.of("org.springframework.security.authentication.CredentialsExpiredException"),
|
||||||
TypeReference.of("org.springframework.security.authentication.InsufficientAuthenticationException"),
|
TypeReference.of("org.springframework.security.authentication.InsufficientAuthenticationException"),
|
||||||
TypeReference
|
TypeReference
|
||||||
.of("org.springframework.security.web.authentication.session.SessionAuthenticationException"),
|
.of("org.springframework.security.web.authentication.session.SessionAuthenticationException"),
|
||||||
TypeReference.of(
|
TypeReference
|
||||||
"org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationException"),
|
.of("org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationException"),
|
||||||
TypeReference.of("org.springframework.security.core.userdetails.User$AuthorityComparator"))
|
TypeReference.of("org.springframework.security.core.userdetails.User$AuthorityComparator"))
|
||||||
.forEach((type) -> hints.serialization().registerType(type, (hint) -> hint.onReachableType(
|
.forEach((type) -> hints.serialization()
|
||||||
|
.registerType(type, (hint) -> hint.onReachableType(
|
||||||
TypeReference.of("org.springframework.security.core.context.SecurityContextImpl"))));
|
TypeReference.of("org.springframework.security.core.context.SecurityContextImpl"))));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void registerOAuth2ResourceServerHintsIfNeeded(RuntimeHints hints) {
|
private void registerOAuth2ResourceServerHintsIfNeeded(RuntimeHints hints) {
|
||||||
Arrays.asList(
|
Arrays.asList(
|
||||||
TypeReference.of("org.springframework.security.oauth2.server.resource.BearerTokenAuthenticationToken"),
|
TypeReference.of("org.springframework.security.oauth2.server.resource.BearerTokenAuthenticationToken"),
|
||||||
TypeReference.of(
|
TypeReference
|
||||||
"org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationToken"),
|
.of("org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationToken"),
|
||||||
TypeReference.of("org.springframework.security.oauth2.core.OAuth2AuthenticationException"))
|
TypeReference.of("org.springframework.security.oauth2.core.OAuth2AuthenticationException"))
|
||||||
.forEach((type) -> hints.serialization().registerType(type, (hint) -> hint.onReachableType(TypeReference
|
.forEach((type) -> hints.serialization()
|
||||||
.of("org.springframework.security.oauth2.server.resource.BearerTokenAuthenticationToken"))));
|
.registerType(type, (hint) -> hint.onReachableType(TypeReference
|
||||||
|
.of("org.springframework.security.oauth2.server.resource.BearerTokenAuthenticationToken"))));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void registerOAuth2ClientHintsIfNeeded(RuntimeHints hints) {
|
private void registerOAuth2ClientHintsIfNeeded(RuntimeHints hints) {
|
||||||
Arrays.asList(
|
Arrays.asList(
|
||||||
TypeReference.of("org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken"),
|
TypeReference.of("org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken"),
|
||||||
TypeReference
|
TypeReference
|
||||||
.of("org.springframework.security.oauth2.client.authentication.OAuth2LoginAuthenticationToken"),
|
.of("org.springframework.security.oauth2.client.authentication.OAuth2LoginAuthenticationToken"),
|
||||||
TypeReference.of(
|
TypeReference
|
||||||
"org.springframework.security.oauth2.client.authentication.OAuth2AuthorizationCodeAuthenticationToken"),
|
.of("org.springframework.security.oauth2.client.authentication.OAuth2AuthorizationCodeAuthenticationToken"),
|
||||||
TypeReference.of("org.springframework.security.oauth2.core.OAuth2AuthenticationException"))
|
TypeReference.of("org.springframework.security.oauth2.core.OAuth2AuthenticationException"))
|
||||||
.forEach((type) -> hints.serialization().registerType(type, (hint) -> hint.onReachableType(TypeReference
|
.forEach((type) -> hints.serialization()
|
||||||
.of("org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken"))));
|
.registerType(type, (hint) -> hint.onReachableType(TypeReference
|
||||||
|
.of("org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken"))));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ class WebSessionSecurityRuntimeHints implements RuntimeHintsRegistrar {
|
|||||||
@Override
|
@Override
|
||||||
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
|
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
|
||||||
if (!ClassUtils.isPresent("org.springframework.web.server.WebSession", classLoader) || !ClassUtils
|
if (!ClassUtils.isPresent("org.springframework.web.server.WebSession", classLoader) || !ClassUtils
|
||||||
.isPresent("org.springframework.security.web.server.csrf.DefaultCsrfToken", classLoader)) {
|
.isPresent("org.springframework.security.web.server.csrf.DefaultCsrfToken", classLoader)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
hints.serialization().registerType(DefaultCsrfToken.class);
|
hints.serialization().registerType(DefaultCsrfToken.class);
|
||||||
|
|||||||
@@ -42,11 +42,12 @@ class HttpSessionSecurityRuntimeHints implements RuntimeHintsRegistrar {
|
|||||||
|| !ClassUtils.isPresent("org.springframework.security.web.csrf.DefaultCsrfToken", classLoader)) {
|
|| !ClassUtils.isPresent("org.springframework.security.web.csrf.DefaultCsrfToken", classLoader)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Arrays.asList(TypeReference.of(TreeMap.class), TypeReference.of(Locale.class),
|
Arrays
|
||||||
TypeReference.of(DefaultSavedRequest.class), TypeReference.of(DefaultCsrfToken.class),
|
.asList(TypeReference.of(TreeMap.class), TypeReference.of(Locale.class),
|
||||||
TypeReference.of(WebAuthenticationDetails.class), TypeReference.of(SavedCookie.class),
|
TypeReference.of(DefaultSavedRequest.class), TypeReference.of(DefaultCsrfToken.class),
|
||||||
TypeReference.of("java.lang.String$CaseInsensitiveComparator"))
|
TypeReference.of(WebAuthenticationDetails.class), TypeReference.of(SavedCookie.class),
|
||||||
.forEach(hints.serialization()::registerType);
|
TypeReference.of("java.lang.String$CaseInsensitiveComparator"))
|
||||||
|
.forEach(hints.serialization()::registerType);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -131,7 +131,7 @@ public class SpringHttpSessionConfiguration implements InitializingBean, Applica
|
|||||||
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
|
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
|
||||||
if (ClassUtils.isPresent("org.springframework.security.web.authentication.RememberMeServices", null)) {
|
if (ClassUtils.isPresent("org.springframework.security.web.authentication.RememberMeServices", null)) {
|
||||||
this.usesSpringSessionRememberMeServices = !ObjectUtils
|
this.usesSpringSessionRememberMeServices = !ObjectUtils
|
||||||
.isEmpty(applicationContext.getBeanNamesForType(SpringSessionRememberMeServices.class));
|
.isEmpty(applicationContext.getBeanNamesForType(SpringSessionRememberMeServices.class));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ import org.springframework.session.web.http.CookieSerializer.CookieValue;
|
|||||||
public final class CookieHttpSessionIdResolver implements HttpSessionIdResolver {
|
public final class CookieHttpSessionIdResolver implements HttpSessionIdResolver {
|
||||||
|
|
||||||
private static final String WRITTEN_SESSION_ID_ATTR = CookieHttpSessionIdResolver.class.getName()
|
private static final String WRITTEN_SESSION_ID_ATTR = CookieHttpSessionIdResolver.class.getName()
|
||||||
.concat(".WRITTEN_SESSION_ID_ATTR");
|
.concat(".WRITTEN_SESSION_ID_ATTR");
|
||||||
|
|
||||||
private CookieSerializer cookieSerializer = new DefaultCookieSerializer();
|
private CookieSerializer cookieSerializer = new DefaultCookieSerializer();
|
||||||
|
|
||||||
|
|||||||
@@ -118,7 +118,7 @@ class HttpSessionAdapter<S extends Session> implements HttpSession {
|
|||||||
if (oldValue instanceof HttpSessionBindingListener) {
|
if (oldValue instanceof HttpSessionBindingListener) {
|
||||||
try {
|
try {
|
||||||
((HttpSessionBindingListener) oldValue)
|
((HttpSessionBindingListener) oldValue)
|
||||||
.valueUnbound(new HttpSessionBindingEvent(this, name, oldValue));
|
.valueUnbound(new HttpSessionBindingEvent(this, name, oldValue));
|
||||||
}
|
}
|
||||||
catch (Throwable th) {
|
catch (Throwable th) {
|
||||||
logger.error("Error invoking session binding event listener", th);
|
logger.error("Error invoking session binding event listener", th);
|
||||||
|
|||||||
@@ -92,7 +92,8 @@ public class SpringSessionWebSessionStore<S extends Session> implements WebSessi
|
|||||||
@Override
|
@Override
|
||||||
public Mono<WebSession> retrieveSession(String sessionId) {
|
public Mono<WebSession> retrieveSession(String sessionId) {
|
||||||
return this.sessions.findById(sessionId)
|
return this.sessions.findById(sessionId)
|
||||||
.doOnNext((session) -> session.setLastAccessedTime(this.clock.instant())).map(this::existingSession);
|
.doOnNext((session) -> session.setLastAccessedTime(this.clock.instant()))
|
||||||
|
.map(this::existingSession);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -233,8 +234,9 @@ public class SpringSessionWebSessionStore<S extends Session> implements WebSessi
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean containsValue(Object value) {
|
public boolean containsValue(Object value) {
|
||||||
return this.session.getAttributeNames().stream()
|
return this.session.getAttributeNames()
|
||||||
.anyMatch((attrName) -> this.session.getAttribute(attrName) != null);
|
.stream()
|
||||||
|
.anyMatch((attrName) -> this.session.getAttribute(attrName) != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ public final class WebSocketRegistryListener implements ApplicationListener<Appl
|
|||||||
else if (event instanceof SessionDisconnectEvent) {
|
else if (event instanceof SessionDisconnectEvent) {
|
||||||
SessionDisconnectEvent e = (SessionDisconnectEvent) event;
|
SessionDisconnectEvent e = (SessionDisconnectEvent) event;
|
||||||
Map<String, Object> sessionAttributes = SimpMessageHeaderAccessor
|
Map<String, Object> sessionAttributes = SimpMessageHeaderAccessor
|
||||||
.getSessionAttributes(e.getMessage().getHeaders());
|
.getSessionAttributes(e.getMessage().getHeaders());
|
||||||
String httpSessionId = (sessionAttributes != null)
|
String httpSessionId = (sessionAttributes != null)
|
||||||
? SessionRepositoryMessageInterceptor.getSessionId(sessionAttributes) : null;
|
? SessionRepositoryMessageInterceptor.getSessionId(sessionAttributes) : null;
|
||||||
afterConnectionClosed(httpSessionId, e.getSessionId());
|
afterConnectionClosed(httpSessionId, e.getSessionId());
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ class MapSessionTests {
|
|||||||
@Test
|
@Test
|
||||||
void constructorNullSession() {
|
void constructorNullSession() {
|
||||||
assertThatIllegalArgumentException().isThrownBy(() -> new MapSession((Session) null))
|
assertThatIllegalArgumentException().isThrownBy(() -> new MapSession((Session) null))
|
||||||
.withMessage("session cannot be null");
|
.withMessage("session cannot be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -70,7 +70,7 @@ class MapSessionTests {
|
|||||||
@Test
|
@Test
|
||||||
void getRequiredAttributeWhenNullThenException() {
|
void getRequiredAttributeWhenNullThenException() {
|
||||||
assertThatIllegalArgumentException().isThrownBy(() -> this.session.getRequiredAttribute("attrName"))
|
assertThatIllegalArgumentException().isThrownBy(() -> this.session.getRequiredAttribute("attrName"))
|
||||||
.withMessage("Required attribute 'attrName' is missing.");
|
.withMessage("Required attribute 'attrName' is missing.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ class ReactiveMapSessionRepositoryTests {
|
|||||||
@Test
|
@Test
|
||||||
void constructorMapWhenNullThenThrowsIllegalArgumentException() {
|
void constructorMapWhenNullThenThrowsIllegalArgumentException() {
|
||||||
assertThatIllegalArgumentException().isThrownBy(() -> new ReactiveMapSessionRepository(null))
|
assertThatIllegalArgumentException().isThrownBy(() -> new ReactiveMapSessionRepository(null))
|
||||||
.withMessage("sessions cannot be null");
|
.withMessage("sessions cannot be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -53,8 +53,9 @@ class CommonSessionRuntimeHintsTests {
|
|||||||
@Test
|
@Test
|
||||||
void aotFactoriesContainsRegistrar() {
|
void aotFactoriesContainsRegistrar() {
|
||||||
boolean match = SpringFactoriesLoader.forResourceLocation("META-INF/spring/aot.factories")
|
boolean match = SpringFactoriesLoader.forResourceLocation("META-INF/spring/aot.factories")
|
||||||
.load(RuntimeHintsRegistrar.class).stream()
|
.load(RuntimeHintsRegistrar.class)
|
||||||
.anyMatch((registrar) -> registrar instanceof CommonSessionRuntimeHints);
|
.stream()
|
||||||
|
.anyMatch((registrar) -> registrar instanceof CommonSessionRuntimeHints);
|
||||||
assertThat(match).isTrue();
|
assertThat(match).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -51,8 +51,9 @@ class CommonSessionSecurityRuntimeHintsTests {
|
|||||||
@Test
|
@Test
|
||||||
void aotFactoriesContainsRegistrar() {
|
void aotFactoriesContainsRegistrar() {
|
||||||
boolean match = SpringFactoriesLoader.forResourceLocation("META-INF/spring/aot.factories")
|
boolean match = SpringFactoriesLoader.forResourceLocation("META-INF/spring/aot.factories")
|
||||||
.load(RuntimeHintsRegistrar.class).stream()
|
.load(RuntimeHintsRegistrar.class)
|
||||||
.anyMatch((registrar) -> registrar instanceof CommonSessionSecurityRuntimeHints);
|
.stream()
|
||||||
|
.anyMatch((registrar) -> registrar instanceof CommonSessionSecurityRuntimeHints);
|
||||||
assertThat(match).isTrue();
|
assertThat(match).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,19 +74,19 @@ class CommonSessionSecurityRuntimeHintsTests {
|
|||||||
TypeReference.of("org.springframework.security.authentication.CredentialsExpiredException"),
|
TypeReference.of("org.springframework.security.authentication.CredentialsExpiredException"),
|
||||||
TypeReference.of("org.springframework.security.authentication.InsufficientAuthenticationException"),
|
TypeReference.of("org.springframework.security.authentication.InsufficientAuthenticationException"),
|
||||||
TypeReference
|
TypeReference
|
||||||
.of("org.springframework.security.web.authentication.session.SessionAuthenticationException"),
|
.of("org.springframework.security.web.authentication.session.SessionAuthenticationException"),
|
||||||
TypeReference.of(
|
TypeReference
|
||||||
"org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationException"),
|
.of("org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationException"),
|
||||||
TypeReference.of("org.springframework.security.core.userdetails.User$AuthorityComparator"),
|
TypeReference.of("org.springframework.security.core.userdetails.User$AuthorityComparator"),
|
||||||
TypeReference.of("org.springframework.security.oauth2.server.resource.BearerTokenAuthenticationToken"),
|
TypeReference.of("org.springframework.security.oauth2.server.resource.BearerTokenAuthenticationToken"),
|
||||||
TypeReference.of(
|
TypeReference
|
||||||
"org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationToken"),
|
.of("org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationToken"),
|
||||||
TypeReference.of("org.springframework.security.oauth2.core.OAuth2AuthenticationException"),
|
TypeReference.of("org.springframework.security.oauth2.core.OAuth2AuthenticationException"),
|
||||||
TypeReference.of("org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken"),
|
TypeReference.of("org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken"),
|
||||||
TypeReference
|
TypeReference
|
||||||
.of("org.springframework.security.oauth2.client.authentication.OAuth2LoginAuthenticationToken"),
|
.of("org.springframework.security.oauth2.client.authentication.OAuth2LoginAuthenticationToken"),
|
||||||
TypeReference.of(
|
TypeReference
|
||||||
"org.springframework.security.oauth2.client.authentication.OAuth2AuthorizationCodeAuthenticationToken"),
|
.of("org.springframework.security.oauth2.client.authentication.OAuth2AuthorizationCodeAuthenticationToken"),
|
||||||
TypeReference.of("org.springframework.security.oauth2.core.OAuth2AuthenticationException"));
|
TypeReference.of("org.springframework.security.oauth2.core.OAuth2AuthenticationException"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ class WebSessionSecurityRuntimeHintsTests {
|
|||||||
void registerHintsWhenWebSessionMissingThenDoNotRegisterHints() {
|
void registerHintsWhenWebSessionMissingThenDoNotRegisterHints() {
|
||||||
try (MockedStatic<ClassUtils> classUtilsMock = mockStatic(ClassUtils.class)) {
|
try (MockedStatic<ClassUtils> classUtilsMock = mockStatic(ClassUtils.class)) {
|
||||||
classUtilsMock.when(() -> ClassUtils.isPresent(eq("org.springframework.web.server.WebSession"), any()))
|
classUtilsMock.when(() -> ClassUtils.isPresent(eq("org.springframework.web.server.WebSession"), any()))
|
||||||
.thenReturn(false);
|
.thenReturn(false);
|
||||||
this.webSessionSecurityRuntimeHints.registerHints(this.hints, getClass().getClassLoader());
|
this.webSessionSecurityRuntimeHints.registerHints(this.hints, getClass().getClassLoader());
|
||||||
assertThat(this.hints.serialization().javaSerializationHints()).isEmpty();
|
assertThat(this.hints.serialization().javaSerializationHints()).isEmpty();
|
||||||
}
|
}
|
||||||
@@ -62,9 +62,9 @@ class WebSessionSecurityRuntimeHintsTests {
|
|||||||
void registerHintsWhenDefaultCsrfTokenMissingThenDoNotRegisterHints() {
|
void registerHintsWhenDefaultCsrfTokenMissingThenDoNotRegisterHints() {
|
||||||
try (MockedStatic<ClassUtils> classUtilsMock = mockStatic(ClassUtils.class)) {
|
try (MockedStatic<ClassUtils> classUtilsMock = mockStatic(ClassUtils.class)) {
|
||||||
classUtilsMock
|
classUtilsMock
|
||||||
.when(() -> ClassUtils
|
.when(() -> ClassUtils.isPresent(eq("org.springframework.security.web.server.csrf.DefaultCsrfToken"),
|
||||||
.isPresent(eq("org.springframework.security.web.server.csrf.DefaultCsrfToken"), any()))
|
any()))
|
||||||
.thenReturn(false);
|
.thenReturn(false);
|
||||||
this.webSessionSecurityRuntimeHints.registerHints(this.hints, getClass().getClassLoader());
|
this.webSessionSecurityRuntimeHints.registerHints(this.hints, getClass().getClassLoader());
|
||||||
assertThat(this.hints.serialization().javaSerializationHints()).isEmpty();
|
assertThat(this.hints.serialization().javaSerializationHints()).isEmpty();
|
||||||
}
|
}
|
||||||
@@ -73,8 +73,9 @@ class WebSessionSecurityRuntimeHintsTests {
|
|||||||
@Test
|
@Test
|
||||||
void aotFactoriesContainsRegistrar() {
|
void aotFactoriesContainsRegistrar() {
|
||||||
boolean match = SpringFactoriesLoader.forResourceLocation("META-INF/spring/aot.factories")
|
boolean match = SpringFactoriesLoader.forResourceLocation("META-INF/spring/aot.factories")
|
||||||
.load(RuntimeHintsRegistrar.class).stream()
|
.load(RuntimeHintsRegistrar.class)
|
||||||
.anyMatch((registrar) -> registrar instanceof WebSessionSecurityRuntimeHints);
|
.stream()
|
||||||
|
.anyMatch((registrar) -> registrar instanceof WebSessionSecurityRuntimeHints);
|
||||||
assertThat(match).isTrue();
|
assertThat(match).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ class HttpSessionSecurityRuntimeHintsTests {
|
|||||||
void registerHintsWhenHttpSessionMissingThenDoNotRegisterHints() {
|
void registerHintsWhenHttpSessionMissingThenDoNotRegisterHints() {
|
||||||
try (MockedStatic<ClassUtils> classUtilsMock = mockStatic(ClassUtils.class)) {
|
try (MockedStatic<ClassUtils> classUtilsMock = mockStatic(ClassUtils.class)) {
|
||||||
classUtilsMock.when(() -> ClassUtils.isPresent(eq("jakarta.servlet.http.HttpSession"), any()))
|
classUtilsMock.when(() -> ClassUtils.isPresent(eq("jakarta.servlet.http.HttpSession"), any()))
|
||||||
.thenReturn(false);
|
.thenReturn(false);
|
||||||
this.httpSessionSecurityRuntimeHints.registerHints(this.hints, getClass().getClassLoader());
|
this.httpSessionSecurityRuntimeHints.registerHints(this.hints, getClass().getClassLoader());
|
||||||
assertThat(this.hints.serialization().javaSerializationHints()).isEmpty();
|
assertThat(this.hints.serialization().javaSerializationHints()).isEmpty();
|
||||||
}
|
}
|
||||||
@@ -72,9 +72,9 @@ class HttpSessionSecurityRuntimeHintsTests {
|
|||||||
@Test
|
@Test
|
||||||
void registerHintsWhenDefaultCsrfTokenMissingThenDoNotRegisterHints() {
|
void registerHintsWhenDefaultCsrfTokenMissingThenDoNotRegisterHints() {
|
||||||
try (MockedStatic<ClassUtils> classUtilsMock = mockStatic(ClassUtils.class)) {
|
try (MockedStatic<ClassUtils> classUtilsMock = mockStatic(ClassUtils.class)) {
|
||||||
classUtilsMock.when(
|
classUtilsMock
|
||||||
() -> ClassUtils.isPresent(eq("org.springframework.security.web.csrf.DefaultCsrfToken"), any()))
|
.when(() -> ClassUtils.isPresent(eq("org.springframework.security.web.csrf.DefaultCsrfToken"), any()))
|
||||||
.thenReturn(false);
|
.thenReturn(false);
|
||||||
this.httpSessionSecurityRuntimeHints.registerHints(this.hints, getClass().getClassLoader());
|
this.httpSessionSecurityRuntimeHints.registerHints(this.hints, getClass().getClassLoader());
|
||||||
assertThat(this.hints.serialization().javaSerializationHints()).isEmpty();
|
assertThat(this.hints.serialization().javaSerializationHints()).isEmpty();
|
||||||
}
|
}
|
||||||
@@ -83,8 +83,9 @@ class HttpSessionSecurityRuntimeHintsTests {
|
|||||||
@Test
|
@Test
|
||||||
void aotFactoriesContainsRegistrar() {
|
void aotFactoriesContainsRegistrar() {
|
||||||
boolean match = SpringFactoriesLoader.forResourceLocation("META-INF/spring/aot.factories")
|
boolean match = SpringFactoriesLoader.forResourceLocation("META-INF/spring/aot.factories")
|
||||||
.load(RuntimeHintsRegistrar.class).stream()
|
.load(RuntimeHintsRegistrar.class)
|
||||||
.anyMatch((registrar) -> registrar instanceof HttpSessionSecurityRuntimeHints);
|
.stream()
|
||||||
|
.anyMatch((registrar) -> registrar instanceof HttpSessionSecurityRuntimeHints);
|
||||||
assertThat(match).isTrue();
|
assertThat(match).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ class EnableSpringHttpSessionCustomCookieSerializerTests {
|
|||||||
void usesReadSessionIds() throws Exception {
|
void usesReadSessionIds() throws Exception {
|
||||||
String sessionId = "sessionId";
|
String sessionId = "sessionId";
|
||||||
given(this.cookieSerializer.readCookieValues(any(HttpServletRequest.class)))
|
given(this.cookieSerializer.readCookieValues(any(HttpServletRequest.class)))
|
||||||
.willReturn(Collections.singletonList(sessionId));
|
.willReturn(Collections.singletonList(sessionId));
|
||||||
given(this.sessionRepository.findById(anyString())).willReturn(new MapSession(sessionId));
|
given(this.sessionRepository.findById(anyString())).willReturn(new MapSession(sessionId));
|
||||||
|
|
||||||
this.sessionRepositoryFilter.doFilter(this.request, this.response, this.chain);
|
this.sessionRepositoryFilter.doFilter(this.request, this.response, this.chain);
|
||||||
|
|||||||
@@ -64,8 +64,8 @@ class SpringHttpSessionConfigurationTests {
|
|||||||
@Test
|
@Test
|
||||||
void noSessionRepositoryConfiguration() {
|
void noSessionRepositoryConfiguration() {
|
||||||
assertThatExceptionOfType(UnsatisfiedDependencyException.class)
|
assertThatExceptionOfType(UnsatisfiedDependencyException.class)
|
||||||
.isThrownBy(() -> registerAndRefresh(EmptyConfiguration.class))
|
.isThrownBy(() -> registerAndRefresh(EmptyConfiguration.class))
|
||||||
.withMessageContaining("org.springframework.session.SessionRepository");
|
.withMessageContaining("org.springframework.session.SessionRepository");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -84,10 +84,10 @@ class SpringHttpSessionConfigurationTests {
|
|||||||
SessionRepositoryFilter sessionRepositoryFilter = this.context.getBean(SessionRepositoryFilter.class);
|
SessionRepositoryFilter sessionRepositoryFilter = this.context.getBean(SessionRepositoryFilter.class);
|
||||||
assertThat(sessionRepositoryFilter).isNotNull();
|
assertThat(sessionRepositoryFilter).isNotNull();
|
||||||
CookieHttpSessionIdResolver httpSessionIdResolver = (CookieHttpSessionIdResolver) ReflectionTestUtils
|
CookieHttpSessionIdResolver httpSessionIdResolver = (CookieHttpSessionIdResolver) ReflectionTestUtils
|
||||||
.getField(sessionRepositoryFilter, "httpSessionIdResolver");
|
.getField(sessionRepositoryFilter, "httpSessionIdResolver");
|
||||||
assertThat(httpSessionIdResolver).isNotNull();
|
assertThat(httpSessionIdResolver).isNotNull();
|
||||||
DefaultCookieSerializer cookieSerializer = (DefaultCookieSerializer) ReflectionTestUtils
|
DefaultCookieSerializer cookieSerializer = (DefaultCookieSerializer) ReflectionTestUtils
|
||||||
.getField(httpSessionIdResolver, "cookieSerializer");
|
.getField(httpSessionIdResolver, "cookieSerializer");
|
||||||
assertThat(cookieSerializer).isNotNull();
|
assertThat(cookieSerializer).isNotNull();
|
||||||
assertThat(ReflectionTestUtils.getField(cookieSerializer, "cookieName")).isEqualTo("test-name");
|
assertThat(ReflectionTestUtils.getField(cookieSerializer, "cookieName")).isEqualTo("test-name");
|
||||||
assertThat(ReflectionTestUtils.getField(cookieSerializer, "cookiePath")).isEqualTo("test-path");
|
assertThat(ReflectionTestUtils.getField(cookieSerializer, "cookiePath")).isEqualTo("test-path");
|
||||||
@@ -102,13 +102,13 @@ class SpringHttpSessionConfigurationTests {
|
|||||||
SessionRepositoryFilter sessionRepositoryFilter = this.context.getBean(SessionRepositoryFilter.class);
|
SessionRepositoryFilter sessionRepositoryFilter = this.context.getBean(SessionRepositoryFilter.class);
|
||||||
assertThat(sessionRepositoryFilter).isNotNull();
|
assertThat(sessionRepositoryFilter).isNotNull();
|
||||||
CookieHttpSessionIdResolver httpSessionIdResolver = (CookieHttpSessionIdResolver) ReflectionTestUtils
|
CookieHttpSessionIdResolver httpSessionIdResolver = (CookieHttpSessionIdResolver) ReflectionTestUtils
|
||||||
.getField(sessionRepositoryFilter, "httpSessionIdResolver");
|
.getField(sessionRepositoryFilter, "httpSessionIdResolver");
|
||||||
assertThat(httpSessionIdResolver).isNotNull();
|
assertThat(httpSessionIdResolver).isNotNull();
|
||||||
DefaultCookieSerializer cookieSerializer = (DefaultCookieSerializer) ReflectionTestUtils
|
DefaultCookieSerializer cookieSerializer = (DefaultCookieSerializer) ReflectionTestUtils
|
||||||
.getField(httpSessionIdResolver, "cookieSerializer");
|
.getField(httpSessionIdResolver, "cookieSerializer");
|
||||||
assertThat(cookieSerializer).isNotNull();
|
assertThat(cookieSerializer).isNotNull();
|
||||||
assertThat(ReflectionTestUtils.getField(cookieSerializer, "rememberMeRequestAttribute"))
|
assertThat(ReflectionTestUtils.getField(cookieSerializer, "rememberMeRequestAttribute"))
|
||||||
.isEqualTo(SpringSessionRememberMeServices.REMEMBER_ME_LOGIN_ATTR);
|
.isEqualTo(SpringSessionRememberMeServices.REMEMBER_ME_LOGIN_ATTR);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
|
|||||||
@@ -77,8 +77,8 @@ class SpringWebSessionConfigurationTests {
|
|||||||
this.context.register(BadConfig.class);
|
this.context.register(BadConfig.class);
|
||||||
|
|
||||||
assertThatExceptionOfType(UnsatisfiedDependencyException.class).isThrownBy(this.context::refresh)
|
assertThatExceptionOfType(UnsatisfiedDependencyException.class).isThrownBy(this.context::refresh)
|
||||||
.withMessageContaining("Error creating bean with name 'webSessionManager'").withMessageContaining(
|
.withMessageContaining("Error creating bean with name 'webSessionManager'")
|
||||||
"No qualifying bean of type '" + ReactiveSessionRepository.class.getCanonicalName());
|
.withMessageContaining("No qualifying bean of type '" + ReactiveSessionRepository.class.getCanonicalName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ class SpringSessionBackedSessionRegistryTest {
|
|||||||
|
|
||||||
assertThat(sessionInfo.getSessionId()).isEqualTo(SESSION_ID);
|
assertThat(sessionInfo.getSessionId()).isEqualTo(SESSION_ID);
|
||||||
assertThat(sessionInfo.getLastRequest().toInstant().truncatedTo(ChronoUnit.MILLIS))
|
assertThat(sessionInfo.getLastRequest().toInstant().truncatedTo(ChronoUnit.MILLIS))
|
||||||
.isEqualTo(NOW.truncatedTo(ChronoUnit.MILLIS));
|
.isEqualTo(NOW.truncatedTo(ChronoUnit.MILLIS));
|
||||||
assertThat(sessionInfo.getPrincipal()).isEqualTo(USER_NAME);
|
assertThat(sessionInfo.getPrincipal()).isEqualTo(USER_NAME);
|
||||||
assertThat(sessionInfo.isExpired()).isFalse();
|
assertThat(sessionInfo.isExpired()).isFalse();
|
||||||
}
|
}
|
||||||
@@ -92,7 +92,7 @@ class SpringSessionBackedSessionRegistryTest {
|
|||||||
|
|
||||||
assertThat(sessionInfo.getSessionId()).isEqualTo(SESSION_ID);
|
assertThat(sessionInfo.getSessionId()).isEqualTo(SESSION_ID);
|
||||||
assertThat(sessionInfo.getLastRequest().toInstant().truncatedTo(ChronoUnit.MILLIS))
|
assertThat(sessionInfo.getLastRequest().toInstant().truncatedTo(ChronoUnit.MILLIS))
|
||||||
.isEqualTo(NOW.truncatedTo(ChronoUnit.MILLIS));
|
.isEqualTo(NOW.truncatedTo(ChronoUnit.MILLIS));
|
||||||
assertThat(sessionInfo.getPrincipal()).isEqualTo(USER_NAME);
|
assertThat(sessionInfo.getPrincipal()).isEqualTo(USER_NAME);
|
||||||
assertThat(sessionInfo.isExpired()).isTrue();
|
assertThat(sessionInfo.isExpired()).isTrue();
|
||||||
}
|
}
|
||||||
@@ -113,7 +113,7 @@ class SpringSessionBackedSessionRegistryTest {
|
|||||||
void getAllSessionsForAuthenticatedPrincipal() {
|
void getAllSessionsForAuthenticatedPrincipal() {
|
||||||
setUpSessions();
|
setUpSessions();
|
||||||
List<SessionInformation> allSessionInfos = this.sessionRegistry
|
List<SessionInformation> allSessionInfos = this.sessionRegistry
|
||||||
.getAllSessions((AuthenticatedPrincipal) () -> USER_NAME, true);
|
.getAllSessions((AuthenticatedPrincipal) () -> USER_NAME, true);
|
||||||
assertThat(allSessionInfos).extracting("sessionId").containsExactly(SESSION_ID, SESSION_ID2);
|
assertThat(allSessionInfos).extracting("sessionId").containsExactly(SESSION_ID, SESSION_ID2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -148,7 +148,7 @@ class SpringSessionBackedSessionRegistryTest {
|
|||||||
ArgumentCaptor<Session> captor = ArgumentCaptor.forClass(Session.class);
|
ArgumentCaptor<Session> captor = ArgumentCaptor.forClass(Session.class);
|
||||||
verify(this.sessionRepository).save(captor.capture());
|
verify(this.sessionRepository).save(captor.capture());
|
||||||
assertThat(captor.getValue().<Boolean>getAttribute(SpringSessionBackedSessionInformation.EXPIRED_ATTR))
|
assertThat(captor.getValue().<Boolean>getAttribute(SpringSessionBackedSessionInformation.EXPIRED_ATTR))
|
||||||
.isEqualTo(Boolean.TRUE);
|
.isEqualTo(Boolean.TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Session createSession(String sessionId, String userName, Instant lastAccessed) {
|
private Session createSession(String sessionId, String userName, Instant lastAccessed) {
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ class SpringSessionRememberMeServicesTests {
|
|||||||
void create() {
|
void create() {
|
||||||
this.rememberMeServices = new SpringSessionRememberMeServices();
|
this.rememberMeServices = new SpringSessionRememberMeServices();
|
||||||
assertThat(ReflectionTestUtils.getField(this.rememberMeServices, "rememberMeParameterName"))
|
assertThat(ReflectionTestUtils.getField(this.rememberMeServices, "rememberMeParameterName"))
|
||||||
.isEqualTo("remember-me");
|
.isEqualTo("remember-me");
|
||||||
assertThat(ReflectionTestUtils.getField(this.rememberMeServices, "alwaysRemember")).isEqualTo(false);
|
assertThat(ReflectionTestUtils.getField(this.rememberMeServices, "alwaysRemember")).isEqualTo(false);
|
||||||
assertThat(ReflectionTestUtils.getField(this.rememberMeServices, "validitySeconds")).isEqualTo(2592000);
|
assertThat(ReflectionTestUtils.getField(this.rememberMeServices, "validitySeconds")).isEqualTo(2592000);
|
||||||
}
|
}
|
||||||
@@ -58,14 +58,14 @@ class SpringSessionRememberMeServicesTests {
|
|||||||
this.rememberMeServices = new SpringSessionRememberMeServices();
|
this.rememberMeServices = new SpringSessionRememberMeServices();
|
||||||
this.rememberMeServices.setRememberMeParameterName("test-param");
|
this.rememberMeServices.setRememberMeParameterName("test-param");
|
||||||
assertThat(ReflectionTestUtils.getField(this.rememberMeServices, "rememberMeParameterName"))
|
assertThat(ReflectionTestUtils.getField(this.rememberMeServices, "rememberMeParameterName"))
|
||||||
.isEqualTo("test-param");
|
.isEqualTo("test-param");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void createWithNullParameter() {
|
void createWithNullParameter() {
|
||||||
this.rememberMeServices = new SpringSessionRememberMeServices();
|
this.rememberMeServices = new SpringSessionRememberMeServices();
|
||||||
assertThatIllegalArgumentException().isThrownBy(() -> this.rememberMeServices.setRememberMeParameterName(null))
|
assertThatIllegalArgumentException().isThrownBy(() -> this.rememberMeServices.setRememberMeParameterName(null))
|
||||||
.withMessage("rememberMeParameterName cannot be empty or null");
|
.withMessage("rememberMeParameterName cannot be empty or null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ class CookieHttpSessionIdResolverTests {
|
|||||||
void getRequestedSessionIdNotNull() {
|
void getRequestedSessionIdNotNull() {
|
||||||
setSessionCookie(this.session.getId());
|
setSessionCookie(this.session.getId());
|
||||||
assertThat(this.strategy.resolveSessionIds(this.request))
|
assertThat(this.strategy.resolveSessionIds(this.request))
|
||||||
.isEqualTo(Collections.singletonList(this.session.getId()));
|
.isEqualTo(Collections.singletonList(this.session.getId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -72,7 +72,7 @@ class CookieHttpSessionIdResolverTests {
|
|||||||
setCookieName("CUSTOM");
|
setCookieName("CUSTOM");
|
||||||
setSessionCookie(this.session.getId());
|
setSessionCookie(this.session.getId());
|
||||||
assertThat(this.strategy.resolveSessionIds(this.request))
|
assertThat(this.strategy.resolveSessionIds(this.request))
|
||||||
.isEqualTo(Collections.singletonList(this.session.getId()));
|
.isEqualTo(Collections.singletonList(this.session.getId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -144,7 +144,7 @@ class CookieHttpSessionIdResolverTests {
|
|||||||
@Test
|
@Test
|
||||||
void createSessionCookieValue() {
|
void createSessionCookieValue() {
|
||||||
assertThat(createSessionCookieValue(17))
|
assertThat(createSessionCookieValue(17))
|
||||||
.isEqualToIgnoringCase("0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 a 10 b 11 c 12 d 13 e 14 f 15 10 16");
|
.isEqualToIgnoringCase("0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 a 10 b 11 c 12 d 13 e 14 f 15 10 16");
|
||||||
}
|
}
|
||||||
|
|
||||||
private String createSessionCookieValue(long size) {
|
private String createSessionCookieValue(long size) {
|
||||||
|
|||||||
@@ -200,7 +200,7 @@ class DefaultCookieSerializerTests {
|
|||||||
void setDomainNameAndDomainNamePatternThrows() {
|
void setDomainNameAndDomainNamePatternThrows() {
|
||||||
this.serializer.setDomainName("example.com");
|
this.serializer.setDomainName("example.com");
|
||||||
assertThatIllegalStateException().isThrownBy(() -> this.serializer.setDomainNamePattern(".*"))
|
assertThatIllegalStateException().isThrownBy(() -> this.serializer.setDomainNamePattern(".*"))
|
||||||
.withMessage("Cannot set both domainName and domainNamePattern");
|
.withMessage("Cannot set both domainName and domainNamePattern");
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- domainNamePattern ---
|
// --- domainNamePattern ---
|
||||||
@@ -229,7 +229,7 @@ class DefaultCookieSerializerTests {
|
|||||||
void setDomainNamePatternAndDomainNameThrows() {
|
void setDomainNamePatternAndDomainNameThrows() {
|
||||||
this.serializer.setDomainNamePattern(".*");
|
this.serializer.setDomainNamePattern(".*");
|
||||||
assertThatIllegalStateException().isThrownBy(() -> this.serializer.setDomainName("example.com"))
|
assertThatIllegalStateException().isThrownBy(() -> this.serializer.setDomainName("example.com"))
|
||||||
.withMessage("Cannot set both domainName and domainNamePattern");
|
.withMessage("Cannot set both domainName and domainNamePattern");
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- cookieName ---
|
// --- cookieName ---
|
||||||
@@ -251,7 +251,7 @@ class DefaultCookieSerializerTests {
|
|||||||
@Test
|
@Test
|
||||||
void setCookieNameNullThrows() {
|
void setCookieNameNullThrows() {
|
||||||
assertThatIllegalArgumentException().isThrownBy(() -> this.serializer.setCookieName(null))
|
assertThatIllegalArgumentException().isThrownBy(() -> this.serializer.setCookieName(null))
|
||||||
.withMessage("cookieName cannot be null");
|
.withMessage("cookieName cannot be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- cookiePath ---
|
// --- cookiePath ---
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ class HeaderHttpSessionIdResolverTests {
|
|||||||
@Test
|
@Test
|
||||||
void createResolverWithNullHeaderName() {
|
void createResolverWithNullHeaderName() {
|
||||||
assertThatIllegalArgumentException().isThrownBy(() -> new HeaderHttpSessionIdResolver(null))
|
assertThatIllegalArgumentException().isThrownBy(() -> new HeaderHttpSessionIdResolver(null))
|
||||||
.withMessage("headerName cannot be null");
|
.withMessage("headerName cannot be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -40,8 +40,9 @@ class OncePerRequestFilterAopTests {
|
|||||||
@Test
|
@Test
|
||||||
void doFilterOnce(@Autowired final OncePerRequestFilter filter) {
|
void doFilterOnce(@Autowired final OncePerRequestFilter filter) {
|
||||||
assertThatCode(() -> filter.doFilter(new MockHttpServletRequest(), new MockHttpServletResponse(),
|
assertThatCode(() -> filter.doFilter(new MockHttpServletRequest(), new MockHttpServletResponse(),
|
||||||
new MockFilterChain())).as("`doFilter` does not throw NPE with the bean is being proxied by Spring AOP")
|
new MockFilterChain()))
|
||||||
.doesNotThrowAnyException();
|
.as("`doFilter` does not throw NPE with the bean is being proxied by Spring AOP")
|
||||||
|
.doesNotThrowAnyException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||||
|
|||||||
@@ -998,7 +998,7 @@ class SessionRepositoryFilterTests {
|
|||||||
final String expectedId = "HttpSessionIdResolver-requested-id";
|
final String expectedId = "HttpSessionIdResolver-requested-id";
|
||||||
|
|
||||||
given(this.strategy.resolveSessionIds(any(HttpServletRequest.class)))
|
given(this.strategy.resolveSessionIds(any(HttpServletRequest.class)))
|
||||||
.willReturn(Collections.singletonList(expectedId));
|
.willReturn(Collections.singletonList(expectedId));
|
||||||
given(sessionRepository.findById(anyString())).willReturn(new MapSession(expectedId));
|
given(sessionRepository.findById(anyString())).willReturn(new MapSession(expectedId));
|
||||||
|
|
||||||
doFilter(new DoInFilter() {
|
doFilter(new DoInFilter() {
|
||||||
@@ -1020,7 +1020,7 @@ class SessionRepositoryFilterTests {
|
|||||||
final String otherId = "HttpSessionIdResolver-requested-id2";
|
final String otherId = "HttpSessionIdResolver-requested-id2";
|
||||||
|
|
||||||
given(this.strategy.resolveSessionIds(any(HttpServletRequest.class)))
|
given(this.strategy.resolveSessionIds(any(HttpServletRequest.class)))
|
||||||
.willReturn(Arrays.asList(expectedId, otherId));
|
.willReturn(Arrays.asList(expectedId, otherId));
|
||||||
|
|
||||||
doFilter(new DoInFilter() {
|
doFilter(new DoInFilter() {
|
||||||
@Override
|
@Override
|
||||||
@@ -1189,7 +1189,7 @@ class SessionRepositoryFilterTests {
|
|||||||
void order() {
|
void order() {
|
||||||
assertThat(
|
assertThat(
|
||||||
AnnotationAwareOrderComparator.INSTANCE.compare(this.filter, new SessionRepositoryFilterDefaultOrder()))
|
AnnotationAwareOrderComparator.INSTANCE.compare(this.filter, new SessionRepositoryFilterDefaultOrder()))
|
||||||
.isZero();
|
.isZero();
|
||||||
}
|
}
|
||||||
|
|
||||||
// We want the filter to work without any dependencies on Spring
|
// We want the filter to work without any dependencies on Spring
|
||||||
@@ -1201,7 +1201,7 @@ class SessionRepositoryFilterTests {
|
|||||||
@Test
|
@Test
|
||||||
void setHttpSessionIdResolverNull() {
|
void setHttpSessionIdResolverNull() {
|
||||||
assertThatIllegalArgumentException().isThrownBy(() -> this.filter.setHttpSessionIdResolver(null))
|
assertThatIllegalArgumentException().isThrownBy(() -> this.filter.setHttpSessionIdResolver(null))
|
||||||
.withMessage("httpSessionIdResolver cannot be null");
|
.withMessage("httpSessionIdResolver cannot be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -1329,16 +1329,18 @@ class SessionRepositoryFilterTests {
|
|||||||
assertThat(cookie.getValue()).isNotEqualTo("INVALID");
|
assertThat(cookie.getValue()).isNotEqualTo("INVALID");
|
||||||
assertThat(cookie.isHttpOnly()).describedAs("Cookie is expected to be HTTP Only").isTrue();
|
assertThat(cookie.isHttpOnly()).describedAs("Cookie is expected to be HTTP Only").isTrue();
|
||||||
assertThat(cookie.getSecure()).describedAs("Cookie secured is expected to be " + this.request.isSecure())
|
assertThat(cookie.getSecure()).describedAs("Cookie secured is expected to be " + this.request.isSecure())
|
||||||
.isEqualTo(this.request.isSecure());
|
.isEqualTo(this.request.isSecure());
|
||||||
assertThat(this.request.getSession(false))
|
assertThat(this.request.getSession(false))
|
||||||
.describedAs("The original HttpServletRequest HttpSession should be null").isNull();
|
.describedAs("The original HttpServletRequest HttpSession should be null")
|
||||||
|
.isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertNoSession() {
|
private void assertNoSession() {
|
||||||
Cookie cookie = getSessionCookie();
|
Cookie cookie = getSessionCookie();
|
||||||
assertThat(cookie).isNull();
|
assertThat(cookie).isNull();
|
||||||
assertThat(this.request.getSession(false))
|
assertThat(this.request.getSession(false))
|
||||||
.describedAs("The original HttpServletRequest HttpSession should be null").isNull();
|
.describedAs("The original HttpServletRequest HttpSession should be null")
|
||||||
|
.isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Cookie getSessionCookie() {
|
private Cookie getSessionCookie() {
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ class SpringSessionWebSessionStoreTests<S extends Session> {
|
|||||||
@Test
|
@Test
|
||||||
void constructorWhenNullRepositoryThenThrowsIllegalArgumentException() {
|
void constructorWhenNullRepositoryThenThrowsIllegalArgumentException() {
|
||||||
assertThatIllegalArgumentException().isThrownBy(() -> new SpringSessionWebSessionStore<S>(null))
|
assertThatIllegalArgumentException().isThrownBy(() -> new SpringSessionWebSessionStore<S>(null))
|
||||||
.withMessage("reactiveSessionRepository cannot be null");
|
.withMessage("reactiveSessionRepository cannot be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -248,7 +248,7 @@ class SpringSessionWebSessionStoreTests<S extends Session> {
|
|||||||
@Test
|
@Test
|
||||||
void setClockWhenNullThenException() {
|
void setClockWhenNullThenException() {
|
||||||
assertThatIllegalArgumentException().isThrownBy(() -> this.webSessionStore.setClock(null))
|
assertThatIllegalArgumentException().isThrownBy(() -> this.webSessionStore.setClock(null))
|
||||||
.withMessage("clock cannot be null");
|
.withMessage("clock cannot be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // gh-1114
|
@Test // gh-1114
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ class WebSocketConnectHandlerDecoratorFactoryTests {
|
|||||||
@Test
|
@Test
|
||||||
void constructorNullEventPublisher() {
|
void constructorNullEventPublisher() {
|
||||||
assertThatIllegalArgumentException().isThrownBy(() -> new WebSocketConnectHandlerDecoratorFactory(null))
|
assertThatIllegalArgumentException().isThrownBy(() -> new WebSocketConnectHandlerDecoratorFactory(null))
|
||||||
.withMessage("eventPublisher cannot be null");
|
.withMessage("eventPublisher cannot be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -78,7 +78,7 @@ class WebSocketConnectHandlerDecoratorFactoryTests {
|
|||||||
void decorateAfterConnectionEstablishedEventError() throws Exception {
|
void decorateAfterConnectionEstablishedEventError() throws Exception {
|
||||||
WebSocketHandler decorated = this.factory.decorate(this.delegate);
|
WebSocketHandler decorated = this.factory.decorate(this.delegate);
|
||||||
willThrow(new IllegalStateException("Test throw on publishEvent")).given(this.eventPublisher)
|
willThrow(new IllegalStateException("Test throw on publishEvent")).given(this.eventPublisher)
|
||||||
.publishEvent(any(ApplicationEvent.class));
|
.publishEvent(any(ApplicationEvent.class));
|
||||||
|
|
||||||
decorated.afterConnectionEstablished(this.session);
|
decorated.afterConnectionEstablished(this.session);
|
||||||
|
|
||||||
|
|||||||
@@ -150,7 +150,7 @@ class WebSocketRegistryListenerTests {
|
|||||||
this.listener.onApplicationEvent(this.disconnect);
|
this.listener.onApplicationEvent(this.disconnect);
|
||||||
|
|
||||||
Map<String, Map<String, WebSocketSession>> httpSessionIdToWsSessions = (Map<String, Map<String, WebSocketSession>>) ReflectionTestUtils
|
Map<String, Map<String, WebSocketSession>> httpSessionIdToWsSessions = (Map<String, Map<String, WebSocketSession>>) ReflectionTestUtils
|
||||||
.getField(this.listener, "httpSessionIdToWsSessions");
|
.getField(this.listener, "httpSessionIdToWsSessions");
|
||||||
assertThat(httpSessionIdToWsSessions).isEmpty();
|
assertThat(httpSessionIdToWsSessions).isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ class SessionRepositoryMessageInterceptorTests {
|
|||||||
@Test
|
@Test
|
||||||
void preSendconstructorNullRepository() {
|
void preSendconstructorNullRepository() {
|
||||||
assertThatIllegalArgumentException().isThrownBy(() -> new SessionRepositoryMessageInterceptor<>(null))
|
assertThatIllegalArgumentException().isThrownBy(() -> new SessionRepositoryMessageInterceptor<>(null))
|
||||||
.withMessage("sessionRepository cannot be null");
|
.withMessage("sessionRepository cannot be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -132,14 +132,14 @@ class SessionRepositoryMessageInterceptorTests {
|
|||||||
@Test
|
@Test
|
||||||
void setMatchingMessageTypesNull() {
|
void setMatchingMessageTypesNull() {
|
||||||
assertThatIllegalArgumentException().isThrownBy(() -> this.interceptor.setMatchingMessageTypes(null))
|
assertThatIllegalArgumentException().isThrownBy(() -> this.interceptor.setMatchingMessageTypes(null))
|
||||||
.withMessage("matchingMessageTypes cannot be null or empty");
|
.withMessage("matchingMessageTypes cannot be null or empty");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void setMatchingMessageTypesEmpty() {
|
void setMatchingMessageTypesEmpty() {
|
||||||
assertThatIllegalArgumentException()
|
assertThatIllegalArgumentException()
|
||||||
.isThrownBy(() -> this.interceptor.setMatchingMessageTypes(Collections.emptySet()))
|
.isThrownBy(() -> this.interceptor.setMatchingMessageTypes(Collections.emptySet()))
|
||||||
.withMessage("matchingMessageTypes cannot be null or empty");
|
.withMessage("matchingMessageTypes cannot be null or empty");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ public abstract class AbstractClassLoaderTest<T> extends AbstractITest {
|
|||||||
"mongoSessionConverter");
|
"mongoSessionConverter");
|
||||||
ReflectionUtils.makeAccessible(mongoSessionConverterField);
|
ReflectionUtils.makeAccessible(mongoSessionConverterField);
|
||||||
AbstractMongoSessionConverter sessionConverter = (AbstractMongoSessionConverter) ReflectionUtils
|
AbstractMongoSessionConverter sessionConverter = (AbstractMongoSessionConverter) ReflectionUtils
|
||||||
.getField(mongoSessionConverterField, this.sessionRepository);
|
.getField(mongoSessionConverterField, this.sessionRepository);
|
||||||
|
|
||||||
AssertionsForClassTypes.assertThat(sessionConverter).isInstanceOf(JdkMongoSessionConverter.class);
|
AssertionsForClassTypes.assertThat(sessionConverter).isInstanceOf(JdkMongoSessionConverter.class);
|
||||||
|
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ public abstract class AbstractMongoRepositoryITest extends AbstractITest {
|
|||||||
assertThat(session.getId()).isEqualTo(toSave.getId());
|
assertThat(session.getId()).isEqualTo(toSave.getId());
|
||||||
assertThat(session.getAttributeNames()).isEqualTo(toSave.getAttributeNames());
|
assertThat(session.getAttributeNames()).isEqualTo(toSave.getAttributeNames());
|
||||||
assertThat(session.<String>getAttribute(expectedAttributeName))
|
assertThat(session.<String>getAttribute(expectedAttributeName))
|
||||||
.isEqualTo(toSave.getAttribute(expectedAttributeName));
|
.isEqualTo(toSave.getAttribute(expectedAttributeName));
|
||||||
|
|
||||||
this.repository.deleteById(toSave.getId());
|
this.repository.deleteById(toSave.getId());
|
||||||
|
|
||||||
@@ -400,7 +400,7 @@ public abstract class AbstractMongoRepositoryITest extends AbstractITest {
|
|||||||
public MongoOperations mongoOperations(MongoDBContainer mongoContainer) {
|
public MongoOperations mongoOperations(MongoDBContainer mongoContainer) {
|
||||||
|
|
||||||
MongoClient mongo = MongoClients
|
MongoClient mongo = MongoClients
|
||||||
.create("mongodb://" + mongoContainer.getHost() + ":" + mongoContainer.getFirstMappedPort());
|
.create("mongodb://" + mongoContainer.getHost() + ":" + mongoContainer.getFirstMappedPort());
|
||||||
return new MongoTemplate(mongo, "test");
|
return new MongoTemplate(mongo, "test");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -73,13 +73,14 @@ public class MongoDbDeleteJacksonSessionVerificationTest {
|
|||||||
|
|
||||||
// 1. Login and capture the SESSION cookie value.
|
// 1. Login and capture the SESSION cookie value.
|
||||||
|
|
||||||
FluxExchangeResult<String> loginResult = this.client.post().uri("/login")
|
FluxExchangeResult<String> loginResult = this.client.post()
|
||||||
.contentType(MediaType.APPLICATION_FORM_URLENCODED) //
|
.uri("/login")
|
||||||
.body(BodyInserters //
|
.contentType(MediaType.APPLICATION_FORM_URLENCODED) //
|
||||||
.fromFormData("username", "admin") //
|
.body(BodyInserters //
|
||||||
.with("password", "password")) //
|
.fromFormData("username", "admin") //
|
||||||
.exchange() //
|
.with("password", "password")) //
|
||||||
.returnResult(String.class);
|
.exchange() //
|
||||||
|
.returnResult(String.class);
|
||||||
|
|
||||||
AssertionsForClassTypes.assertThat(loginResult.getResponseHeaders().getLocation()).isEqualTo(URI.create("/"));
|
AssertionsForClassTypes.assertThat(loginResult.getResponseHeaders().getLocation()).isEqualTo(URI.create("/"));
|
||||||
|
|
||||||
@@ -87,42 +88,54 @@ public class MongoDbDeleteJacksonSessionVerificationTest {
|
|||||||
|
|
||||||
// 2. Fetch a protected resource using the SESSION cookie.
|
// 2. Fetch a protected resource using the SESSION cookie.
|
||||||
|
|
||||||
this.client.get().uri("/hello") //
|
this.client.get()
|
||||||
.cookie("SESSION", originalSessionId) //
|
.uri("/hello") //
|
||||||
.exchange() //
|
.cookie("SESSION", originalSessionId) //
|
||||||
.expectStatus().isOk() //
|
.exchange() //
|
||||||
.returnResult(String.class).getResponseBody() //
|
.expectStatus()
|
||||||
.as(StepVerifier::create) //
|
.isOk() //
|
||||||
.expectNext("HelloWorld") //
|
.returnResult(String.class)
|
||||||
.verifyComplete();
|
.getResponseBody() //
|
||||||
|
.as(StepVerifier::create) //
|
||||||
|
.expectNext("HelloWorld") //
|
||||||
|
.verifyComplete();
|
||||||
|
|
||||||
// 3. Logout using the SESSION cookie, and capture the new SESSION cookie.
|
// 3. Logout using the SESSION cookie, and capture the new SESSION cookie.
|
||||||
|
|
||||||
String newSessionId = this.client.post().uri("/logout") //
|
String newSessionId = this.client.post()
|
||||||
.cookie("SESSION", originalSessionId) //
|
.uri("/logout") //
|
||||||
.exchange() //
|
.cookie("SESSION", originalSessionId) //
|
||||||
.expectStatus().isFound() //
|
.exchange() //
|
||||||
.returnResult(String.class).getResponseCookies().getFirst("SESSION").getValue();
|
.expectStatus()
|
||||||
|
.isFound() //
|
||||||
|
.returnResult(String.class)
|
||||||
|
.getResponseCookies()
|
||||||
|
.getFirst("SESSION")
|
||||||
|
.getValue();
|
||||||
|
|
||||||
AssertionsForClassTypes.assertThat(newSessionId).isNotEqualTo(originalSessionId);
|
AssertionsForClassTypes.assertThat(newSessionId).isNotEqualTo(originalSessionId);
|
||||||
|
|
||||||
// 4. Verify the new SESSION cookie is not yet authorized.
|
// 4. Verify the new SESSION cookie is not yet authorized.
|
||||||
|
|
||||||
this.client.get().uri("/hello") //
|
this.client.get()
|
||||||
.cookie("SESSION", newSessionId) //
|
.uri("/hello") //
|
||||||
.exchange() //
|
.cookie("SESSION", newSessionId) //
|
||||||
.expectStatus().isFound() //
|
.exchange() //
|
||||||
.expectHeader()
|
.expectStatus()
|
||||||
.value(HttpHeaders.LOCATION, (value) -> AssertionsForClassTypes.assertThat(value).isEqualTo("/login"));
|
.isFound() //
|
||||||
|
.expectHeader()
|
||||||
|
.value(HttpHeaders.LOCATION, (value) -> AssertionsForClassTypes.assertThat(value).isEqualTo("/login"));
|
||||||
|
|
||||||
// 5. Verify the original SESSION cookie no longer works.
|
// 5. Verify the original SESSION cookie no longer works.
|
||||||
|
|
||||||
this.client.get().uri("/hello") //
|
this.client.get()
|
||||||
.cookie("SESSION", originalSessionId) //
|
.uri("/hello") //
|
||||||
.exchange() //
|
.cookie("SESSION", originalSessionId) //
|
||||||
.expectStatus().isFound() //
|
.exchange() //
|
||||||
.expectHeader()
|
.expectStatus()
|
||||||
.value(HttpHeaders.LOCATION, (value) -> AssertionsForClassTypes.assertThat(value).isEqualTo("/login"));
|
.isFound() //
|
||||||
|
.expectHeader()
|
||||||
|
.value(HttpHeaders.LOCATION, (value) -> AssertionsForClassTypes.assertThat(value).isEqualTo("/login"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@@ -142,23 +155,25 @@ public class MongoDbDeleteJacksonSessionVerificationTest {
|
|||||||
@Bean
|
@Bean
|
||||||
SecurityWebFilterChain securityWebFilterChain(ServerHttpSecurity http) {
|
SecurityWebFilterChain securityWebFilterChain(ServerHttpSecurity http) {
|
||||||
return http //
|
return http //
|
||||||
.logout()//
|
.logout()//
|
||||||
/**/.and() //
|
/**/.and() //
|
||||||
.formLogin() //
|
.formLogin() //
|
||||||
/**/.and() //
|
/**/.and() //
|
||||||
.csrf().disable() //
|
.csrf()
|
||||||
.authorizeExchange() //
|
.disable() //
|
||||||
.anyExchange().authenticated() //
|
.authorizeExchange() //
|
||||||
/**/.and() //
|
.anyExchange()
|
||||||
.build();
|
.authenticated() //
|
||||||
|
/**/.and() //
|
||||||
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
MapReactiveUserDetailsService userDetailsService() {
|
MapReactiveUserDetailsService userDetailsService() {
|
||||||
return new MapReactiveUserDetailsService(User.withUsername("admin") //
|
return new MapReactiveUserDetailsService(User.withUsername("admin") //
|
||||||
.password("{noop}password") //
|
.password("{noop}password") //
|
||||||
.roles("USER,ADMIN") //
|
.roles("USER,ADMIN") //
|
||||||
.build());
|
.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@@ -186,7 +201,7 @@ public class MongoDbDeleteJacksonSessionVerificationTest {
|
|||||||
ReactiveMongoOperations mongoOperations(MongoDBContainer mongoContainer) {
|
ReactiveMongoOperations mongoOperations(MongoDBContainer mongoContainer) {
|
||||||
|
|
||||||
MongoClient mongo = MongoClients
|
MongoClient mongo = MongoClients
|
||||||
.create("mongodb://" + mongoContainer.getHost() + ":" + mongoContainer.getFirstMappedPort());
|
.create("mongodb://" + mongoContainer.getHost() + ":" + mongoContainer.getFirstMappedPort());
|
||||||
return new ReactiveMongoTemplate(mongo, "DB_Name_DeleteJacksonSessionVerificationTest");
|
return new ReactiveMongoTemplate(mongo, "DB_Name_DeleteJacksonSessionVerificationTest");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -73,13 +73,14 @@ public class MongoDbLogoutVerificationTest {
|
|||||||
|
|
||||||
// 1. Login and capture the SESSION cookie value.
|
// 1. Login and capture the SESSION cookie value.
|
||||||
|
|
||||||
FluxExchangeResult<String> loginResult = this.client.post().uri("/login")
|
FluxExchangeResult<String> loginResult = this.client.post()
|
||||||
.contentType(MediaType.APPLICATION_FORM_URLENCODED) //
|
.uri("/login")
|
||||||
.body(BodyInserters //
|
.contentType(MediaType.APPLICATION_FORM_URLENCODED) //
|
||||||
.fromFormData("username", "admin") //
|
.body(BodyInserters //
|
||||||
.with("password", "password")) //
|
.fromFormData("username", "admin") //
|
||||||
.exchange() //
|
.with("password", "password")) //
|
||||||
.returnResult(String.class);
|
.exchange() //
|
||||||
|
.returnResult(String.class);
|
||||||
|
|
||||||
AssertionsForClassTypes.assertThat(loginResult.getResponseHeaders().getLocation()).isEqualTo(URI.create("/"));
|
AssertionsForClassTypes.assertThat(loginResult.getResponseHeaders().getLocation()).isEqualTo(URI.create("/"));
|
||||||
|
|
||||||
@@ -87,42 +88,54 @@ public class MongoDbLogoutVerificationTest {
|
|||||||
|
|
||||||
// 2. Fetch a protected resource using the SESSION cookie.
|
// 2. Fetch a protected resource using the SESSION cookie.
|
||||||
|
|
||||||
this.client.get().uri("/hello") //
|
this.client.get()
|
||||||
.cookie("SESSION", originalSessionId) //
|
.uri("/hello") //
|
||||||
.exchange() //
|
.cookie("SESSION", originalSessionId) //
|
||||||
.expectStatus().isOk() //
|
.exchange() //
|
||||||
.returnResult(String.class).getResponseBody() //
|
.expectStatus()
|
||||||
.as(StepVerifier::create) //
|
.isOk() //
|
||||||
.expectNext("HelloWorld") //
|
.returnResult(String.class)
|
||||||
.verifyComplete();
|
.getResponseBody() //
|
||||||
|
.as(StepVerifier::create) //
|
||||||
|
.expectNext("HelloWorld") //
|
||||||
|
.verifyComplete();
|
||||||
|
|
||||||
// 3. Logout using the SESSION cookie, and capture the new SESSION cookie.
|
// 3. Logout using the SESSION cookie, and capture the new SESSION cookie.
|
||||||
|
|
||||||
String newSessionId = this.client.post().uri("/logout") //
|
String newSessionId = this.client.post()
|
||||||
.cookie("SESSION", originalSessionId) //
|
.uri("/logout") //
|
||||||
.exchange() //
|
.cookie("SESSION", originalSessionId) //
|
||||||
.expectStatus().isFound() //
|
.exchange() //
|
||||||
.returnResult(String.class).getResponseCookies().getFirst("SESSION").getValue();
|
.expectStatus()
|
||||||
|
.isFound() //
|
||||||
|
.returnResult(String.class)
|
||||||
|
.getResponseCookies()
|
||||||
|
.getFirst("SESSION")
|
||||||
|
.getValue();
|
||||||
|
|
||||||
AssertionsForClassTypes.assertThat(newSessionId).isNotEqualTo(originalSessionId);
|
AssertionsForClassTypes.assertThat(newSessionId).isNotEqualTo(originalSessionId);
|
||||||
|
|
||||||
// 4. Verify the new SESSION cookie is not yet authorized.
|
// 4. Verify the new SESSION cookie is not yet authorized.
|
||||||
|
|
||||||
this.client.get().uri("/hello") //
|
this.client.get()
|
||||||
.cookie("SESSION", newSessionId) //
|
.uri("/hello") //
|
||||||
.exchange() //
|
.cookie("SESSION", newSessionId) //
|
||||||
.expectStatus().isFound() //
|
.exchange() //
|
||||||
.expectHeader()
|
.expectStatus()
|
||||||
.value(HttpHeaders.LOCATION, (value) -> AssertionsForClassTypes.assertThat(value).isEqualTo("/login"));
|
.isFound() //
|
||||||
|
.expectHeader()
|
||||||
|
.value(HttpHeaders.LOCATION, (value) -> AssertionsForClassTypes.assertThat(value).isEqualTo("/login"));
|
||||||
|
|
||||||
// 5. Verify the original SESSION cookie no longer works.
|
// 5. Verify the original SESSION cookie no longer works.
|
||||||
|
|
||||||
this.client.get().uri("/hello") //
|
this.client.get()
|
||||||
.cookie("SESSION", originalSessionId) //
|
.uri("/hello") //
|
||||||
.exchange() //
|
.cookie("SESSION", originalSessionId) //
|
||||||
.expectStatus().isFound() //
|
.exchange() //
|
||||||
.expectHeader()
|
.expectStatus()
|
||||||
.value(HttpHeaders.LOCATION, (value) -> AssertionsForClassTypes.assertThat(value).isEqualTo("/login"));
|
.isFound() //
|
||||||
|
.expectHeader()
|
||||||
|
.value(HttpHeaders.LOCATION, (value) -> AssertionsForClassTypes.assertThat(value).isEqualTo("/login"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@@ -143,24 +156,26 @@ public class MongoDbLogoutVerificationTest {
|
|||||||
SecurityWebFilterChain securityWebFilterChain(ServerHttpSecurity http) {
|
SecurityWebFilterChain securityWebFilterChain(ServerHttpSecurity http) {
|
||||||
|
|
||||||
return http //
|
return http //
|
||||||
.logout()//
|
.logout()//
|
||||||
/**/.and() //
|
/**/.and() //
|
||||||
.formLogin() //
|
.formLogin() //
|
||||||
/**/.and() //
|
/**/.and() //
|
||||||
.csrf().disable() //
|
.csrf()
|
||||||
.authorizeExchange() //
|
.disable() //
|
||||||
.anyExchange().authenticated() //
|
.authorizeExchange() //
|
||||||
/**/.and() //
|
.anyExchange()
|
||||||
.build();
|
.authenticated() //
|
||||||
|
/**/.and() //
|
||||||
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
MapReactiveUserDetailsService userDetailsService() {
|
MapReactiveUserDetailsService userDetailsService() {
|
||||||
|
|
||||||
return new MapReactiveUserDetailsService(User.withUsername("admin") //
|
return new MapReactiveUserDetailsService(User.withUsername("admin") //
|
||||||
.password("{noop}password") //
|
.password("{noop}password") //
|
||||||
.roles("USER,ADMIN") //
|
.roles("USER,ADMIN") //
|
||||||
.build());
|
.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -183,7 +198,7 @@ public class MongoDbLogoutVerificationTest {
|
|||||||
ReactiveMongoOperations mongoOperations(MongoDBContainer mongoContainer) {
|
ReactiveMongoOperations mongoOperations(MongoDBContainer mongoContainer) {
|
||||||
|
|
||||||
MongoClient mongo = MongoClients
|
MongoClient mongo = MongoClients
|
||||||
.create("mongodb://" + mongoContainer.getHost() + ":" + mongoContainer.getFirstMappedPort());
|
.create("mongodb://" + mongoContainer.getHost() + ":" + mongoContainer.getFirstMappedPort());
|
||||||
return new ReactiveMongoTemplate(mongo, "test");
|
return new ReactiveMongoTemplate(mongo, "test");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -86,13 +86,13 @@ public abstract class AbstractMongoSessionConverter implements GenericConverter
|
|||||||
LOG.info("Creating TTL index on field " + EXPIRE_AT_FIELD_NAME);
|
LOG.info("Creating TTL index on field " + EXPIRE_AT_FIELD_NAME);
|
||||||
|
|
||||||
sessionCollectionIndexes
|
sessionCollectionIndexes
|
||||||
.ensureIndex(new Index(EXPIRE_AT_FIELD_NAME, Sort.Direction.ASC).named(EXPIRE_AT_FIELD_NAME).expire(0));
|
.ensureIndex(new Index(EXPIRE_AT_FIELD_NAME, Sort.Direction.ASC).named(EXPIRE_AT_FIELD_NAME).expire(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String extractPrincipal(MongoSession expiringSession) {
|
protected String extractPrincipal(MongoSession expiringSession) {
|
||||||
|
|
||||||
return this.indexResolver.resolveIndexesFor(expiringSession)
|
return this.indexResolver.resolveIndexesFor(expiringSession)
|
||||||
.get(FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME);
|
.get(FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<ConvertiblePair> getConvertibleTypes() {
|
public Set<ConvertiblePair> getConvertibleTypes() {
|
||||||
|
|||||||
@@ -137,10 +137,11 @@ public class MongoIndexedSessionRepository
|
|||||||
public Map<String, MongoSession> findByIndexNameAndIndexValue(String indexName, String indexValue) {
|
public Map<String, MongoSession> findByIndexNameAndIndexValue(String indexName, String indexValue) {
|
||||||
|
|
||||||
return Optional.ofNullable(this.mongoSessionConverter.getQueryForIndex(indexName, indexValue))
|
return Optional.ofNullable(this.mongoSessionConverter.getQueryForIndex(indexName, indexValue))
|
||||||
.map((query) -> this.mongoOperations.find(query, Document.class, this.collectionName))
|
.map((query) -> this.mongoOperations.find(query, Document.class, this.collectionName))
|
||||||
.orElse(Collections.emptyList()).stream()
|
.orElse(Collections.emptyList())
|
||||||
.map((dbSession) -> MongoSessionUtils.convertToSession(this.mongoSessionConverter, dbSession))
|
.stream()
|
||||||
.collect(Collectors.toMap(MongoSession::getId, (mapSession) -> mapSession));
|
.map((dbSession) -> MongoSessionUtils.convertToSession(this.mongoSessionConverter, dbSession))
|
||||||
|
.collect(Collectors.toMap(MongoSession::getId, (mapSession) -> mapSession));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -95,50 +95,50 @@ public class ReactiveMongoSessionRepository
|
|||||||
public Mono<MongoSession> createSession() {
|
public Mono<MongoSession> createSession() {
|
||||||
|
|
||||||
return Mono.justOrEmpty(this.defaultMaxInactiveInterval.toSeconds()) //
|
return Mono.justOrEmpty(this.defaultMaxInactiveInterval.toSeconds()) //
|
||||||
.map(MongoSession::new) //
|
.map(MongoSession::new) //
|
||||||
.doOnNext((mongoSession) -> publishEvent(new SessionCreatedEvent(this, mongoSession))) //
|
.doOnNext((mongoSession) -> publishEvent(new SessionCreatedEvent(this, mongoSession))) //
|
||||||
.switchIfEmpty(Mono.just(new MongoSession()));
|
.switchIfEmpty(Mono.just(new MongoSession()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Mono<Void> save(MongoSession session) {
|
public Mono<Void> save(MongoSession session) {
|
||||||
|
|
||||||
return Mono //
|
return Mono //
|
||||||
.justOrEmpty(MongoSessionUtils.convertToDBObject(this.mongoSessionConverter, session)) //
|
.justOrEmpty(MongoSessionUtils.convertToDBObject(this.mongoSessionConverter, session)) //
|
||||||
.flatMap((dbObject) -> {
|
.flatMap((dbObject) -> {
|
||||||
if (session.hasChangedSessionId()) {
|
if (session.hasChangedSessionId()) {
|
||||||
|
|
||||||
return this.mongoOperations
|
return this.mongoOperations
|
||||||
.remove(Query.query(Criteria.where("_id").is(session.getOriginalSessionId())),
|
.remove(Query.query(Criteria.where("_id").is(session.getOriginalSessionId())),
|
||||||
this.collectionName) //
|
this.collectionName) //
|
||||||
.then(this.mongoOperations.save(dbObject, this.collectionName));
|
.then(this.mongoOperations.save(dbObject, this.collectionName));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
return this.mongoOperations.save(dbObject, this.collectionName);
|
return this.mongoOperations.save(dbObject, this.collectionName);
|
||||||
}
|
}
|
||||||
}) //
|
}) //
|
||||||
.then();
|
.then();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Mono<MongoSession> findById(String id) {
|
public Mono<MongoSession> findById(String id) {
|
||||||
|
|
||||||
return findSession(id) //
|
return findSession(id) //
|
||||||
.map((document) -> MongoSessionUtils.convertToSession(this.mongoSessionConverter, document)) //
|
.map((document) -> MongoSessionUtils.convertToSession(this.mongoSessionConverter, document)) //
|
||||||
.filter((mongoSession) -> !mongoSession.isExpired()) //
|
.filter((mongoSession) -> !mongoSession.isExpired()) //
|
||||||
.switchIfEmpty(Mono.defer(() -> this.deleteById(id).then(Mono.empty())));
|
.switchIfEmpty(Mono.defer(() -> this.deleteById(id).then(Mono.empty())));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Mono<Void> deleteById(String id) {
|
public Mono<Void> deleteById(String id) {
|
||||||
|
|
||||||
return findSession(id) //
|
return findSession(id) //
|
||||||
.flatMap((document) -> this.mongoOperations.remove(document, this.collectionName) //
|
.flatMap((document) -> this.mongoOperations.remove(document, this.collectionName) //
|
||||||
.then(Mono.just(document))) //
|
.then(Mono.just(document))) //
|
||||||
.map((document) -> MongoSessionUtils.convertToSession(this.mongoSessionConverter, document)) //
|
.map((document) -> MongoSessionUtils.convertToSession(this.mongoSessionConverter, document)) //
|
||||||
.doOnNext((mongoSession) -> publishEvent(new SessionDeletedEvent(this, mongoSession))) //
|
.doOnNext((mongoSession) -> publishEvent(new SessionDeletedEvent(this, mongoSession))) //
|
||||||
.then();
|
.then();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ public class MongoHttpSessionConfiguration implements BeanClassLoaderAware, Embe
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.sessionRepositoryCustomizers
|
this.sessionRepositoryCustomizers
|
||||||
.forEach((sessionRepositoryCustomizer) -> sessionRepositoryCustomizer.customize(repository));
|
.forEach((sessionRepositoryCustomizer) -> sessionRepositoryCustomizer.customize(repository));
|
||||||
|
|
||||||
return repository;
|
return repository;
|
||||||
}
|
}
|
||||||
@@ -121,11 +121,11 @@ public class MongoHttpSessionConfiguration implements BeanClassLoaderAware, Embe
|
|||||||
public void setImportMetadata(AnnotationMetadata importMetadata) {
|
public void setImportMetadata(AnnotationMetadata importMetadata) {
|
||||||
|
|
||||||
AnnotationAttributes attributes = AnnotationAttributes
|
AnnotationAttributes attributes = AnnotationAttributes
|
||||||
.fromMap(importMetadata.getAnnotationAttributes(EnableMongoHttpSession.class.getName()));
|
.fromMap(importMetadata.getAnnotationAttributes(EnableMongoHttpSession.class.getName()));
|
||||||
|
|
||||||
if (attributes != null) {
|
if (attributes != null) {
|
||||||
this.maxInactiveInterval = Duration
|
this.maxInactiveInterval = Duration
|
||||||
.ofSeconds(attributes.<Integer>getNumber("maxInactiveIntervalInSeconds"));
|
.ofSeconds(attributes.<Integer>getNumber("maxInactiveIntervalInSeconds"));
|
||||||
}
|
}
|
||||||
|
|
||||||
String collectionNameValue = (attributes != null) ? attributes.getString("collectionName") : "";
|
String collectionNameValue = (attributes != null) ? attributes.getString("collectionName") : "";
|
||||||
|
|||||||
@@ -110,7 +110,7 @@ public class ReactiveMongoWebSessionConfiguration
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.sessionRepositoryCustomizers
|
this.sessionRepositoryCustomizers
|
||||||
.forEach((sessionRepositoryCustomizer) -> sessionRepositoryCustomizer.customize(repository));
|
.forEach((sessionRepositoryCustomizer) -> sessionRepositoryCustomizer.customize(repository));
|
||||||
|
|
||||||
return repository;
|
return repository;
|
||||||
}
|
}
|
||||||
@@ -124,11 +124,11 @@ public class ReactiveMongoWebSessionConfiguration
|
|||||||
public void setImportMetadata(AnnotationMetadata importMetadata) {
|
public void setImportMetadata(AnnotationMetadata importMetadata) {
|
||||||
|
|
||||||
AnnotationAttributes attributes = AnnotationAttributes
|
AnnotationAttributes attributes = AnnotationAttributes
|
||||||
.fromMap(importMetadata.getAnnotationAttributes(EnableMongoWebSession.class.getName()));
|
.fromMap(importMetadata.getAnnotationAttributes(EnableMongoWebSession.class.getName()));
|
||||||
|
|
||||||
if (attributes != null) {
|
if (attributes != null) {
|
||||||
this.maxInactiveInterval = Duration
|
this.maxInactiveInterval = Duration
|
||||||
.ofSeconds(attributes.<Integer>getNumber("maxInactiveIntervalInSeconds"));
|
.ofSeconds(attributes.<Integer>getNumber("maxInactiveIntervalInSeconds"));
|
||||||
}
|
}
|
||||||
|
|
||||||
String collectionNameValue = (attributes != null) ? attributes.getString("collectionName") : "";
|
String collectionNameValue = (attributes != null) ? attributes.getString("collectionName") : "";
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ public class JacksonMongoSessionConverterTest extends AbstractMongoSessionConver
|
|||||||
void shouldNotAllowNullObjectMapperToBeInjected() {
|
void shouldNotAllowNullObjectMapperToBeInjected() {
|
||||||
|
|
||||||
Assertions.assertThatIllegalArgumentException()
|
Assertions.assertThatIllegalArgumentException()
|
||||||
.isThrownBy(() -> new JacksonMongoSessionConverter((ObjectMapper) null));
|
.isThrownBy(() -> new JacksonMongoSessionConverter((ObjectMapper) null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -43,14 +43,14 @@ public class JdkMongoSessionConverterTest extends AbstractMongoSessionConverterT
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void constructorNullSerializer() {
|
void constructorNullSerializer() {
|
||||||
assertThatIllegalArgumentException().isThrownBy(
|
assertThatIllegalArgumentException()
|
||||||
() -> new JdkMongoSessionConverter(null, new DeserializingConverter(), this.inactiveInterval));
|
.isThrownBy(() -> new JdkMongoSessionConverter(null, new DeserializingConverter(), this.inactiveInterval));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void constructorNullDeserializer() {
|
void constructorNullDeserializer() {
|
||||||
assertThatIllegalArgumentException().isThrownBy(
|
assertThatIllegalArgumentException()
|
||||||
() -> new JdkMongoSessionConverter(new SerializingConverter(), null, this.inactiveInterval));
|
.isThrownBy(() -> new JdkMongoSessionConverter(new SerializingConverter(), null, this.inactiveInterval));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ public class MongoIndexedSessionRepositoryTest {
|
|||||||
// then
|
// then
|
||||||
assertThat(session.getId()).isNotEmpty();
|
assertThat(session.getId()).isNotEmpty();
|
||||||
assertThat(session.getMaxInactiveInterval().getSeconds())
|
assertThat(session.getMaxInactiveInterval().getSeconds())
|
||||||
.isEqualTo(MapSession.DEFAULT_MAX_INACTIVE_INTERVAL_SECONDS);
|
.isEqualTo(MapSession.DEFAULT_MAX_INACTIVE_INTERVAL_SECONDS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -88,7 +88,8 @@ public class MongoIndexedSessionRepositoryTest {
|
|||||||
BasicDBObject dbSession = new BasicDBObject();
|
BasicDBObject dbSession = new BasicDBObject();
|
||||||
|
|
||||||
given(this.converter.convert(session, TypeDescriptor.valueOf(MongoSession.class),
|
given(this.converter.convert(session, TypeDescriptor.valueOf(MongoSession.class),
|
||||||
TypeDescriptor.valueOf(DBObject.class))).willReturn(dbSession);
|
TypeDescriptor.valueOf(DBObject.class)))
|
||||||
|
.willReturn(dbSession);
|
||||||
// when
|
// when
|
||||||
this.repository.save(session);
|
this.repository.save(session);
|
||||||
|
|
||||||
@@ -104,12 +105,14 @@ public class MongoIndexedSessionRepositoryTest {
|
|||||||
Document sessionDocument = new Document();
|
Document sessionDocument = new Document();
|
||||||
|
|
||||||
given(this.mongoOperations.findById(sessionId, Document.class,
|
given(this.mongoOperations.findById(sessionId, Document.class,
|
||||||
MongoIndexedSessionRepository.DEFAULT_COLLECTION_NAME)).willReturn(sessionDocument);
|
MongoIndexedSessionRepository.DEFAULT_COLLECTION_NAME))
|
||||||
|
.willReturn(sessionDocument);
|
||||||
|
|
||||||
MongoSession session = new MongoSession();
|
MongoSession session = new MongoSession();
|
||||||
|
|
||||||
given(this.converter.convert(sessionDocument, TypeDescriptor.valueOf(Document.class),
|
given(this.converter.convert(sessionDocument, TypeDescriptor.valueOf(Document.class),
|
||||||
TypeDescriptor.valueOf(MongoSession.class))).willReturn(session);
|
TypeDescriptor.valueOf(MongoSession.class)))
|
||||||
|
.willReturn(session);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
MongoSession retrievedSession = this.repository.findById(sessionId);
|
MongoSession retrievedSession = this.repository.findById(sessionId);
|
||||||
@@ -126,13 +129,15 @@ public class MongoIndexedSessionRepositoryTest {
|
|||||||
Document sessionDocument = new Document();
|
Document sessionDocument = new Document();
|
||||||
|
|
||||||
given(this.mongoOperations.findById(sessionId, Document.class,
|
given(this.mongoOperations.findById(sessionId, Document.class,
|
||||||
MongoIndexedSessionRepository.DEFAULT_COLLECTION_NAME)).willReturn(sessionDocument);
|
MongoIndexedSessionRepository.DEFAULT_COLLECTION_NAME))
|
||||||
|
.willReturn(sessionDocument);
|
||||||
|
|
||||||
MongoSession session = mock(MongoSession.class);
|
MongoSession session = mock(MongoSession.class);
|
||||||
|
|
||||||
given(session.isExpired()).willReturn(true);
|
given(session.isExpired()).willReturn(true);
|
||||||
given(this.converter.convert(sessionDocument, TypeDescriptor.valueOf(Document.class),
|
given(this.converter.convert(sessionDocument, TypeDescriptor.valueOf(Document.class),
|
||||||
TypeDescriptor.valueOf(MongoSession.class))).willReturn(session);
|
TypeDescriptor.valueOf(MongoSession.class)))
|
||||||
|
.willReturn(session);
|
||||||
given(session.getId()).willReturn("sessionId");
|
given(session.getId()).willReturn("sessionId");
|
||||||
|
|
||||||
// when
|
// when
|
||||||
@@ -155,9 +160,11 @@ public class MongoIndexedSessionRepositoryTest {
|
|||||||
MongoSession mongoSession = new MongoSession(sessionId, MapSession.DEFAULT_MAX_INACTIVE_INTERVAL_SECONDS);
|
MongoSession mongoSession = new MongoSession(sessionId, MapSession.DEFAULT_MAX_INACTIVE_INTERVAL_SECONDS);
|
||||||
|
|
||||||
given(this.converter.convert(sessionDocument, TypeDescriptor.valueOf(Document.class),
|
given(this.converter.convert(sessionDocument, TypeDescriptor.valueOf(Document.class),
|
||||||
TypeDescriptor.valueOf(MongoSession.class))).willReturn(mongoSession);
|
TypeDescriptor.valueOf(MongoSession.class)))
|
||||||
|
.willReturn(mongoSession);
|
||||||
given(this.mongoOperations.findById(eq(sessionId), eq(Document.class),
|
given(this.mongoOperations.findById(eq(sessionId), eq(Document.class),
|
||||||
eq(MongoIndexedSessionRepository.DEFAULT_COLLECTION_NAME))).willReturn(sessionDocument);
|
eq(MongoIndexedSessionRepository.DEFAULT_COLLECTION_NAME)))
|
||||||
|
.willReturn(sessionDocument);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
this.repository.deleteById(sessionId);
|
this.repository.deleteById(sessionId);
|
||||||
@@ -178,14 +185,15 @@ public class MongoIndexedSessionRepositoryTest {
|
|||||||
given(this.converter.getQueryForIndex(anyString(), any(Object.class))).willReturn(mock(Query.class));
|
given(this.converter.getQueryForIndex(anyString(), any(Object.class))).willReturn(mock(Query.class));
|
||||||
given(this.mongoOperations.find(any(Query.class), eq(Document.class),
|
given(this.mongoOperations.find(any(Query.class), eq(Document.class),
|
||||||
eq(MongoIndexedSessionRepository.DEFAULT_COLLECTION_NAME)))
|
eq(MongoIndexedSessionRepository.DEFAULT_COLLECTION_NAME)))
|
||||||
.willReturn(Collections.singletonList(document));
|
.willReturn(Collections.singletonList(document));
|
||||||
|
|
||||||
String sessionId = UUID.randomUUID().toString();
|
String sessionId = UUID.randomUUID().toString();
|
||||||
|
|
||||||
MongoSession session = new MongoSession(sessionId, 1800);
|
MongoSession session = new MongoSession(sessionId, 1800);
|
||||||
|
|
||||||
given(this.converter.convert(document, TypeDescriptor.valueOf(Document.class),
|
given(this.converter.convert(document, TypeDescriptor.valueOf(Document.class),
|
||||||
TypeDescriptor.valueOf(MongoSession.class))).willReturn(session);
|
TypeDescriptor.valueOf(MongoSession.class)))
|
||||||
|
.willReturn(session);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
Map<String, MongoSession> sessionsMap = this.repository.findByIndexNameAndIndexValue(principalNameIndexName,
|
Map<String, MongoSession> sessionsMap = this.repository.findByIndexNameAndIndexValue(principalNameIndexName,
|
||||||
|
|||||||
@@ -83,14 +83,14 @@ public class ReactiveMongoSessionRepositoryTest {
|
|||||||
void shouldCreateSession() {
|
void shouldCreateSession() {
|
||||||
|
|
||||||
this.repository.createSession() //
|
this.repository.createSession() //
|
||||||
.as(StepVerifier::create) //
|
.as(StepVerifier::create) //
|
||||||
.expectNextMatches((mongoSession) -> {
|
.expectNextMatches((mongoSession) -> {
|
||||||
assertThat(mongoSession.getId()).isNotEmpty();
|
assertThat(mongoSession.getId()).isNotEmpty();
|
||||||
assertThat(mongoSession.getMaxInactiveInterval())
|
assertThat(mongoSession.getMaxInactiveInterval())
|
||||||
.isEqualTo(Duration.ofSeconds(MapSession.DEFAULT_MAX_INACTIVE_INTERVAL_SECONDS));
|
.isEqualTo(Duration.ofSeconds(MapSession.DEFAULT_MAX_INACTIVE_INTERVAL_SECONDS));
|
||||||
return true;
|
return true;
|
||||||
}) //
|
}) //
|
||||||
.verifyComplete();
|
.verifyComplete();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -101,14 +101,15 @@ public class ReactiveMongoSessionRepositoryTest {
|
|||||||
BasicDBObject dbSession = new BasicDBObject();
|
BasicDBObject dbSession = new BasicDBObject();
|
||||||
|
|
||||||
given(this.converter.convert(session, TypeDescriptor.valueOf(MongoSession.class),
|
given(this.converter.convert(session, TypeDescriptor.valueOf(MongoSession.class),
|
||||||
TypeDescriptor.valueOf(DBObject.class))).willReturn(dbSession);
|
TypeDescriptor.valueOf(DBObject.class)))
|
||||||
|
.willReturn(dbSession);
|
||||||
|
|
||||||
given(this.mongoOperations.save(dbSession, "sessions")).willReturn(Mono.just(dbSession));
|
given(this.mongoOperations.save(dbSession, "sessions")).willReturn(Mono.just(dbSession));
|
||||||
|
|
||||||
// when
|
// when
|
||||||
this.repository.save(session) //
|
this.repository.save(session) //
|
||||||
.as(StepVerifier::create) //
|
.as(StepVerifier::create) //
|
||||||
.verifyComplete();
|
.verifyComplete();
|
||||||
|
|
||||||
verify(this.mongoOperations).save(dbSession, ReactiveMongoSessionRepository.DEFAULT_COLLECTION_NAME);
|
verify(this.mongoOperations).save(dbSession, ReactiveMongoSessionRepository.DEFAULT_COLLECTION_NAME);
|
||||||
}
|
}
|
||||||
@@ -121,18 +122,20 @@ public class ReactiveMongoSessionRepositoryTest {
|
|||||||
Document sessionDocument = new Document();
|
Document sessionDocument = new Document();
|
||||||
|
|
||||||
given(this.mongoOperations.findById(sessionId, Document.class,
|
given(this.mongoOperations.findById(sessionId, Document.class,
|
||||||
ReactiveMongoSessionRepository.DEFAULT_COLLECTION_NAME)).willReturn(Mono.just(sessionDocument));
|
ReactiveMongoSessionRepository.DEFAULT_COLLECTION_NAME))
|
||||||
|
.willReturn(Mono.just(sessionDocument));
|
||||||
|
|
||||||
MongoSession session = new MongoSession();
|
MongoSession session = new MongoSession();
|
||||||
|
|
||||||
given(this.converter.convert(sessionDocument, TypeDescriptor.valueOf(Document.class),
|
given(this.converter.convert(sessionDocument, TypeDescriptor.valueOf(Document.class),
|
||||||
TypeDescriptor.valueOf(MongoSession.class))).willReturn(session);
|
TypeDescriptor.valueOf(MongoSession.class)))
|
||||||
|
.willReturn(session);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
this.repository.findById(sessionId) //
|
this.repository.findById(sessionId) //
|
||||||
.as(StepVerifier::create) //
|
.as(StepVerifier::create) //
|
||||||
.expectNext(session) //
|
.expectNext(session) //
|
||||||
.verifyComplete();
|
.verifyComplete();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -143,21 +146,23 @@ public class ReactiveMongoSessionRepositoryTest {
|
|||||||
Document sessionDocument = new Document();
|
Document sessionDocument = new Document();
|
||||||
|
|
||||||
given(this.mongoOperations.findById(sessionId, Document.class,
|
given(this.mongoOperations.findById(sessionId, Document.class,
|
||||||
ReactiveMongoSessionRepository.DEFAULT_COLLECTION_NAME)).willReturn(Mono.just(sessionDocument));
|
ReactiveMongoSessionRepository.DEFAULT_COLLECTION_NAME))
|
||||||
|
.willReturn(Mono.just(sessionDocument));
|
||||||
|
|
||||||
given(this.mongoOperations.remove(sessionDocument, ReactiveMongoSessionRepository.DEFAULT_COLLECTION_NAME))
|
given(this.mongoOperations.remove(sessionDocument, ReactiveMongoSessionRepository.DEFAULT_COLLECTION_NAME))
|
||||||
.willReturn(Mono.just(DeleteResult.acknowledged(1)));
|
.willReturn(Mono.just(DeleteResult.acknowledged(1)));
|
||||||
|
|
||||||
MongoSession session = mock(MongoSession.class);
|
MongoSession session = mock(MongoSession.class);
|
||||||
|
|
||||||
given(session.isExpired()).willReturn(true);
|
given(session.isExpired()).willReturn(true);
|
||||||
given(this.converter.convert(sessionDocument, TypeDescriptor.valueOf(Document.class),
|
given(this.converter.convert(sessionDocument, TypeDescriptor.valueOf(Document.class),
|
||||||
TypeDescriptor.valueOf(MongoSession.class))).willReturn(session);
|
TypeDescriptor.valueOf(MongoSession.class)))
|
||||||
|
.willReturn(session);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
this.repository.findById(sessionId) //
|
this.repository.findById(sessionId) //
|
||||||
.as(StepVerifier::create) //
|
.as(StepVerifier::create) //
|
||||||
.verifyComplete();
|
.verifyComplete();
|
||||||
|
|
||||||
// then
|
// then
|
||||||
verify(this.mongoOperations).remove(any(Document.class),
|
verify(this.mongoOperations).remove(any(Document.class),
|
||||||
@@ -172,20 +177,22 @@ public class ReactiveMongoSessionRepositoryTest {
|
|||||||
Document sessionDocument = new Document();
|
Document sessionDocument = new Document();
|
||||||
|
|
||||||
given(this.mongoOperations.findById(sessionId, Document.class,
|
given(this.mongoOperations.findById(sessionId, Document.class,
|
||||||
ReactiveMongoSessionRepository.DEFAULT_COLLECTION_NAME)).willReturn(Mono.just(sessionDocument));
|
ReactiveMongoSessionRepository.DEFAULT_COLLECTION_NAME))
|
||||||
|
.willReturn(Mono.just(sessionDocument));
|
||||||
|
|
||||||
given(this.mongoOperations.remove(sessionDocument, "sessions"))
|
given(this.mongoOperations.remove(sessionDocument, "sessions"))
|
||||||
.willReturn(Mono.just(DeleteResult.acknowledged(1)));
|
.willReturn(Mono.just(DeleteResult.acknowledged(1)));
|
||||||
|
|
||||||
MongoSession session = mock(MongoSession.class);
|
MongoSession session = mock(MongoSession.class);
|
||||||
|
|
||||||
given(this.converter.convert(sessionDocument, TypeDescriptor.valueOf(Document.class),
|
given(this.converter.convert(sessionDocument, TypeDescriptor.valueOf(Document.class),
|
||||||
TypeDescriptor.valueOf(MongoSession.class))).willReturn(session);
|
TypeDescriptor.valueOf(MongoSession.class)))
|
||||||
|
.willReturn(session);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
this.repository.deleteById(sessionId) //
|
this.repository.deleteById(sessionId) //
|
||||||
.as(StepVerifier::create) //
|
.as(StepVerifier::create) //
|
||||||
.verifyComplete();
|
.verifyComplete();
|
||||||
|
|
||||||
verify(this.mongoOperations).remove(any(Document.class),
|
verify(this.mongoOperations).remove(any(Document.class),
|
||||||
eq(ReactiveMongoSessionRepository.DEFAULT_COLLECTION_NAME));
|
eq(ReactiveMongoSessionRepository.DEFAULT_COLLECTION_NAME));
|
||||||
|
|||||||
@@ -72,8 +72,8 @@ public class MongoHttpSessionConfigurationTest {
|
|||||||
void noMongoOperationsConfiguration() {
|
void noMongoOperationsConfiguration() {
|
||||||
|
|
||||||
assertThatExceptionOfType(UnsatisfiedDependencyException.class)
|
assertThatExceptionOfType(UnsatisfiedDependencyException.class)
|
||||||
.isThrownBy(() -> registerAndRefresh(EmptyConfiguration.class))
|
.isThrownBy(() -> registerAndRefresh(EmptyConfiguration.class))
|
||||||
.withMessageContaining("mongoSessionRepository");
|
.withMessageContaining("mongoSessionRepository");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -114,7 +114,7 @@ public class MongoHttpSessionConfigurationTest {
|
|||||||
MongoIndexedSessionRepository repository = this.context.getBean(MongoIndexedSessionRepository.class);
|
MongoIndexedSessionRepository repository = this.context.getBean(MongoIndexedSessionRepository.class);
|
||||||
|
|
||||||
assertThat(repository).extracting("defaultMaxInactiveInterval")
|
assertThat(repository).extracting("defaultMaxInactiveInterval")
|
||||||
.isEqualTo(Duration.ofSeconds(MAX_INACTIVE_INTERVAL_IN_SECONDS));
|
.isEqualTo(Duration.ofSeconds(MAX_INACTIVE_INTERVAL_IN_SECONDS));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -125,7 +125,7 @@ public class MongoHttpSessionConfigurationTest {
|
|||||||
MongoIndexedSessionRepository repository = this.context.getBean(MongoIndexedSessionRepository.class);
|
MongoIndexedSessionRepository repository = this.context.getBean(MongoIndexedSessionRepository.class);
|
||||||
|
|
||||||
assertThat(repository).extracting("defaultMaxInactiveInterval")
|
assertThat(repository).extracting("defaultMaxInactiveInterval")
|
||||||
.isEqualTo(Duration.ofSeconds(MAX_INACTIVE_INTERVAL_IN_SECONDS));
|
.isEqualTo(Duration.ofSeconds(MAX_INACTIVE_INTERVAL_IN_SECONDS));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -145,7 +145,7 @@ public class MongoHttpSessionConfigurationTest {
|
|||||||
void resolveCollectionNameByPropertyPlaceholder() {
|
void resolveCollectionNameByPropertyPlaceholder() {
|
||||||
|
|
||||||
this.context
|
this.context
|
||||||
.setEnvironment(new MockEnvironment().withProperty("session.mongo.collectionName", COLLECTION_NAME));
|
.setEnvironment(new MockEnvironment().withProperty("session.mongo.collectionName", COLLECTION_NAME));
|
||||||
registerAndRefresh(CustomMongoJdbcSessionConfiguration.class);
|
registerAndRefresh(CustomMongoJdbcSessionConfiguration.class);
|
||||||
|
|
||||||
MongoHttpSessionConfiguration configuration = this.context.getBean(MongoHttpSessionConfiguration.class);
|
MongoHttpSessionConfiguration configuration = this.context.getBean(MongoHttpSessionConfiguration.class);
|
||||||
@@ -174,8 +174,8 @@ public class MongoHttpSessionConfigurationTest {
|
|||||||
|
|
||||||
assertThat(repository).isNotNull();
|
assertThat(repository).isNotNull();
|
||||||
assertThat(indexResolver).isNotNull();
|
assertThat(indexResolver).isNotNull();
|
||||||
assertThat(repository).extracting("mongoSessionConverter").hasFieldOrPropertyWithValue("indexResolver",
|
assertThat(repository).extracting("mongoSessionConverter")
|
||||||
indexResolver);
|
.hasFieldOrPropertyWithValue("indexResolver", indexResolver);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -189,8 +189,8 @@ public class MongoHttpSessionConfigurationTest {
|
|||||||
|
|
||||||
assertThat(repository).isNotNull();
|
assertThat(repository).isNotNull();
|
||||||
assertThat(indexResolver).isNotNull();
|
assertThat(indexResolver).isNotNull();
|
||||||
assertThat(repository).extracting("mongoSessionConverter").hasFieldOrPropertyWithValue("indexResolver",
|
assertThat(repository).extracting("mongoSessionConverter")
|
||||||
indexResolver);
|
.hasFieldOrPropertyWithValue("indexResolver", indexResolver);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -95,9 +95,8 @@ public class ReactiveMongoWebSessionConfigurationTest {
|
|||||||
this.context.register(BadConfig.class);
|
this.context.register(BadConfig.class);
|
||||||
|
|
||||||
assertThatExceptionOfType(UnsatisfiedDependencyException.class).isThrownBy(this.context::refresh)
|
assertThatExceptionOfType(UnsatisfiedDependencyException.class).isThrownBy(this.context::refresh)
|
||||||
.withMessageContaining("Error creating bean with name 'reactiveMongoSessionRepository'")
|
.withMessageContaining("Error creating bean with name 'reactiveMongoSessionRepository'")
|
||||||
.withMessageContaining(
|
.withMessageContaining("No qualifying bean of type '" + ReactiveMongoOperations.class.getCanonicalName());
|
||||||
"No qualifying bean of type '" + ReactiveMongoOperations.class.getCanonicalName());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -193,8 +192,8 @@ public class ReactiveMongoWebSessionConfigurationTest {
|
|||||||
|
|
||||||
assertThat(repository).isNotNull();
|
assertThat(repository).isNotNull();
|
||||||
assertThat(indexResolver).isNotNull();
|
assertThat(indexResolver).isNotNull();
|
||||||
assertThat(repository).extracting("mongoSessionConverter").hasFieldOrPropertyWithValue("indexResolver",
|
assertThat(repository).extracting("mongoSessionConverter")
|
||||||
indexResolver);
|
.hasFieldOrPropertyWithValue("indexResolver", indexResolver);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -209,8 +208,8 @@ public class ReactiveMongoWebSessionConfigurationTest {
|
|||||||
|
|
||||||
assertThat(repository).isNotNull();
|
assertThat(repository).isNotNull();
|
||||||
assertThat(indexResolver).isNotNull();
|
assertThat(indexResolver).isNotNull();
|
||||||
assertThat(repository).extracting("mongoSessionConverter").hasFieldOrPropertyWithValue("indexResolver",
|
assertThat(repository).extracting("mongoSessionConverter")
|
||||||
indexResolver);
|
.hasFieldOrPropertyWithValue("indexResolver", indexResolver);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ class ReactiveRedisSessionRepositoryITests extends AbstractRedisITests {
|
|||||||
assertThat(session.getId()).isEqualTo(toSave.getId());
|
assertThat(session.getId()).isEqualTo(toSave.getId());
|
||||||
assertThat(session.getAttributeNames()).isEqualTo(toSave.getAttributeNames());
|
assertThat(session.getAttributeNames()).isEqualTo(toSave.getAttributeNames());
|
||||||
assertThat(session.<String>getAttribute(expectedAttributeName))
|
assertThat(session.<String>getAttribute(expectedAttributeName))
|
||||||
.isEqualTo(toSave.getAttribute(expectedAttributeName));
|
.isEqualTo(toSave.getAttribute(expectedAttributeName));
|
||||||
|
|
||||||
this.repository.deleteById(toSave.getId()).block();
|
this.repository.deleteById(toSave.getId()).block();
|
||||||
|
|
||||||
@@ -229,7 +229,7 @@ class ReactiveRedisSessionRepositoryITests extends AbstractRedisITests {
|
|||||||
toSave.setLastAccessedTime(Instant.now());
|
toSave.setLastAccessedTime(Instant.now());
|
||||||
|
|
||||||
assertThatIllegalStateException().isThrownBy(() -> this.repository.save(toSave).block())
|
assertThatIllegalStateException().isThrownBy(() -> this.repository.save(toSave).block())
|
||||||
.withMessage("Session was invalidated");
|
.withMessage("Session was invalidated");
|
||||||
|
|
||||||
assertThat(this.repository.findById(sessionId).block()).isNull();
|
assertThat(this.repository.findById(sessionId).block()).isNull();
|
||||||
assertThat(this.repository.findById(session.getId()).block()).isNotNull();
|
assertThat(this.repository.findById(session.getId()).block()).isNotNull();
|
||||||
@@ -240,7 +240,7 @@ class ReactiveRedisSessionRepositoryITests extends AbstractRedisITests {
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
void saveChangeSessionIdAfterCheckWhenOriginalKeyDoesNotExistsThenIgnoreError() {
|
void saveChangeSessionIdAfterCheckWhenOriginalKeyDoesNotExistsThenIgnoreError() {
|
||||||
ReactiveRedisOperations<String, Object> sessionRedisOperations = (ReactiveRedisOperations<String, Object>) ReflectionTestUtils
|
ReactiveRedisOperations<String, Object> sessionRedisOperations = (ReactiveRedisOperations<String, Object>) ReflectionTestUtils
|
||||||
.getField(this.repository, "sessionRedisOperations");
|
.getField(this.repository, "sessionRedisOperations");
|
||||||
ReactiveRedisOperations<String, Object> spyOperations = spy(sessionRedisOperations);
|
ReactiveRedisOperations<String, Object> spyOperations = spy(sessionRedisOperations);
|
||||||
ReflectionTestUtils.setField(this.repository, "sessionRedisOperations", spyOperations);
|
ReflectionTestUtils.setField(this.repository, "sessionRedisOperations", spyOperations);
|
||||||
|
|
||||||
@@ -267,7 +267,8 @@ class ReactiveRedisSessionRepositoryITests extends AbstractRedisITests {
|
|||||||
ReactiveHashOperations<String, Object, Object> opsForHash = spy(this.sessionRedisOperations.opsForHash());
|
ReactiveHashOperations<String, Object, Object> opsForHash = spy(this.sessionRedisOperations.opsForHash());
|
||||||
given(spy.opsForHash()).willReturn(opsForHash);
|
given(spy.opsForHash()).willReturn(opsForHash);
|
||||||
willAnswer((invocation) -> Mono.delay(Duration.ofSeconds(1)).then((Mono<Void>) invocation.callRealMethod()))
|
willAnswer((invocation) -> Mono.delay(Duration.ofSeconds(1)).then((Mono<Void>) invocation.callRealMethod()))
|
||||||
.given(opsForHash).putAll(anyString(), any());
|
.given(opsForHash)
|
||||||
|
.putAll(anyString(), any());
|
||||||
RedisSession toSave = this.repository.createSession().block();
|
RedisSession toSave = this.repository.createSession().block();
|
||||||
|
|
||||||
String expectedAttributeName = "a";
|
String expectedAttributeName = "a";
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ class RedisIndexedSessionRepositoryDynamicITests extends AbstractRedisITests {
|
|||||||
this.context.refresh();
|
this.context.refresh();
|
||||||
this.sessionRepository = this.context.getBean(RedisIndexedSessionRepository.class);
|
this.sessionRepository = this.context.getBean(RedisIndexedSessionRepository.class);
|
||||||
RedisOperations<String, Object> redisOperations = (RedisOperations<String, Object>) ReflectionTestUtils
|
RedisOperations<String, Object> redisOperations = (RedisOperations<String, Object>) ReflectionTestUtils
|
||||||
.getField(this.sessionRepository, "sessionRedisOperations");
|
.getField(this.sessionRepository, "sessionRedisOperations");
|
||||||
this.spyOperations = spy(redisOperations);
|
this.spyOperations = spy(redisOperations);
|
||||||
ReflectionTestUtils.setField(this.sessionRepository, "sessionRedisOperations", this.spyOperations);
|
ReflectionTestUtils.setField(this.sessionRepository, "sessionRedisOperations", this.spyOperations);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -119,7 +119,7 @@ class RedisIndexedSessionRepositoryITests extends AbstractRedisITests {
|
|||||||
assertThat(session.getId()).isEqualTo(toSave.getId());
|
assertThat(session.getId()).isEqualTo(toSave.getId());
|
||||||
assertThat(session.getAttributeNames()).isEqualTo(toSave.getAttributeNames());
|
assertThat(session.getAttributeNames()).isEqualTo(toSave.getAttributeNames());
|
||||||
assertThat(session.<String>getAttribute(expectedAttributeName))
|
assertThat(session.<String>getAttribute(expectedAttributeName))
|
||||||
.isEqualTo(toSave.getAttribute(expectedAttributeName));
|
.isEqualTo(toSave.getAttribute(expectedAttributeName));
|
||||||
|
|
||||||
this.registry.clear();
|
this.registry.clear();
|
||||||
|
|
||||||
@@ -127,11 +127,11 @@ class RedisIndexedSessionRepositoryITests extends AbstractRedisITests {
|
|||||||
|
|
||||||
assertThat(this.repository.findById(toSave.getId())).isNull();
|
assertThat(this.repository.findById(toSave.getId())).isNull();
|
||||||
assertThat(this.registry.<SessionDestroyedEvent>getEvent(toSave.getId()))
|
assertThat(this.registry.<SessionDestroyedEvent>getEvent(toSave.getId()))
|
||||||
.isInstanceOf(SessionDestroyedEvent.class);
|
.isInstanceOf(SessionDestroyedEvent.class);
|
||||||
assertThat(this.redis.boundSetOps(usernameSessionKey).members()).doesNotContain(toSave.getId());
|
assertThat(this.redis.boundSetOps(usernameSessionKey).members()).doesNotContain(toSave.getId());
|
||||||
|
|
||||||
assertThat(this.registry.getEvent(toSave.getId()).getSession().<String>getAttribute(expectedAttributeName))
|
assertThat(this.registry.getEvent(toSave.getId()).getSession().<String>getAttribute(expectedAttributeName))
|
||||||
.isEqualTo(expectedAttributeValue);
|
.isEqualTo(expectedAttributeValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ class RedisSessionRepositoryITests extends AbstractRedisITests {
|
|||||||
void save_NewSession_ShouldSaveSession() {
|
void save_NewSession_ShouldSaveSession() {
|
||||||
RedisSession session = createAndSaveSession(Instant.now());
|
RedisSession session = createAndSaveSession(Instant.now());
|
||||||
assertThat(session.getMaxInactiveInterval())
|
assertThat(session.getMaxInactiveInterval())
|
||||||
.isEqualTo(Duration.ofSeconds(MapSession.DEFAULT_MAX_INACTIVE_INTERVAL_SECONDS));
|
.isEqualTo(Duration.ofSeconds(MapSession.DEFAULT_MAX_INACTIVE_INTERVAL_SECONDS));
|
||||||
assertThat(session.getAttributeNames()).isEqualTo(Collections.singleton("attribute1"));
|
assertThat(session.getAttributeNames()).isEqualTo(Collections.singleton("attribute1"));
|
||||||
assertThat(session.<String>getAttribute("attribute1")).isEqualTo("value1");
|
assertThat(session.<String>getAttribute("attribute1")).isEqualTo("value1");
|
||||||
}
|
}
|
||||||
@@ -69,7 +69,7 @@ class RedisSessionRepositoryITests extends AbstractRedisITests {
|
|||||||
RedisSession session = createAndSaveSession(Instant.now());
|
RedisSession session = createAndSaveSession(Instant.now());
|
||||||
this.sessionRepository.deleteById(session.getId());
|
this.sessionRepository.deleteById(session.getId());
|
||||||
assertThatIllegalStateException().isThrownBy(() -> this.sessionRepository.save(session))
|
assertThatIllegalStateException().isThrownBy(() -> this.sessionRepository.save(session))
|
||||||
.withMessage("Session was invalidated");
|
.withMessage("Session was invalidated");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -160,7 +160,7 @@ class RedisSessionRepositoryITests extends AbstractRedisITests {
|
|||||||
updateSession(session, Instant.now(), "attribute1", "value1");
|
updateSession(session, Instant.now(), "attribute1", "value1");
|
||||||
String newSessionId = session.changeSessionId();
|
String newSessionId = session.changeSessionId();
|
||||||
assertThatIllegalStateException().isThrownBy(() -> this.sessionRepository.save(session))
|
assertThatIllegalStateException().isThrownBy(() -> this.sessionRepository.save(session))
|
||||||
.withMessage("Session was invalidated");
|
.withMessage("Session was invalidated");
|
||||||
assertThat(this.sessionRepository.findById(newSessionId)).isNull();
|
assertThat(this.sessionRepository.findById(newSessionId)).isNull();
|
||||||
assertThat(this.sessionRepository.findById(originalSessionId)).isNull();
|
assertThat(this.sessionRepository.findById(originalSessionId)).isNull();
|
||||||
}
|
}
|
||||||
@@ -177,7 +177,7 @@ class RedisSessionRepositoryITests extends AbstractRedisITests {
|
|||||||
updateSession(copy2, now.plusSeconds(2L), "attribute3", "value3");
|
updateSession(copy2, now.plusSeconds(2L), "attribute3", "value3");
|
||||||
String newSessionId2 = copy2.changeSessionId();
|
String newSessionId2 = copy2.changeSessionId();
|
||||||
assertThatIllegalStateException().isThrownBy(() -> this.sessionRepository.save(copy2))
|
assertThatIllegalStateException().isThrownBy(() -> this.sessionRepository.save(copy2))
|
||||||
.withMessage("Session was invalidated");
|
.withMessage("Session was invalidated");
|
||||||
assertThat(this.sessionRepository.findById(newSessionId1)).isNotNull();
|
assertThat(this.sessionRepository.findById(newSessionId1)).isNotNull();
|
||||||
assertThat(this.sessionRepository.findById(newSessionId2)).isNull();
|
assertThat(this.sessionRepository.findById(newSessionId2)).isNull();
|
||||||
assertThat(this.sessionRepository.findById(originalSessionId)).isNull();
|
assertThat(this.sessionRepository.findById(originalSessionId)).isNull();
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ class RedisListenerContainerTaskExecutorITests extends AbstractRedisITests {
|
|||||||
@Test
|
@Test
|
||||||
void testRedisDelEventsAreDispatchedInSessionTaskExecutor() throws InterruptedException {
|
void testRedisDelEventsAreDispatchedInSessionTaskExecutor() throws InterruptedException {
|
||||||
BoundSetOperations<Object, Object> ops = this.redis
|
BoundSetOperations<Object, Object> ops = this.redis
|
||||||
.boundSetOps("spring:session:RedisListenerContainerTaskExecutorITests:expirations:dummy");
|
.boundSetOps("spring:session:RedisListenerContainerTaskExecutorITests:expirations:dummy");
|
||||||
ops.add("value");
|
ops.add("value");
|
||||||
ops.remove("value");
|
ops.remove("value");
|
||||||
assertThat(this.executor.taskDispatched()).isTrue();
|
assertThat(this.executor.taskDispatched()).isTrue();
|
||||||
|
|||||||
@@ -133,8 +133,9 @@ public class ReactiveRedisSessionRepository
|
|||||||
return session.save();
|
return session.save();
|
||||||
}
|
}
|
||||||
String sessionKey = getSessionKey(session.hasChangedSessionId() ? session.originalSessionId : session.getId());
|
String sessionKey = getSessionKey(session.hasChangedSessionId() ? session.originalSessionId : session.getId());
|
||||||
return this.sessionRedisOperations.hasKey(sessionKey).flatMap(
|
return this.sessionRedisOperations.hasKey(sessionKey)
|
||||||
(exists) -> exists ? session.save() : Mono.error(new IllegalStateException("Session was invalidated")));
|
.flatMap((exists) -> exists ? session.save()
|
||||||
|
: Mono.error(new IllegalStateException("Session was invalidated")));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -283,7 +284,7 @@ public class ReactiveRedisSessionRepository
|
|||||||
|
|
||||||
String sessionKey = getSessionKey(getId());
|
String sessionKey = getSessionKey(getId());
|
||||||
Mono<Boolean> update = ReactiveRedisSessionRepository.this.sessionRedisOperations.opsForHash()
|
Mono<Boolean> update = ReactiveRedisSessionRepository.this.sessionRedisOperations.opsForHash()
|
||||||
.putAll(sessionKey, new HashMap<>(this.delta));
|
.putAll(sessionKey, new HashMap<>(this.delta));
|
||||||
Mono<Boolean> setTtl;
|
Mono<Boolean> setTtl;
|
||||||
if (getMaxInactiveInterval().getSeconds() >= 0) {
|
if (getMaxInactiveInterval().getSeconds() >= 0) {
|
||||||
setTtl = ReactiveRedisSessionRepository.this.sessionRedisOperations.expire(sessionKey,
|
setTtl = ReactiveRedisSessionRepository.this.sessionRedisOperations.expire(sessionKey,
|
||||||
@@ -320,10 +321,11 @@ public class ReactiveRedisSessionRepository
|
|||||||
String sessionKey = getSessionKey(sessionId);
|
String sessionKey = getSessionKey(sessionId);
|
||||||
|
|
||||||
return ReactiveRedisSessionRepository.this.sessionRedisOperations.rename(originalSessionKey, sessionKey)
|
return ReactiveRedisSessionRepository.this.sessionRedisOperations.rename(originalSessionKey, sessionKey)
|
||||||
.flatMap((unused) -> Mono.fromDirect(replaceSessionId)).onErrorResume((ex) -> {
|
.flatMap((unused) -> Mono.fromDirect(replaceSessionId))
|
||||||
String message = NestedExceptionUtils.getMostSpecificCause(ex).getMessage();
|
.onErrorResume((ex) -> {
|
||||||
return StringUtils.startsWithIgnoreCase(message, "ERR no such key");
|
String message = NestedExceptionUtils.getMostSpecificCause(ex).getMessage();
|
||||||
}, (ex) -> Mono.empty());
|
return StringUtils.startsWithIgnoreCase(message, "ERR no such key");
|
||||||
|
}, (ex) -> Mono.empty());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -857,7 +857,7 @@ public class RedisIndexedSessionRepository
|
|||||||
if (this.originalPrincipalName != null) {
|
if (this.originalPrincipalName != null) {
|
||||||
String originalPrincipalRedisKey = getPrincipalKey(this.originalPrincipalName);
|
String originalPrincipalRedisKey = getPrincipalKey(this.originalPrincipalName);
|
||||||
RedisIndexedSessionRepository.this.sessionRedisOperations.boundSetOps(originalPrincipalRedisKey)
|
RedisIndexedSessionRepository.this.sessionRedisOperations.boundSetOps(originalPrincipalRedisKey)
|
||||||
.remove(sessionId);
|
.remove(sessionId);
|
||||||
}
|
}
|
||||||
Map<String, String> indexes = RedisIndexedSessionRepository.this.indexResolver.resolveIndexesFor(this);
|
Map<String, String> indexes = RedisIndexedSessionRepository.this.indexResolver.resolveIndexesFor(this);
|
||||||
String principal = indexes.get(PRINCIPAL_NAME_INDEX_NAME);
|
String principal = indexes.get(PRINCIPAL_NAME_INDEX_NAME);
|
||||||
@@ -865,7 +865,7 @@ public class RedisIndexedSessionRepository
|
|||||||
if (principal != null) {
|
if (principal != null) {
|
||||||
String principalRedisKey = getPrincipalKey(principal);
|
String principalRedisKey = getPrincipalKey(principal);
|
||||||
RedisIndexedSessionRepository.this.sessionRedisOperations.boundSetOps(principalRedisKey)
|
RedisIndexedSessionRepository.this.sessionRedisOperations.boundSetOps(principalRedisKey)
|
||||||
.add(sessionId);
|
.add(sessionId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (this.isNew) {
|
if (this.isNew) {
|
||||||
@@ -905,9 +905,9 @@ public class RedisIndexedSessionRepository
|
|||||||
if (this.originalPrincipalName != null) {
|
if (this.originalPrincipalName != null) {
|
||||||
String originalPrincipalRedisKey = getPrincipalKey(this.originalPrincipalName);
|
String originalPrincipalRedisKey = getPrincipalKey(this.originalPrincipalName);
|
||||||
RedisIndexedSessionRepository.this.sessionRedisOperations.boundSetOps(originalPrincipalRedisKey)
|
RedisIndexedSessionRepository.this.sessionRedisOperations.boundSetOps(originalPrincipalRedisKey)
|
||||||
.remove(this.originalSessionId);
|
.remove(this.originalSessionId);
|
||||||
RedisIndexedSessionRepository.this.sessionRedisOperations.boundSetOps(originalPrincipalRedisKey)
|
RedisIndexedSessionRepository.this.sessionRedisOperations.boundSetOps(originalPrincipalRedisKey)
|
||||||
.add(sessionId);
|
.add(sessionId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.originalSessionId = sessionId;
|
this.originalSessionId = sessionId;
|
||||||
|
|||||||
@@ -298,7 +298,7 @@ public class RedisSessionRepository implements SessionRepository<RedisSessionRep
|
|||||||
RedisSessionRepository.this.sessionRedisOperations.opsForHash().putAll(key, new HashMap<>(this.delta));
|
RedisSessionRepository.this.sessionRedisOperations.opsForHash().putAll(key, new HashMap<>(this.delta));
|
||||||
RedisSessionRepository.this.sessionRedisOperations.expireAt(key,
|
RedisSessionRepository.this.sessionRedisOperations.expireAt(key,
|
||||||
Instant.ofEpochMilli(getLastAccessedTime().toEpochMilli())
|
Instant.ofEpochMilli(getLastAccessedTime().toEpochMilli())
|
||||||
.plusSeconds(getMaxInactiveInterval().getSeconds()));
|
.plusSeconds(getMaxInactiveInterval().getSeconds()));
|
||||||
this.delta.clear();
|
this.delta.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -119,7 +119,7 @@ public abstract class AbstractRedisHttpSessionConfiguration<T extends SessionRep
|
|||||||
@SpringSessionRedisConnectionFactory ObjectProvider<RedisConnectionFactory> springSessionRedisConnectionFactory,
|
@SpringSessionRedisConnectionFactory ObjectProvider<RedisConnectionFactory> springSessionRedisConnectionFactory,
|
||||||
ObjectProvider<RedisConnectionFactory> redisConnectionFactory) {
|
ObjectProvider<RedisConnectionFactory> redisConnectionFactory) {
|
||||||
this.redisConnectionFactory = springSessionRedisConnectionFactory
|
this.redisConnectionFactory = springSessionRedisConnectionFactory
|
||||||
.getIfAvailable(redisConnectionFactory::getObject);
|
.getIfAvailable(redisConnectionFactory::getObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected RedisConnectionFactory getRedisConnectionFactory() {
|
protected RedisConnectionFactory getRedisConnectionFactory() {
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ public class RedisHttpSessionConfiguration extends AbstractRedisHttpSessionConfi
|
|||||||
sessionRepository.setFlushMode(getFlushMode());
|
sessionRepository.setFlushMode(getFlushMode());
|
||||||
sessionRepository.setSaveMode(getSaveMode());
|
sessionRepository.setSaveMode(getSaveMode());
|
||||||
getSessionRepositoryCustomizers()
|
getSessionRepositoryCustomizers()
|
||||||
.forEach((sessionRepositoryCustomizer) -> sessionRepositoryCustomizer.customize(sessionRepository));
|
.forEach((sessionRepositoryCustomizer) -> sessionRepositoryCustomizer.customize(sessionRepository));
|
||||||
return sessionRepository;
|
return sessionRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,7 +73,7 @@ public class RedisHttpSessionConfiguration extends AbstractRedisHttpSessionConfi
|
|||||||
@Override
|
@Override
|
||||||
public void setImportMetadata(AnnotationMetadata importMetadata) {
|
public void setImportMetadata(AnnotationMetadata importMetadata) {
|
||||||
Map<String, Object> attributeMap = importMetadata
|
Map<String, Object> attributeMap = importMetadata
|
||||||
.getAnnotationAttributes(EnableRedisHttpSession.class.getName());
|
.getAnnotationAttributes(EnableRedisHttpSession.class.getName());
|
||||||
AnnotationAttributes attributes = AnnotationAttributes.fromMap(attributeMap);
|
AnnotationAttributes attributes = AnnotationAttributes.fromMap(attributeMap);
|
||||||
if (attributes == null) {
|
if (attributes == null) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ public class RedisIndexedHttpSessionConfiguration
|
|||||||
int database = resolveDatabase();
|
int database = resolveDatabase();
|
||||||
sessionRepository.setDatabase(database);
|
sessionRepository.setDatabase(database);
|
||||||
getSessionRepositoryCustomizers()
|
getSessionRepositoryCustomizers()
|
||||||
.forEach((sessionRepositoryCustomizer) -> sessionRepositoryCustomizer.customize(sessionRepository));
|
.forEach((sessionRepositoryCustomizer) -> sessionRepositoryCustomizer.customize(sessionRepository));
|
||||||
return sessionRepository;
|
return sessionRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -174,7 +174,7 @@ public class RedisIndexedHttpSessionConfiguration
|
|||||||
@Override
|
@Override
|
||||||
public void setImportMetadata(AnnotationMetadata importMetadata) {
|
public void setImportMetadata(AnnotationMetadata importMetadata) {
|
||||||
Map<String, Object> attributeMap = importMetadata
|
Map<String, Object> attributeMap = importMetadata
|
||||||
.getAnnotationAttributes(EnableRedisIndexedHttpSession.class.getName());
|
.getAnnotationAttributes(EnableRedisIndexedHttpSession.class.getName());
|
||||||
AnnotationAttributes attributes = AnnotationAttributes.fromMap(attributeMap);
|
AnnotationAttributes attributes = AnnotationAttributes.fromMap(attributeMap);
|
||||||
if (attributes == null) {
|
if (attributes == null) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ public class RedisWebSessionConfiguration implements BeanClassLoaderAware, Embed
|
|||||||
}
|
}
|
||||||
sessionRepository.setSaveMode(this.saveMode);
|
sessionRepository.setSaveMode(this.saveMode);
|
||||||
this.sessionRepositoryCustomizers
|
this.sessionRepositoryCustomizers
|
||||||
.forEach((sessionRepositoryCustomizer) -> sessionRepositoryCustomizer.customize(sessionRepository));
|
.forEach((sessionRepositoryCustomizer) -> sessionRepositoryCustomizer.customize(sessionRepository));
|
||||||
return sessionRepository;
|
return sessionRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -113,7 +113,7 @@ public class RedisWebSessionConfiguration implements BeanClassLoaderAware, Embed
|
|||||||
@SpringSessionRedisConnectionFactory ObjectProvider<ReactiveRedisConnectionFactory> springSessionRedisConnectionFactory,
|
@SpringSessionRedisConnectionFactory ObjectProvider<ReactiveRedisConnectionFactory> springSessionRedisConnectionFactory,
|
||||||
ObjectProvider<ReactiveRedisConnectionFactory> redisConnectionFactory) {
|
ObjectProvider<ReactiveRedisConnectionFactory> redisConnectionFactory) {
|
||||||
ReactiveRedisConnectionFactory redisConnectionFactoryToUse = springSessionRedisConnectionFactory
|
ReactiveRedisConnectionFactory redisConnectionFactoryToUse = springSessionRedisConnectionFactory
|
||||||
.getIfAvailable();
|
.getIfAvailable();
|
||||||
if (redisConnectionFactoryToUse == null) {
|
if (redisConnectionFactoryToUse == null) {
|
||||||
redisConnectionFactoryToUse = redisConnectionFactory.getObject();
|
redisConnectionFactoryToUse = redisConnectionFactory.getObject();
|
||||||
}
|
}
|
||||||
@@ -145,7 +145,7 @@ public class RedisWebSessionConfiguration implements BeanClassLoaderAware, Embed
|
|||||||
@Override
|
@Override
|
||||||
public void setImportMetadata(AnnotationMetadata importMetadata) {
|
public void setImportMetadata(AnnotationMetadata importMetadata) {
|
||||||
Map<String, Object> attributeMap = importMetadata
|
Map<String, Object> attributeMap = importMetadata
|
||||||
.getAnnotationAttributes(EnableRedisWebSession.class.getName());
|
.getAnnotationAttributes(EnableRedisWebSession.class.getName());
|
||||||
AnnotationAttributes attributes = AnnotationAttributes.fromMap(attributeMap);
|
AnnotationAttributes attributes = AnnotationAttributes.fromMap(attributeMap);
|
||||||
if (attributes == null) {
|
if (attributes == null) {
|
||||||
return;
|
return;
|
||||||
@@ -163,8 +163,10 @@ public class RedisWebSessionConfiguration implements BeanClassLoaderAware, Embed
|
|||||||
RedisSerializer<Object> defaultSerializer = (this.defaultRedisSerializer != null) ? this.defaultRedisSerializer
|
RedisSerializer<Object> defaultSerializer = (this.defaultRedisSerializer != null) ? this.defaultRedisSerializer
|
||||||
: new JdkSerializationRedisSerializer(this.classLoader);
|
: new JdkSerializationRedisSerializer(this.classLoader);
|
||||||
RedisSerializationContext<String, Object> serializationContext = RedisSerializationContext
|
RedisSerializationContext<String, Object> serializationContext = RedisSerializationContext
|
||||||
.<String, Object>newSerializationContext(defaultSerializer).key(keySerializer).hashKey(keySerializer)
|
.<String, Object>newSerializationContext(defaultSerializer)
|
||||||
.build();
|
.key(keySerializer)
|
||||||
|
.hashKey(keySerializer)
|
||||||
|
.build();
|
||||||
return new ReactiveRedisTemplate<>(this.redisConnectionFactory, serializationContext);
|
return new ReactiveRedisTemplate<>(this.redisConnectionFactory, serializationContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ class ReactiveRedisSessionRepositoryTests {
|
|||||||
@Test
|
@Test
|
||||||
void constructorWithNullReactiveRedisOperations() {
|
void constructorWithNullReactiveRedisOperations() {
|
||||||
assertThatIllegalArgumentException().isThrownBy(() -> new ReactiveRedisSessionRepository(null))
|
assertThatIllegalArgumentException().isThrownBy(() -> new ReactiveRedisSessionRepository(null))
|
||||||
.withMessageContaining("sessionRedisOperations cannot be null");
|
.withMessageContaining("sessionRedisOperations cannot be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -92,13 +92,13 @@ class ReactiveRedisSessionRepositoryTests {
|
|||||||
@Test
|
@Test
|
||||||
void nullRedisKeyNamespace() {
|
void nullRedisKeyNamespace() {
|
||||||
assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setRedisKeyNamespace(null))
|
assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setRedisKeyNamespace(null))
|
||||||
.withMessage("namespace cannot be null or empty");
|
.withMessage("namespace cannot be null or empty");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void emptyRedisKeyNamespace() {
|
void emptyRedisKeyNamespace() {
|
||||||
assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setRedisKeyNamespace(""))
|
assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setRedisKeyNamespace(""))
|
||||||
.withMessage("namespace cannot be null or empty");
|
.withMessage("namespace cannot be null or empty");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -112,9 +112,9 @@ class ReactiveRedisSessionRepositoryTests {
|
|||||||
@Test
|
@Test
|
||||||
void createSessionDefaultMaxInactiveInterval() {
|
void createSessionDefaultMaxInactiveInterval() {
|
||||||
StepVerifier.create(this.repository.createSession())
|
StepVerifier.create(this.repository.createSession())
|
||||||
.consumeNextWith((session) -> assertThat(session.getMaxInactiveInterval())
|
.consumeNextWith((session) -> assertThat(session.getMaxInactiveInterval())
|
||||||
.isEqualTo(Duration.ofSeconds(MapSession.DEFAULT_MAX_INACTIVE_INTERVAL_SECONDS)))
|
.isEqualTo(Duration.ofSeconds(MapSession.DEFAULT_MAX_INACTIVE_INTERVAL_SECONDS)))
|
||||||
.verifyComplete();
|
.verifyComplete();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -123,8 +123,8 @@ class ReactiveRedisSessionRepositoryTests {
|
|||||||
this.repository.setDefaultMaxInactiveInterval(interval);
|
this.repository.setDefaultMaxInactiveInterval(interval);
|
||||||
|
|
||||||
StepVerifier.create(this.repository.createSession())
|
StepVerifier.create(this.repository.createSession())
|
||||||
.consumeNextWith((session) -> assertThat(session.getMaxInactiveInterval()).isEqualTo(interval))
|
.consumeNextWith((session) -> assertThat(session.getMaxInactiveInterval()).isEqualTo(interval))
|
||||||
.verifyComplete();
|
.verifyComplete();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -145,11 +145,11 @@ class ReactiveRedisSessionRepositoryTests {
|
|||||||
Map<String, Object> delta = this.delta.getAllValues().get(0);
|
Map<String, Object> delta = this.delta.getAllValues().get(0);
|
||||||
assertThat(delta.size()).isEqualTo(3);
|
assertThat(delta.size()).isEqualTo(3);
|
||||||
assertThat(delta.get(RedisSessionMapper.CREATION_TIME_KEY))
|
assertThat(delta.get(RedisSessionMapper.CREATION_TIME_KEY))
|
||||||
.isEqualTo(newSession.getCreationTime().toEpochMilli());
|
.isEqualTo(newSession.getCreationTime().toEpochMilli());
|
||||||
assertThat(delta.get(RedisSessionMapper.MAX_INACTIVE_INTERVAL_KEY))
|
assertThat(delta.get(RedisSessionMapper.MAX_INACTIVE_INTERVAL_KEY))
|
||||||
.isEqualTo((int) newSession.getMaxInactiveInterval().getSeconds());
|
.isEqualTo((int) newSession.getMaxInactiveInterval().getSeconds());
|
||||||
assertThat(delta.get(RedisSessionMapper.LAST_ACCESSED_TIME_KEY))
|
assertThat(delta.get(RedisSessionMapper.LAST_ACCESSED_TIME_KEY))
|
||||||
.isEqualTo(newSession.getLastAccessedTime().toEpochMilli());
|
.isEqualTo(newSession.getLastAccessedTime().toEpochMilli());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -172,11 +172,11 @@ class ReactiveRedisSessionRepositoryTests {
|
|||||||
Map<String, Object> delta = this.delta.getAllValues().get(0);
|
Map<String, Object> delta = this.delta.getAllValues().get(0);
|
||||||
assertThat(delta.size()).isEqualTo(3);
|
assertThat(delta.size()).isEqualTo(3);
|
||||||
assertThat(delta.get(RedisSessionMapper.CREATION_TIME_KEY))
|
assertThat(delta.get(RedisSessionMapper.CREATION_TIME_KEY))
|
||||||
.isEqualTo(newSession.getCreationTime().toEpochMilli());
|
.isEqualTo(newSession.getCreationTime().toEpochMilli());
|
||||||
assertThat(delta.get(RedisSessionMapper.MAX_INACTIVE_INTERVAL_KEY))
|
assertThat(delta.get(RedisSessionMapper.MAX_INACTIVE_INTERVAL_KEY))
|
||||||
.isEqualTo((int) newSession.getMaxInactiveInterval().getSeconds());
|
.isEqualTo((int) newSession.getMaxInactiveInterval().getSeconds());
|
||||||
assertThat(delta.get(RedisSessionMapper.LAST_ACCESSED_TIME_KEY))
|
assertThat(delta.get(RedisSessionMapper.LAST_ACCESSED_TIME_KEY))
|
||||||
.isEqualTo(newSession.getLastAccessedTime().toEpochMilli());
|
.isEqualTo(newSession.getLastAccessedTime().toEpochMilli());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -211,8 +211,8 @@ class ReactiveRedisSessionRepositoryTests {
|
|||||||
verifyNoMoreInteractions(this.redisOperations);
|
verifyNoMoreInteractions(this.redisOperations);
|
||||||
verifyNoMoreInteractions(this.hashOperations);
|
verifyNoMoreInteractions(this.hashOperations);
|
||||||
|
|
||||||
assertThat(this.delta.getAllValues().get(0)).isEqualTo(
|
assertThat(this.delta.getAllValues().get(0))
|
||||||
map(RedisSessionMapper.LAST_ACCESSED_TIME_KEY, session.getLastAccessedTime().toEpochMilli()));
|
.isEqualTo(map(RedisSessionMapper.LAST_ACCESSED_TIME_KEY, session.getLastAccessedTime().toEpochMilli()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -258,7 +258,7 @@ class ReactiveRedisSessionRepositoryTests {
|
|||||||
verifyNoMoreInteractions(this.hashOperations);
|
verifyNoMoreInteractions(this.hashOperations);
|
||||||
|
|
||||||
assertThat(this.delta.getAllValues().get(0))
|
assertThat(this.delta.getAllValues().get(0))
|
||||||
.isEqualTo(map(RedisIndexedSessionRepository.getSessionAttrNameKey(attrName), null));
|
.isEqualTo(map(RedisIndexedSessionRepository.getSessionAttrNameKey(attrName), null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -328,10 +328,10 @@ class ReactiveRedisSessionRepositoryTests {
|
|||||||
assertThat(session.<String>getAttribute(attribute1)).isEqualTo(expected.getAttribute(attribute1));
|
assertThat(session.<String>getAttribute(attribute1)).isEqualTo(expected.getAttribute(attribute1));
|
||||||
assertThat(session.<String>getAttribute(attribute2)).isEqualTo(expected.getAttribute(attribute2));
|
assertThat(session.<String>getAttribute(attribute2)).isEqualTo(expected.getAttribute(attribute2));
|
||||||
assertThat(session.getCreationTime().truncatedTo(ChronoUnit.MILLIS))
|
assertThat(session.getCreationTime().truncatedTo(ChronoUnit.MILLIS))
|
||||||
.isEqualTo(expected.getCreationTime().truncatedTo(ChronoUnit.MILLIS));
|
.isEqualTo(expected.getCreationTime().truncatedTo(ChronoUnit.MILLIS));
|
||||||
assertThat(session.getMaxInactiveInterval()).isEqualTo(expected.getMaxInactiveInterval());
|
assertThat(session.getMaxInactiveInterval()).isEqualTo(expected.getMaxInactiveInterval());
|
||||||
assertThat(session.getLastAccessedTime().truncatedTo(ChronoUnit.MILLIS))
|
assertThat(session.getLastAccessedTime().truncatedTo(ChronoUnit.MILLIS))
|
||||||
.isEqualTo(expected.getLastAccessedTime().truncatedTo(ChronoUnit.MILLIS));
|
.isEqualTo(expected.getLastAccessedTime().truncatedTo(ChronoUnit.MILLIS));
|
||||||
}).verifyComplete();
|
}).verifyComplete();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ class RedisIndexedSessionRepositoryTests {
|
|||||||
@Test
|
@Test
|
||||||
void setApplicationEventPublisherNull() {
|
void setApplicationEventPublisherNull() {
|
||||||
assertThatIllegalArgumentException().isThrownBy(() -> this.redisRepository.setApplicationEventPublisher(null))
|
assertThatIllegalArgumentException().isThrownBy(() -> this.redisRepository.setApplicationEventPublisher(null))
|
||||||
.withMessage("applicationEventPublisher cannot be null");
|
.withMessage("applicationEventPublisher cannot be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -178,9 +178,9 @@ class RedisIndexedSessionRepositoryTests {
|
|||||||
Object creationTime = delta.get(RedisSessionMapper.CREATION_TIME_KEY);
|
Object creationTime = delta.get(RedisSessionMapper.CREATION_TIME_KEY);
|
||||||
assertThat(creationTime).isEqualTo(session.getCreationTime().toEpochMilli());
|
assertThat(creationTime).isEqualTo(session.getCreationTime().toEpochMilli());
|
||||||
assertThat(delta.get(RedisSessionMapper.MAX_INACTIVE_INTERVAL_KEY))
|
assertThat(delta.get(RedisSessionMapper.MAX_INACTIVE_INTERVAL_KEY))
|
||||||
.isEqualTo((int) Duration.ofSeconds(MapSession.DEFAULT_MAX_INACTIVE_INTERVAL_SECONDS).getSeconds());
|
.isEqualTo((int) Duration.ofSeconds(MapSession.DEFAULT_MAX_INACTIVE_INTERVAL_SECONDS).getSeconds());
|
||||||
assertThat(delta.get(RedisSessionMapper.LAST_ACCESSED_TIME_KEY))
|
assertThat(delta.get(RedisSessionMapper.LAST_ACCESSED_TIME_KEY))
|
||||||
.isEqualTo(session.getCreationTime().toEpochMilli());
|
.isEqualTo(session.getCreationTime().toEpochMilli());
|
||||||
}
|
}
|
||||||
|
|
||||||
// gh-467
|
// gh-467
|
||||||
@@ -199,7 +199,7 @@ class RedisIndexedSessionRepositoryTests {
|
|||||||
|
|
||||||
String sessionKey = "spring:session:sessions:" + session.getId();
|
String sessionKey = "spring:session:sessions:" + session.getId();
|
||||||
String backgroundExpireKey = "spring:session:expirations:" + RedisSessionExpirationPolicy
|
String backgroundExpireKey = "spring:session:expirations:" + RedisSessionExpirationPolicy
|
||||||
.roundUpToNextMinute(RedisSessionExpirationPolicy.expiresInMillis(session));
|
.roundUpToNextMinute(RedisSessionExpirationPolicy.expiresInMillis(session));
|
||||||
String destroyedTriggerKey = "spring:session:sessions:expires:" + session.getId();
|
String destroyedTriggerKey = "spring:session:sessions:expires:" + session.getId();
|
||||||
|
|
||||||
given(this.redisOperations.<String, Object>boundHashOps(sessionKey)).willReturn(this.boundHashOperations);
|
given(this.redisOperations.<String, Object>boundHashOps(sessionKey)).willReturn(this.boundHashOperations);
|
||||||
@@ -226,11 +226,11 @@ class RedisIndexedSessionRepositoryTests {
|
|||||||
session.setLastAccessedTime(session.getLastAccessedTime());
|
session.setLastAccessedTime(session.getLastAccessedTime());
|
||||||
|
|
||||||
given(this.redisOperations.<String, Object>boundHashOps("spring:session:sessions:session-id"))
|
given(this.redisOperations.<String, Object>boundHashOps("spring:session:sessions:session-id"))
|
||||||
.willReturn(this.boundHashOperations);
|
.willReturn(this.boundHashOperations);
|
||||||
given(this.redisOperations.boundSetOps("spring:session:expirations:1404361860000"))
|
given(this.redisOperations.boundSetOps("spring:session:expirations:1404361860000"))
|
||||||
.willReturn(this.boundSetOperations);
|
.willReturn(this.boundSetOperations);
|
||||||
given(this.redisOperations.boundValueOps("spring:session:sessions:expires:session-id"))
|
given(this.redisOperations.boundValueOps("spring:session:sessions:expires:session-id"))
|
||||||
.willReturn(this.boundValueOperations);
|
.willReturn(this.boundValueOperations);
|
||||||
|
|
||||||
this.redisRepository.save(session);
|
this.redisRepository.save(session);
|
||||||
|
|
||||||
@@ -252,8 +252,8 @@ class RedisIndexedSessionRepositoryTests {
|
|||||||
|
|
||||||
this.redisRepository.save(session);
|
this.redisRepository.save(session);
|
||||||
|
|
||||||
assertThat(getDelta()).isEqualTo(
|
assertThat(getDelta())
|
||||||
map(RedisSessionMapper.LAST_ACCESSED_TIME_KEY, session.getLastAccessedTime().toEpochMilli()));
|
.isEqualTo(map(RedisSessionMapper.LAST_ACCESSED_TIME_KEY, session.getLastAccessedTime().toEpochMilli()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -362,7 +362,7 @@ class RedisIndexedSessionRepositoryTests {
|
|||||||
expected.setAttribute(attribute1, "test");
|
expected.setAttribute(attribute1, "test");
|
||||||
expected.setAttribute(attribute2, null);
|
expected.setAttribute(attribute2, null);
|
||||||
given(this.redisOperations.<String, Object>boundHashOps(getKey(expected.getId())))
|
given(this.redisOperations.<String, Object>boundHashOps(getKey(expected.getId())))
|
||||||
.willReturn(this.boundHashOperations);
|
.willReturn(this.boundHashOperations);
|
||||||
Map<String, Object> map = map(RedisIndexedSessionRepository.getSessionAttrNameKey(attribute1),
|
Map<String, Object> map = map(RedisIndexedSessionRepository.getSessionAttrNameKey(attribute1),
|
||||||
expected.getAttribute(attribute1), RedisIndexedSessionRepository.getSessionAttrNameKey(attribute2),
|
expected.getAttribute(attribute1), RedisIndexedSessionRepository.getSessionAttrNameKey(attribute2),
|
||||||
expected.getAttribute(attribute2), RedisSessionMapper.CREATION_TIME_KEY,
|
expected.getAttribute(attribute2), RedisSessionMapper.CREATION_TIME_KEY,
|
||||||
@@ -377,17 +377,17 @@ class RedisIndexedSessionRepositoryTests {
|
|||||||
assertThat(session.<String>getAttribute(attribute1)).isEqualTo(expected.getAttribute(attribute1));
|
assertThat(session.<String>getAttribute(attribute1)).isEqualTo(expected.getAttribute(attribute1));
|
||||||
assertThat(session.<String>getAttribute(attribute2)).isEqualTo(expected.getAttribute(attribute2));
|
assertThat(session.<String>getAttribute(attribute2)).isEqualTo(expected.getAttribute(attribute2));
|
||||||
assertThat(session.getCreationTime().truncatedTo(ChronoUnit.MILLIS))
|
assertThat(session.getCreationTime().truncatedTo(ChronoUnit.MILLIS))
|
||||||
.isEqualTo(expected.getCreationTime().truncatedTo(ChronoUnit.MILLIS));
|
.isEqualTo(expected.getCreationTime().truncatedTo(ChronoUnit.MILLIS));
|
||||||
assertThat(session.getMaxInactiveInterval()).isEqualTo(expected.getMaxInactiveInterval());
|
assertThat(session.getMaxInactiveInterval()).isEqualTo(expected.getMaxInactiveInterval());
|
||||||
assertThat(session.getLastAccessedTime().truncatedTo(ChronoUnit.MILLIS))
|
assertThat(session.getLastAccessedTime().truncatedTo(ChronoUnit.MILLIS))
|
||||||
.isEqualTo(expected.getLastAccessedTime().truncatedTo(ChronoUnit.MILLIS));
|
.isEqualTo(expected.getLastAccessedTime().truncatedTo(ChronoUnit.MILLIS));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void getSessionExpired() {
|
void getSessionExpired() {
|
||||||
String expiredId = "expired-id";
|
String expiredId = "expired-id";
|
||||||
given(this.redisOperations.<String, Object>boundHashOps(getKey(expiredId)))
|
given(this.redisOperations.<String, Object>boundHashOps(getKey(expiredId)))
|
||||||
.willReturn(this.boundHashOperations);
|
.willReturn(this.boundHashOperations);
|
||||||
Map<String, Object> map = map(RedisSessionMapper.CREATION_TIME_KEY, Instant.EPOCH.toEpochMilli(),
|
Map<String, Object> map = map(RedisSessionMapper.CREATION_TIME_KEY, Instant.EPOCH.toEpochMilli(),
|
||||||
RedisSessionMapper.MAX_INACTIVE_INTERVAL_KEY, 1, RedisSessionMapper.LAST_ACCESSED_TIME_KEY,
|
RedisSessionMapper.MAX_INACTIVE_INTERVAL_KEY, 1, RedisSessionMapper.LAST_ACCESSED_TIME_KEY,
|
||||||
Instant.now().minus(5, ChronoUnit.MINUTES).toEpochMilli());
|
Instant.now().minus(5, ChronoUnit.MINUTES).toEpochMilli());
|
||||||
@@ -402,15 +402,15 @@ class RedisIndexedSessionRepositoryTests {
|
|||||||
given(this.redisOperations.boundSetOps(anyString())).willReturn(this.boundSetOperations);
|
given(this.redisOperations.boundSetOps(anyString())).willReturn(this.boundSetOperations);
|
||||||
given(this.boundSetOperations.members()).willReturn(Collections.singleton(expiredId));
|
given(this.boundSetOperations.members()).willReturn(Collections.singleton(expiredId));
|
||||||
given(this.redisOperations.<String, Object>boundHashOps(getKey(expiredId)))
|
given(this.redisOperations.<String, Object>boundHashOps(getKey(expiredId)))
|
||||||
.willReturn(this.boundHashOperations);
|
.willReturn(this.boundHashOperations);
|
||||||
Map<String, Object> map = map(RedisSessionMapper.CREATION_TIME_KEY, Instant.EPOCH.toEpochMilli(),
|
Map<String, Object> map = map(RedisSessionMapper.CREATION_TIME_KEY, Instant.EPOCH.toEpochMilli(),
|
||||||
RedisSessionMapper.MAX_INACTIVE_INTERVAL_KEY, 1, RedisSessionMapper.LAST_ACCESSED_TIME_KEY,
|
RedisSessionMapper.MAX_INACTIVE_INTERVAL_KEY, 1, RedisSessionMapper.LAST_ACCESSED_TIME_KEY,
|
||||||
Instant.now().minus(5, ChronoUnit.MINUTES).toEpochMilli());
|
Instant.now().minus(5, ChronoUnit.MINUTES).toEpochMilli());
|
||||||
given(this.boundHashOperations.entries()).willReturn(map);
|
given(this.boundHashOperations.entries()).willReturn(map);
|
||||||
|
|
||||||
assertThat(this.redisRepository
|
assertThat(this.redisRepository
|
||||||
.findByIndexNameAndIndexValue(FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME, "principal"))
|
.findByIndexNameAndIndexValue(FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME, "principal"))
|
||||||
.isEmpty();
|
.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -422,24 +422,24 @@ class RedisIndexedSessionRepositoryTests {
|
|||||||
given(this.redisOperations.boundSetOps(anyString())).willReturn(this.boundSetOperations);
|
given(this.redisOperations.boundSetOps(anyString())).willReturn(this.boundSetOperations);
|
||||||
given(this.boundSetOperations.members()).willReturn(Collections.singleton(sessionId));
|
given(this.boundSetOperations.members()).willReturn(Collections.singleton(sessionId));
|
||||||
given(this.redisOperations.<String, Object>boundHashOps(getKey(sessionId)))
|
given(this.redisOperations.<String, Object>boundHashOps(getKey(sessionId)))
|
||||||
.willReturn(this.boundHashOperations);
|
.willReturn(this.boundHashOperations);
|
||||||
Map<String, Object> map = map(RedisSessionMapper.CREATION_TIME_KEY, createdTime.toEpochMilli(),
|
Map<String, Object> map = map(RedisSessionMapper.CREATION_TIME_KEY, createdTime.toEpochMilli(),
|
||||||
RedisSessionMapper.MAX_INACTIVE_INTERVAL_KEY, (int) maxInactive.getSeconds(),
|
RedisSessionMapper.MAX_INACTIVE_INTERVAL_KEY, (int) maxInactive.getSeconds(),
|
||||||
RedisSessionMapper.LAST_ACCESSED_TIME_KEY, lastAccessed.toEpochMilli());
|
RedisSessionMapper.LAST_ACCESSED_TIME_KEY, lastAccessed.toEpochMilli());
|
||||||
given(this.boundHashOperations.entries()).willReturn(map);
|
given(this.boundHashOperations.entries()).willReturn(map);
|
||||||
|
|
||||||
Map<String, RedisSession> sessionIdToSessions = this.redisRepository
|
Map<String, RedisSession> sessionIdToSessions = this.redisRepository
|
||||||
.findByIndexNameAndIndexValue(FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME, "principal");
|
.findByIndexNameAndIndexValue(FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME, "principal");
|
||||||
|
|
||||||
assertThat(sessionIdToSessions).hasSize(1);
|
assertThat(sessionIdToSessions).hasSize(1);
|
||||||
RedisSession session = sessionIdToSessions.get(sessionId);
|
RedisSession session = sessionIdToSessions.get(sessionId);
|
||||||
assertThat(session).isNotNull();
|
assertThat(session).isNotNull();
|
||||||
assertThat(session.getId()).isEqualTo(sessionId);
|
assertThat(session.getId()).isEqualTo(sessionId);
|
||||||
assertThat(session.getLastAccessedTime().truncatedTo(ChronoUnit.MILLIS))
|
assertThat(session.getLastAccessedTime().truncatedTo(ChronoUnit.MILLIS))
|
||||||
.isEqualTo(lastAccessed.truncatedTo(ChronoUnit.MILLIS));
|
.isEqualTo(lastAccessed.truncatedTo(ChronoUnit.MILLIS));
|
||||||
assertThat(session.getMaxInactiveInterval()).isEqualTo(maxInactive);
|
assertThat(session.getMaxInactiveInterval()).isEqualTo(maxInactive);
|
||||||
assertThat(session.getCreationTime().truncatedTo(ChronoUnit.MILLIS))
|
assertThat(session.getCreationTime().truncatedTo(ChronoUnit.MILLIS))
|
||||||
.isEqualTo(createdTime.truncatedTo(ChronoUnit.MILLIS));
|
.isEqualTo(createdTime.truncatedTo(ChronoUnit.MILLIS));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -503,7 +503,7 @@ class RedisIndexedSessionRepositoryTests {
|
|||||||
void onMessageDeletedSessionFound() {
|
void onMessageDeletedSessionFound() {
|
||||||
String deletedId = "deleted-id";
|
String deletedId = "deleted-id";
|
||||||
given(this.redisOperations.<String, Object>boundHashOps(getKey(deletedId)))
|
given(this.redisOperations.<String, Object>boundHashOps(getKey(deletedId)))
|
||||||
.willReturn(this.boundHashOperations);
|
.willReturn(this.boundHashOperations);
|
||||||
Map<String, Object> map = map(RedisSessionMapper.CREATION_TIME_KEY, Instant.EPOCH.toEpochMilli(),
|
Map<String, Object> map = map(RedisSessionMapper.CREATION_TIME_KEY, Instant.EPOCH.toEpochMilli(),
|
||||||
RedisSessionMapper.MAX_INACTIVE_INTERVAL_KEY, 0, RedisSessionMapper.LAST_ACCESSED_TIME_KEY,
|
RedisSessionMapper.MAX_INACTIVE_INTERVAL_KEY, 0, RedisSessionMapper.LAST_ACCESSED_TIME_KEY,
|
||||||
System.currentTimeMillis() - TimeUnit.MINUTES.toMillis(5));
|
System.currentTimeMillis() - TimeUnit.MINUTES.toMillis(5));
|
||||||
@@ -531,7 +531,7 @@ class RedisIndexedSessionRepositoryTests {
|
|||||||
void onMessageDeletedSessionNotFound() {
|
void onMessageDeletedSessionNotFound() {
|
||||||
String deletedId = "deleted-id";
|
String deletedId = "deleted-id";
|
||||||
given(this.redisOperations.<String, Object>boundHashOps(getKey(deletedId)))
|
given(this.redisOperations.<String, Object>boundHashOps(getKey(deletedId)))
|
||||||
.willReturn(this.boundHashOperations);
|
.willReturn(this.boundHashOperations);
|
||||||
given(this.boundHashOperations.entries()).willReturn(map());
|
given(this.boundHashOperations.entries()).willReturn(map());
|
||||||
|
|
||||||
String channel = "__keyevent@0__:del";
|
String channel = "__keyevent@0__:del";
|
||||||
@@ -554,7 +554,7 @@ class RedisIndexedSessionRepositoryTests {
|
|||||||
void onMessageExpiredSessionFound() {
|
void onMessageExpiredSessionFound() {
|
||||||
String expiredId = "expired-id";
|
String expiredId = "expired-id";
|
||||||
given(this.redisOperations.<String, Object>boundHashOps(getKey(expiredId)))
|
given(this.redisOperations.<String, Object>boundHashOps(getKey(expiredId)))
|
||||||
.willReturn(this.boundHashOperations);
|
.willReturn(this.boundHashOperations);
|
||||||
Map<String, Object> map = map(RedisSessionMapper.CREATION_TIME_KEY, Instant.EPOCH.toEpochMilli(),
|
Map<String, Object> map = map(RedisSessionMapper.CREATION_TIME_KEY, Instant.EPOCH.toEpochMilli(),
|
||||||
RedisSessionMapper.MAX_INACTIVE_INTERVAL_KEY, 1, RedisSessionMapper.LAST_ACCESSED_TIME_KEY,
|
RedisSessionMapper.MAX_INACTIVE_INTERVAL_KEY, 1, RedisSessionMapper.LAST_ACCESSED_TIME_KEY,
|
||||||
System.currentTimeMillis() - TimeUnit.MINUTES.toMillis(5));
|
System.currentTimeMillis() - TimeUnit.MINUTES.toMillis(5));
|
||||||
@@ -582,7 +582,7 @@ class RedisIndexedSessionRepositoryTests {
|
|||||||
void onMessageExpiredSessionNotFound() {
|
void onMessageExpiredSessionNotFound() {
|
||||||
String expiredId = "expired-id";
|
String expiredId = "expired-id";
|
||||||
given(this.redisOperations.<String, Object>boundHashOps(getKey(expiredId)))
|
given(this.redisOperations.<String, Object>boundHashOps(getKey(expiredId)))
|
||||||
.willReturn(this.boundHashOperations);
|
.willReturn(this.boundHashOperations);
|
||||||
given(this.boundHashOperations.entries()).willReturn(map());
|
given(this.boundHashOperations.entries()).willReturn(map());
|
||||||
|
|
||||||
String channel = "__keyevent@0__:expired";
|
String channel = "__keyevent@0__:expired";
|
||||||
@@ -654,9 +654,9 @@ class RedisIndexedSessionRepositoryTests {
|
|||||||
Object creationTime = delta.get(RedisSessionMapper.CREATION_TIME_KEY);
|
Object creationTime = delta.get(RedisSessionMapper.CREATION_TIME_KEY);
|
||||||
assertThat(creationTime).isEqualTo(session.getCreationTime().toEpochMilli());
|
assertThat(creationTime).isEqualTo(session.getCreationTime().toEpochMilli());
|
||||||
assertThat(delta.get(RedisSessionMapper.MAX_INACTIVE_INTERVAL_KEY))
|
assertThat(delta.get(RedisSessionMapper.MAX_INACTIVE_INTERVAL_KEY))
|
||||||
.isEqualTo((int) Duration.ofSeconds(MapSession.DEFAULT_MAX_INACTIVE_INTERVAL_SECONDS).getSeconds());
|
.isEqualTo((int) Duration.ofSeconds(MapSession.DEFAULT_MAX_INACTIVE_INTERVAL_SECONDS).getSeconds());
|
||||||
assertThat(delta.get(RedisSessionMapper.LAST_ACCESSED_TIME_KEY))
|
assertThat(delta.get(RedisSessionMapper.LAST_ACCESSED_TIME_KEY))
|
||||||
.isEqualTo(session.getCreationTime().toEpochMilli());
|
.isEqualTo(session.getCreationTime().toEpochMilli());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // gh-1409
|
@Test // gh-1409
|
||||||
@@ -736,26 +736,26 @@ class RedisIndexedSessionRepositoryTests {
|
|||||||
|
|
||||||
Map<String, Object> delta = getDelta(2);
|
Map<String, Object> delta = getDelta(2);
|
||||||
assertThat(delta.size()).isEqualTo(1);
|
assertThat(delta.size()).isEqualTo(1);
|
||||||
assertThat(delta).isEqualTo(
|
assertThat(delta)
|
||||||
map(RedisSessionMapper.LAST_ACCESSED_TIME_KEY, session.getLastAccessedTime().toEpochMilli()));
|
.isEqualTo(map(RedisSessionMapper.LAST_ACCESSED_TIME_KEY, session.getLastAccessedTime().toEpochMilli()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void setFlushModeNull() {
|
void setFlushModeNull() {
|
||||||
assertThatIllegalArgumentException().isThrownBy(() -> this.redisRepository.setFlushMode(null))
|
assertThatIllegalArgumentException().isThrownBy(() -> this.redisRepository.setFlushMode(null))
|
||||||
.withMessage("flushMode cannot be null");
|
.withMessage("flushMode cannot be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void setCleanupCronNull() {
|
void setCleanupCronNull() {
|
||||||
assertThatIllegalArgumentException().isThrownBy(() -> this.redisRepository.setCleanupCron(null))
|
assertThatIllegalArgumentException().isThrownBy(() -> this.redisRepository.setCleanupCron(null))
|
||||||
.withMessage("cleanupCron must not be null");
|
.withMessage("cleanupCron must not be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void setCleanupCronInvalid() {
|
void setCleanupCronInvalid() {
|
||||||
assertThatIllegalArgumentException().isThrownBy(() -> this.redisRepository.setCleanupCron("test"))
|
assertThatIllegalArgumentException().isThrownBy(() -> this.redisRepository.setCleanupCron("test"))
|
||||||
.withMessage("cleanupCron must be valid");
|
.withMessage("cleanupCron must be valid");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -784,13 +784,13 @@ class RedisIndexedSessionRepositoryTests {
|
|||||||
@Test
|
@Test
|
||||||
void setRedisKeyNamespaceNullNamespace() {
|
void setRedisKeyNamespaceNullNamespace() {
|
||||||
assertThatIllegalArgumentException().isThrownBy(() -> this.redisRepository.setRedisKeyNamespace(null))
|
assertThatIllegalArgumentException().isThrownBy(() -> this.redisRepository.setRedisKeyNamespace(null))
|
||||||
.withMessage("namespace cannot be null or empty");
|
.withMessage("namespace cannot be null or empty");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void setRedisKeyNamespaceEmptyNamespace() {
|
void setRedisKeyNamespaceEmptyNamespace() {
|
||||||
assertThatIllegalArgumentException().isThrownBy(() -> this.redisRepository.setRedisKeyNamespace(" "))
|
assertThatIllegalArgumentException().isThrownBy(() -> this.redisRepository.setRedisKeyNamespace(" "))
|
||||||
.withMessage("namespace cannot be null or empty");
|
.withMessage("namespace cannot be null or empty");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // gh-1120
|
@Test // gh-1120
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ class RedisSessionExpirationPolicyTests {
|
|||||||
void onExpirationUpdatedRemovesOriginalExpirationTimeRoundedUp() {
|
void onExpirationUpdatedRemovesOriginalExpirationTimeRoundedUp() {
|
||||||
long originalExpirationTimeInMs = ONE_MINUTE_AGO;
|
long originalExpirationTimeInMs = ONE_MINUTE_AGO;
|
||||||
long originalRoundedToNextMinInMs = RedisSessionExpirationPolicy
|
long originalRoundedToNextMinInMs = RedisSessionExpirationPolicy
|
||||||
.roundUpToNextMinute(originalExpirationTimeInMs);
|
.roundUpToNextMinute(originalExpirationTimeInMs);
|
||||||
String originalExpireKey = this.policy.getExpirationKey(originalRoundedToNextMinInMs);
|
String originalExpireKey = this.policy.getExpirationKey(originalRoundedToNextMinInMs);
|
||||||
|
|
||||||
this.policy.onExpirationUpdated(originalExpirationTimeInMs, this.session);
|
this.policy.onExpirationUpdated(originalExpirationTimeInMs, this.session);
|
||||||
@@ -98,7 +98,7 @@ class RedisSessionExpirationPolicyTests {
|
|||||||
void onExpirationUpdatedDoNotSendDeleteWhenExpirationTimeDoesNotChange() {
|
void onExpirationUpdatedDoNotSendDeleteWhenExpirationTimeDoesNotChange() {
|
||||||
long originalExpirationTimeInMs = RedisSessionExpirationPolicy.expiresInMillis(this.session) - 10;
|
long originalExpirationTimeInMs = RedisSessionExpirationPolicy.expiresInMillis(this.session) - 10;
|
||||||
long originalRoundedToNextMinInMs = RedisSessionExpirationPolicy
|
long originalRoundedToNextMinInMs = RedisSessionExpirationPolicy
|
||||||
.roundUpToNextMinute(originalExpirationTimeInMs);
|
.roundUpToNextMinute(originalExpirationTimeInMs);
|
||||||
String originalExpireKey = this.policy.getExpirationKey(originalRoundedToNextMinInMs);
|
String originalExpireKey = this.policy.getExpirationKey(originalRoundedToNextMinInMs);
|
||||||
|
|
||||||
this.policy.onExpirationUpdated(originalExpirationTimeInMs, this.session);
|
this.policy.onExpirationUpdated(originalExpirationTimeInMs, this.session);
|
||||||
|
|||||||
@@ -48,25 +48,25 @@ class RedisSessionMapperTests {
|
|||||||
@Test
|
@Test
|
||||||
void constructor_NullId_ShouldThrowException() {
|
void constructor_NullId_ShouldThrowException() {
|
||||||
assertThatIllegalArgumentException().isThrownBy(() -> new RedisSessionMapper(null))
|
assertThatIllegalArgumentException().isThrownBy(() -> new RedisSessionMapper(null))
|
||||||
.withMessage("sessionId must not be empty");
|
.withMessage("sessionId must not be empty");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void constructor_EmptyId_ShouldThrowException() {
|
void constructor_EmptyId_ShouldThrowException() {
|
||||||
assertThatIllegalArgumentException().isThrownBy(() -> new RedisSessionMapper(" "))
|
assertThatIllegalArgumentException().isThrownBy(() -> new RedisSessionMapper(" "))
|
||||||
.withMessage("sessionId must not be empty");
|
.withMessage("sessionId must not be empty");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void apply_NullMap_ShouldThrowException() {
|
void apply_NullMap_ShouldThrowException() {
|
||||||
assertThatIllegalArgumentException().isThrownBy(() -> this.mapper.apply(null))
|
assertThatIllegalArgumentException().isThrownBy(() -> this.mapper.apply(null))
|
||||||
.withMessage("map must not be empty");
|
.withMessage("map must not be empty");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void apply_EmptyMap_ShouldThrowException() {
|
void apply_EmptyMap_ShouldThrowException() {
|
||||||
assertThatIllegalArgumentException().isThrownBy(() -> this.mapper.apply(Collections.emptyMap()))
|
assertThatIllegalArgumentException().isThrownBy(() -> this.mapper.apply(Collections.emptyMap()))
|
||||||
.withMessage("map must not be empty");
|
.withMessage("map must not be empty");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -75,7 +75,7 @@ class RedisSessionMapperTests {
|
|||||||
sessionMap.put(RedisSessionMapper.LAST_ACCESSED_TIME_KEY, 0L);
|
sessionMap.put(RedisSessionMapper.LAST_ACCESSED_TIME_KEY, 0L);
|
||||||
sessionMap.put(RedisSessionMapper.MAX_INACTIVE_INTERVAL_KEY, 1800);
|
sessionMap.put(RedisSessionMapper.MAX_INACTIVE_INTERVAL_KEY, 1800);
|
||||||
assertThatIllegalStateException().isThrownBy(() -> this.mapper.apply(sessionMap))
|
assertThatIllegalStateException().isThrownBy(() -> this.mapper.apply(sessionMap))
|
||||||
.withMessage(RedisSessionMapper.CREATION_TIME_KEY + " key must not be null");
|
.withMessage(RedisSessionMapper.CREATION_TIME_KEY + " key must not be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -84,7 +84,7 @@ class RedisSessionMapperTests {
|
|||||||
sessionMap.put(RedisSessionMapper.CREATION_TIME_KEY, 0L);
|
sessionMap.put(RedisSessionMapper.CREATION_TIME_KEY, 0L);
|
||||||
sessionMap.put(RedisSessionMapper.MAX_INACTIVE_INTERVAL_KEY, 1800);
|
sessionMap.put(RedisSessionMapper.MAX_INACTIVE_INTERVAL_KEY, 1800);
|
||||||
assertThatIllegalStateException().isThrownBy(() -> this.mapper.apply(sessionMap))
|
assertThatIllegalStateException().isThrownBy(() -> this.mapper.apply(sessionMap))
|
||||||
.withMessage(RedisSessionMapper.LAST_ACCESSED_TIME_KEY + " key must not be null");
|
.withMessage(RedisSessionMapper.LAST_ACCESSED_TIME_KEY + " key must not be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -93,7 +93,7 @@ class RedisSessionMapperTests {
|
|||||||
sessionMap.put(RedisSessionMapper.CREATION_TIME_KEY, 0L);
|
sessionMap.put(RedisSessionMapper.CREATION_TIME_KEY, 0L);
|
||||||
sessionMap.put(RedisSessionMapper.LAST_ACCESSED_TIME_KEY, 0L);
|
sessionMap.put(RedisSessionMapper.LAST_ACCESSED_TIME_KEY, 0L);
|
||||||
assertThatIllegalStateException().isThrownBy(() -> this.mapper.apply(sessionMap))
|
assertThatIllegalStateException().isThrownBy(() -> this.mapper.apply(sessionMap))
|
||||||
.withMessage(RedisSessionMapper.MAX_INACTIVE_INTERVAL_KEY + " key must not be null");
|
.withMessage(RedisSessionMapper.MAX_INACTIVE_INTERVAL_KEY + " key must not be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -79,21 +79,21 @@ class RedisSessionRepositoryTests {
|
|||||||
@Test
|
@Test
|
||||||
void constructor_NullRedisOperations_ShouldThrowException() {
|
void constructor_NullRedisOperations_ShouldThrowException() {
|
||||||
assertThatIllegalArgumentException().isThrownBy(() -> new ReactiveRedisSessionRepository(null))
|
assertThatIllegalArgumentException().isThrownBy(() -> new ReactiveRedisSessionRepository(null))
|
||||||
.withMessageContaining("sessionRedisOperations cannot be null");
|
.withMessageContaining("sessionRedisOperations cannot be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void setDefaultMaxInactiveInterval_ValidInterval_ShouldSetInterval() {
|
void setDefaultMaxInactiveInterval_ValidInterval_ShouldSetInterval() {
|
||||||
this.sessionRepository.setDefaultMaxInactiveInterval(Duration.ofMinutes(10));
|
this.sessionRepository.setDefaultMaxInactiveInterval(Duration.ofMinutes(10));
|
||||||
assertThat(ReflectionTestUtils.getField(this.sessionRepository, "defaultMaxInactiveInterval"))
|
assertThat(ReflectionTestUtils.getField(this.sessionRepository, "defaultMaxInactiveInterval"))
|
||||||
.isEqualTo(Duration.ofMinutes(10));
|
.isEqualTo(Duration.ofMinutes(10));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void setDefaultMaxInactiveInterval_NullInterval_ShouldThrowException() {
|
void setDefaultMaxInactiveInterval_NullInterval_ShouldThrowException() {
|
||||||
assertThatIllegalArgumentException()
|
assertThatIllegalArgumentException()
|
||||||
.isThrownBy(() -> this.sessionRepository.setDefaultMaxInactiveInterval(null))
|
.isThrownBy(() -> this.sessionRepository.setDefaultMaxInactiveInterval(null))
|
||||||
.withMessage("defaultMaxInactiveInterval must not be null");
|
.withMessage("defaultMaxInactiveInterval must not be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -105,13 +105,13 @@ class RedisSessionRepositoryTests {
|
|||||||
@Test
|
@Test
|
||||||
void setRedisKeyNamespace_NullNamespace_ShouldThrowException() {
|
void setRedisKeyNamespace_NullNamespace_ShouldThrowException() {
|
||||||
assertThatIllegalArgumentException().isThrownBy(() -> this.sessionRepository.setRedisKeyNamespace(null))
|
assertThatIllegalArgumentException().isThrownBy(() -> this.sessionRepository.setRedisKeyNamespace(null))
|
||||||
.withMessage("namespace must not be empty");
|
.withMessage("namespace must not be empty");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void setRedisKeyNamespace_EmptyNamespace_ShouldThrowException() {
|
void setRedisKeyNamespace_EmptyNamespace_ShouldThrowException() {
|
||||||
assertThatIllegalArgumentException().isThrownBy(() -> this.sessionRepository.setRedisKeyNamespace(" "))
|
assertThatIllegalArgumentException().isThrownBy(() -> this.sessionRepository.setRedisKeyNamespace(" "))
|
||||||
.withMessage("namespace must not be empty");
|
.withMessage("namespace must not be empty");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -123,27 +123,27 @@ class RedisSessionRepositoryTests {
|
|||||||
@Test
|
@Test
|
||||||
void setFlushMode_NullFlushMode_ShouldThrowException() {
|
void setFlushMode_NullFlushMode_ShouldThrowException() {
|
||||||
assertThatIllegalArgumentException().isThrownBy(() -> this.sessionRepository.setFlushMode(null))
|
assertThatIllegalArgumentException().isThrownBy(() -> this.sessionRepository.setFlushMode(null))
|
||||||
.withMessage("flushMode must not be null");
|
.withMessage("flushMode must not be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void setSaveMode_ValidSaveMode_ShouldSetSaveMode() {
|
void setSaveMode_ValidSaveMode_ShouldSetSaveMode() {
|
||||||
this.sessionRepository.setSaveMode(SaveMode.ON_GET_ATTRIBUTE);
|
this.sessionRepository.setSaveMode(SaveMode.ON_GET_ATTRIBUTE);
|
||||||
assertThat(ReflectionTestUtils.getField(this.sessionRepository, "saveMode"))
|
assertThat(ReflectionTestUtils.getField(this.sessionRepository, "saveMode"))
|
||||||
.isEqualTo(SaveMode.ON_GET_ATTRIBUTE);
|
.isEqualTo(SaveMode.ON_GET_ATTRIBUTE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void setSaveMode_NullSaveMode_ShouldThrowException() {
|
void setSaveMode_NullSaveMode_ShouldThrowException() {
|
||||||
assertThatIllegalArgumentException().isThrownBy(() -> this.sessionRepository.setSaveMode(null))
|
assertThatIllegalArgumentException().isThrownBy(() -> this.sessionRepository.setSaveMode(null))
|
||||||
.withMessage("saveMode must not be null");
|
.withMessage("saveMode must not be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void createSession_DefaultMaxInactiveInterval_ShouldCreateSession() {
|
void createSession_DefaultMaxInactiveInterval_ShouldCreateSession() {
|
||||||
RedisSession redisSession = this.sessionRepository.createSession();
|
RedisSession redisSession = this.sessionRepository.createSession();
|
||||||
assertThat(redisSession.getMaxInactiveInterval())
|
assertThat(redisSession.getMaxInactiveInterval())
|
||||||
.isEqualTo(Duration.ofSeconds(MapSession.DEFAULT_MAX_INACTIVE_INTERVAL_SECONDS));
|
.isEqualTo(Duration.ofSeconds(MapSession.DEFAULT_MAX_INACTIVE_INTERVAL_SECONDS));
|
||||||
verifyNoMoreInteractions(this.sessionRedisOperations);
|
verifyNoMoreInteractions(this.sessionRedisOperations);
|
||||||
verifyNoMoreInteractions(this.sessionHashOperations);
|
verifyNoMoreInteractions(this.sessionHashOperations);
|
||||||
}
|
}
|
||||||
@@ -304,7 +304,7 @@ class RedisSessionRepositoryTests {
|
|||||||
void save_SessionNotExists_ShouldThrowException() {
|
void save_SessionNotExists_ShouldThrowException() {
|
||||||
RedisSession session = createTestSession();
|
RedisSession session = createTestSession();
|
||||||
assertThatIllegalStateException().isThrownBy(() -> this.sessionRepository.save(session))
|
assertThatIllegalStateException().isThrownBy(() -> this.sessionRepository.save(session))
|
||||||
.withMessage("Session was invalidated");
|
.withMessage("Session was invalidated");
|
||||||
verify(this.sessionRedisOperations).hasKey(eq(TEST_SESSION_KEY));
|
verify(this.sessionRedisOperations).hasKey(eq(TEST_SESSION_KEY));
|
||||||
verifyNoMoreInteractions(this.sessionRedisOperations);
|
verifyNoMoreInteractions(this.sessionRedisOperations);
|
||||||
verifyNoMoreInteractions(this.sessionHashOperations);
|
verifyNoMoreInteractions(this.sessionHashOperations);
|
||||||
@@ -315,16 +315,16 @@ class RedisSessionRepositoryTests {
|
|||||||
void findById_SessionExists_ShouldReturnSession() {
|
void findById_SessionExists_ShouldReturnSession() {
|
||||||
Instant now = Instant.now().truncatedTo(ChronoUnit.MILLIS);
|
Instant now = Instant.now().truncatedTo(ChronoUnit.MILLIS);
|
||||||
given(this.sessionHashOperations.entries(eq(TEST_SESSION_KEY)))
|
given(this.sessionHashOperations.entries(eq(TEST_SESSION_KEY)))
|
||||||
.willReturn(mapOf(RedisSessionMapper.CREATION_TIME_KEY, Instant.EPOCH.toEpochMilli(),
|
.willReturn(mapOf(RedisSessionMapper.CREATION_TIME_KEY, Instant.EPOCH.toEpochMilli(),
|
||||||
RedisSessionMapper.LAST_ACCESSED_TIME_KEY, now.toEpochMilli(),
|
RedisSessionMapper.LAST_ACCESSED_TIME_KEY, now.toEpochMilli(),
|
||||||
RedisSessionMapper.MAX_INACTIVE_INTERVAL_KEY, MapSession.DEFAULT_MAX_INACTIVE_INTERVAL_SECONDS,
|
RedisSessionMapper.MAX_INACTIVE_INTERVAL_KEY, MapSession.DEFAULT_MAX_INACTIVE_INTERVAL_SECONDS,
|
||||||
RedisSessionMapper.ATTRIBUTE_PREFIX + "attribute1", "value1"));
|
RedisSessionMapper.ATTRIBUTE_PREFIX + "attribute1", "value1"));
|
||||||
RedisSession session = this.sessionRepository.findById(TEST_SESSION_ID);
|
RedisSession session = this.sessionRepository.findById(TEST_SESSION_ID);
|
||||||
assertThat(session.getId()).isEqualTo(TEST_SESSION_ID);
|
assertThat(session.getId()).isEqualTo(TEST_SESSION_ID);
|
||||||
assertThat(session.getCreationTime()).isEqualTo(Instant.EPOCH);
|
assertThat(session.getCreationTime()).isEqualTo(Instant.EPOCH);
|
||||||
assertThat(session.getLastAccessedTime()).isEqualTo(now);
|
assertThat(session.getLastAccessedTime()).isEqualTo(now);
|
||||||
assertThat(session.getMaxInactiveInterval())
|
assertThat(session.getMaxInactiveInterval())
|
||||||
.isEqualTo(Duration.ofSeconds(MapSession.DEFAULT_MAX_INACTIVE_INTERVAL_SECONDS));
|
.isEqualTo(Duration.ofSeconds(MapSession.DEFAULT_MAX_INACTIVE_INTERVAL_SECONDS));
|
||||||
assertThat(session.getAttributeNames()).isEqualTo(Collections.singleton("attribute1"));
|
assertThat(session.getAttributeNames()).isEqualTo(Collections.singleton("attribute1"));
|
||||||
assertThat(session.<String>getAttribute("attribute1")).isEqualTo("value1");
|
assertThat(session.<String>getAttribute("attribute1")).isEqualTo("value1");
|
||||||
verify(this.sessionRedisOperations).opsForHash();
|
verify(this.sessionRedisOperations).opsForHash();
|
||||||
@@ -337,10 +337,10 @@ class RedisSessionRepositoryTests {
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
void findById_SessionExistsAndIsExpired_ShouldReturnNull() {
|
void findById_SessionExistsAndIsExpired_ShouldReturnNull() {
|
||||||
given(this.sessionHashOperations.entries(eq(TEST_SESSION_KEY)))
|
given(this.sessionHashOperations.entries(eq(TEST_SESSION_KEY)))
|
||||||
.willReturn(mapOf(RedisSessionMapper.CREATION_TIME_KEY, Instant.EPOCH.toEpochMilli(),
|
.willReturn(mapOf(RedisSessionMapper.CREATION_TIME_KEY, Instant.EPOCH.toEpochMilli(),
|
||||||
RedisSessionMapper.LAST_ACCESSED_TIME_KEY, Instant.EPOCH.toEpochMilli(),
|
RedisSessionMapper.LAST_ACCESSED_TIME_KEY, Instant.EPOCH.toEpochMilli(),
|
||||||
RedisSessionMapper.MAX_INACTIVE_INTERVAL_KEY, MapSession.DEFAULT_MAX_INACTIVE_INTERVAL_SECONDS,
|
RedisSessionMapper.MAX_INACTIVE_INTERVAL_KEY, MapSession.DEFAULT_MAX_INACTIVE_INTERVAL_SECONDS,
|
||||||
RedisSessionMapper.ATTRIBUTE_PREFIX + "attribute1", "value1"));
|
RedisSessionMapper.ATTRIBUTE_PREFIX + "attribute1", "value1"));
|
||||||
assertThat(this.sessionRepository.findById(TEST_SESSION_ID)).isNull();
|
assertThat(this.sessionRepository.findById(TEST_SESSION_ID)).isNull();
|
||||||
verify(this.sessionRedisOperations).opsForHash();
|
verify(this.sessionRedisOperations).opsForHash();
|
||||||
verify(this.sessionHashOperations).entries(eq(TEST_SESSION_KEY));
|
verify(this.sessionHashOperations).entries(eq(TEST_SESSION_KEY));
|
||||||
@@ -379,7 +379,7 @@ class RedisSessionRepositoryTests {
|
|||||||
|
|
||||||
private static Instant getExpiry(RedisSession session) {
|
private static Instant getExpiry(RedisSession session) {
|
||||||
return Instant.ofEpochMilli(session.getLastAccessedTime().toEpochMilli())
|
return Instant.ofEpochMilli(session.getLastAccessedTime().toEpochMilli())
|
||||||
.plusSeconds(session.getMaxInactiveInterval().getSeconds());
|
.plusSeconds(session.getMaxInactiveInterval().getSeconds());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Map mapOf(Object... objects) {
|
private static Map mapOf(Object... objects) {
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ class RedisHttpsSessionConfigurationTests {
|
|||||||
@Test
|
@Test
|
||||||
void resolveValueByPlaceholder() {
|
void resolveValueByPlaceholder() {
|
||||||
this.context
|
this.context
|
||||||
.setEnvironment(new MockEnvironment().withProperty("session.redis.namespace", "customRedisNamespace"));
|
.setEnvironment(new MockEnvironment().withProperty("session.redis.namespace", "customRedisNamespace"));
|
||||||
registerAndRefresh(RedisConfig.class, PropertySourceConfiguration.class,
|
registerAndRefresh(RedisConfig.class, PropertySourceConfiguration.class,
|
||||||
CustomRedisHttpSessionConfiguration2.class);
|
CustomRedisHttpSessionConfiguration2.class);
|
||||||
RedisHttpSessionConfiguration configuration = this.context.getBean(RedisHttpSessionConfiguration.class);
|
RedisHttpSessionConfiguration configuration = this.context.getBean(RedisHttpSessionConfiguration.class);
|
||||||
@@ -127,10 +127,10 @@ class RedisHttpsSessionConfigurationTests {
|
|||||||
assertThat(redisConnectionFactory).isNotNull();
|
assertThat(redisConnectionFactory).isNotNull();
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
RedisOperations<String, Object> redisOperations = (RedisOperations<String, Object>) ReflectionTestUtils
|
RedisOperations<String, Object> redisOperations = (RedisOperations<String, Object>) ReflectionTestUtils
|
||||||
.getField(repository, "sessionRedisOperations");
|
.getField(repository, "sessionRedisOperations");
|
||||||
assertThat(redisOperations).isNotNull();
|
assertThat(redisOperations).isNotNull();
|
||||||
assertThat(ReflectionTestUtils.getField(redisOperations, "connectionFactory"))
|
assertThat(ReflectionTestUtils.getField(redisOperations, "connectionFactory"))
|
||||||
.isEqualTo(redisConnectionFactory);
|
.isEqualTo(redisConnectionFactory);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -144,10 +144,10 @@ class RedisHttpsSessionConfigurationTests {
|
|||||||
assertThat(redisConnectionFactory).isNotNull();
|
assertThat(redisConnectionFactory).isNotNull();
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
RedisOperations<String, Object> redisOperations = (RedisOperations<String, Object>) ReflectionTestUtils
|
RedisOperations<String, Object> redisOperations = (RedisOperations<String, Object>) ReflectionTestUtils
|
||||||
.getField(repository, "sessionRedisOperations");
|
.getField(repository, "sessionRedisOperations");
|
||||||
assertThat(redisOperations).isNotNull();
|
assertThat(redisOperations).isNotNull();
|
||||||
assertThat(ReflectionTestUtils.getField(redisOperations, "connectionFactory"))
|
assertThat(ReflectionTestUtils.getField(redisOperations, "connectionFactory"))
|
||||||
.isEqualTo(redisConnectionFactory);
|
.isEqualTo(redisConnectionFactory);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -161,10 +161,10 @@ class RedisHttpsSessionConfigurationTests {
|
|||||||
assertThat(redisConnectionFactory).isNotNull();
|
assertThat(redisConnectionFactory).isNotNull();
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
RedisOperations<String, Object> redisOperations = (RedisOperations<String, Object>) ReflectionTestUtils
|
RedisOperations<String, Object> redisOperations = (RedisOperations<String, Object>) ReflectionTestUtils
|
||||||
.getField(repository, "sessionRedisOperations");
|
.getField(repository, "sessionRedisOperations");
|
||||||
assertThat(redisOperations).isNotNull();
|
assertThat(redisOperations).isNotNull();
|
||||||
assertThat(ReflectionTestUtils.getField(redisOperations, "connectionFactory"))
|
assertThat(ReflectionTestUtils.getField(redisOperations, "connectionFactory"))
|
||||||
.isEqualTo(redisConnectionFactory);
|
.isEqualTo(redisConnectionFactory);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -178,17 +178,18 @@ class RedisHttpsSessionConfigurationTests {
|
|||||||
assertThat(redisConnectionFactory).isNotNull();
|
assertThat(redisConnectionFactory).isNotNull();
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
RedisOperations<String, Object> redisOperations = (RedisOperations<String, Object>) ReflectionTestUtils
|
RedisOperations<String, Object> redisOperations = (RedisOperations<String, Object>) ReflectionTestUtils
|
||||||
.getField(repository, "sessionRedisOperations");
|
.getField(repository, "sessionRedisOperations");
|
||||||
assertThat(redisOperations).isNotNull();
|
assertThat(redisOperations).isNotNull();
|
||||||
assertThat(ReflectionTestUtils.getField(redisOperations, "connectionFactory"))
|
assertThat(ReflectionTestUtils.getField(redisOperations, "connectionFactory"))
|
||||||
.isEqualTo(redisConnectionFactory);
|
.isEqualTo(redisConnectionFactory);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void multipleConnectionFactoryRedisConfig() {
|
void multipleConnectionFactoryRedisConfig() {
|
||||||
assertThatExceptionOfType(BeanCreationException.class)
|
assertThatExceptionOfType(BeanCreationException.class)
|
||||||
.isThrownBy(() -> registerAndRefresh(RedisConfig.class, MultipleConnectionFactoryRedisConfig.class))
|
.isThrownBy(() -> registerAndRefresh(RedisConfig.class, MultipleConnectionFactoryRedisConfig.class))
|
||||||
.havingRootCause().withMessageContaining("expected single matching bean but found 2");
|
.havingRootCause()
|
||||||
|
.withMessageContaining("expected single matching bean but found 2");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -365,7 +366,7 @@ class RedisHttpsSessionConfigurationTests {
|
|||||||
@Order(1)
|
@Order(1)
|
||||||
SessionRepositoryCustomizer<RedisSessionRepository> sessionRepositoryCustomizerTwo() {
|
SessionRepositoryCustomizer<RedisSessionRepository> sessionRepositoryCustomizerTwo() {
|
||||||
return (sessionRepository) -> sessionRepository
|
return (sessionRepository) -> sessionRepository
|
||||||
.setDefaultMaxInactiveInterval(Duration.ofSeconds(MAX_INACTIVE_INTERVAL_IN_SECONDS));
|
.setDefaultMaxInactiveInterval(Duration.ofSeconds(MAX_INACTIVE_INTERVAL_IN_SECONDS));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -84,18 +84,18 @@ class RedisIndexedHttpSessionConfigurationTests {
|
|||||||
void resolveValue() {
|
void resolveValue() {
|
||||||
registerAndRefresh(RedisConfig.class, CustomRedisHttpSessionConfiguration.class);
|
registerAndRefresh(RedisConfig.class, CustomRedisHttpSessionConfiguration.class);
|
||||||
RedisIndexedHttpSessionConfiguration configuration = this.context
|
RedisIndexedHttpSessionConfiguration configuration = this.context
|
||||||
.getBean(RedisIndexedHttpSessionConfiguration.class);
|
.getBean(RedisIndexedHttpSessionConfiguration.class);
|
||||||
assertThat(ReflectionTestUtils.getField(configuration, "redisNamespace")).isEqualTo("myRedisNamespace");
|
assertThat(ReflectionTestUtils.getField(configuration, "redisNamespace")).isEqualTo("myRedisNamespace");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void resolveValueByPlaceholder() {
|
void resolveValueByPlaceholder() {
|
||||||
this.context
|
this.context
|
||||||
.setEnvironment(new MockEnvironment().withProperty("session.redis.namespace", "customRedisNamespace"));
|
.setEnvironment(new MockEnvironment().withProperty("session.redis.namespace", "customRedisNamespace"));
|
||||||
registerAndRefresh(RedisConfig.class, PropertySourceConfiguration.class,
|
registerAndRefresh(RedisConfig.class, PropertySourceConfiguration.class,
|
||||||
CustomRedisHttpSessionConfiguration2.class);
|
CustomRedisHttpSessionConfiguration2.class);
|
||||||
RedisIndexedHttpSessionConfiguration configuration = this.context
|
RedisIndexedHttpSessionConfiguration configuration = this.context
|
||||||
.getBean(RedisIndexedHttpSessionConfiguration.class);
|
.getBean(RedisIndexedHttpSessionConfiguration.class);
|
||||||
assertThat(ReflectionTestUtils.getField(configuration, "redisNamespace")).isEqualTo("customRedisNamespace");
|
assertThat(ReflectionTestUtils.getField(configuration, "redisNamespace")).isEqualTo("customRedisNamespace");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -141,10 +141,10 @@ class RedisIndexedHttpSessionConfigurationTests {
|
|||||||
assertThat(redisConnectionFactory).isNotNull();
|
assertThat(redisConnectionFactory).isNotNull();
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
RedisOperations<String, Object> redisOperations = (RedisOperations<String, Object>) ReflectionTestUtils
|
RedisOperations<String, Object> redisOperations = (RedisOperations<String, Object>) ReflectionTestUtils
|
||||||
.getField(repository, "sessionRedisOperations");
|
.getField(repository, "sessionRedisOperations");
|
||||||
assertThat(redisOperations).isNotNull();
|
assertThat(redisOperations).isNotNull();
|
||||||
assertThat(ReflectionTestUtils.getField(redisOperations, "connectionFactory"))
|
assertThat(ReflectionTestUtils.getField(redisOperations, "connectionFactory"))
|
||||||
.isEqualTo(redisConnectionFactory);
|
.isEqualTo(redisConnectionFactory);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -158,10 +158,10 @@ class RedisIndexedHttpSessionConfigurationTests {
|
|||||||
assertThat(redisConnectionFactory).isNotNull();
|
assertThat(redisConnectionFactory).isNotNull();
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
RedisOperations<String, Object> redisOperations = (RedisOperations<String, Object>) ReflectionTestUtils
|
RedisOperations<String, Object> redisOperations = (RedisOperations<String, Object>) ReflectionTestUtils
|
||||||
.getField(repository, "sessionRedisOperations");
|
.getField(repository, "sessionRedisOperations");
|
||||||
assertThat(redisOperations).isNotNull();
|
assertThat(redisOperations).isNotNull();
|
||||||
assertThat(ReflectionTestUtils.getField(redisOperations, "connectionFactory"))
|
assertThat(ReflectionTestUtils.getField(redisOperations, "connectionFactory"))
|
||||||
.isEqualTo(redisConnectionFactory);
|
.isEqualTo(redisConnectionFactory);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -175,10 +175,10 @@ class RedisIndexedHttpSessionConfigurationTests {
|
|||||||
assertThat(redisConnectionFactory).isNotNull();
|
assertThat(redisConnectionFactory).isNotNull();
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
RedisOperations<String, Object> redisOperations = (RedisOperations<String, Object>) ReflectionTestUtils
|
RedisOperations<String, Object> redisOperations = (RedisOperations<String, Object>) ReflectionTestUtils
|
||||||
.getField(repository, "sessionRedisOperations");
|
.getField(repository, "sessionRedisOperations");
|
||||||
assertThat(redisOperations).isNotNull();
|
assertThat(redisOperations).isNotNull();
|
||||||
assertThat(ReflectionTestUtils.getField(redisOperations, "connectionFactory"))
|
assertThat(ReflectionTestUtils.getField(redisOperations, "connectionFactory"))
|
||||||
.isEqualTo(redisConnectionFactory);
|
.isEqualTo(redisConnectionFactory);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -192,17 +192,18 @@ class RedisIndexedHttpSessionConfigurationTests {
|
|||||||
assertThat(redisConnectionFactory).isNotNull();
|
assertThat(redisConnectionFactory).isNotNull();
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
RedisOperations<String, Object> redisOperations = (RedisOperations<String, Object>) ReflectionTestUtils
|
RedisOperations<String, Object> redisOperations = (RedisOperations<String, Object>) ReflectionTestUtils
|
||||||
.getField(repository, "sessionRedisOperations");
|
.getField(repository, "sessionRedisOperations");
|
||||||
assertThat(redisOperations).isNotNull();
|
assertThat(redisOperations).isNotNull();
|
||||||
assertThat(ReflectionTestUtils.getField(redisOperations, "connectionFactory"))
|
assertThat(ReflectionTestUtils.getField(redisOperations, "connectionFactory"))
|
||||||
.isEqualTo(redisConnectionFactory);
|
.isEqualTo(redisConnectionFactory);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void multipleConnectionFactoryRedisConfig() {
|
void multipleConnectionFactoryRedisConfig() {
|
||||||
assertThatExceptionOfType(BeanCreationException.class)
|
assertThatExceptionOfType(BeanCreationException.class)
|
||||||
.isThrownBy(() -> registerAndRefresh(RedisConfig.class, MultipleConnectionFactoryRedisConfig.class))
|
.isThrownBy(() -> registerAndRefresh(RedisConfig.class, MultipleConnectionFactoryRedisConfig.class))
|
||||||
.havingRootCause().withMessageContaining("expected single matching bean but found 2");
|
.havingRootCause()
|
||||||
|
.withMessageContaining("expected single matching bean but found 2");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -220,7 +221,7 @@ class RedisIndexedHttpSessionConfigurationTests {
|
|||||||
void customRedisMessageListenerContainerConfig() {
|
void customRedisMessageListenerContainerConfig() {
|
||||||
registerAndRefresh(RedisConfig.class, CustomRedisMessageListenerContainerConfig.class);
|
registerAndRefresh(RedisConfig.class, CustomRedisMessageListenerContainerConfig.class);
|
||||||
Map<String, RedisMessageListenerContainer> beans = this.context
|
Map<String, RedisMessageListenerContainer> beans = this.context
|
||||||
.getBeansOfType(RedisMessageListenerContainer.class);
|
.getBeansOfType(RedisMessageListenerContainer.class);
|
||||||
assertThat(beans).hasSize(2);
|
assertThat(beans).hasSize(2);
|
||||||
assertThat(beans).containsKeys("springSessionRedisMessageListenerContainer", "redisMessageListenerContainer");
|
assertThat(beans).containsKeys("springSessionRedisMessageListenerContainer", "redisMessageListenerContainer");
|
||||||
}
|
}
|
||||||
@@ -230,7 +231,7 @@ class RedisIndexedHttpSessionConfigurationTests {
|
|||||||
registerAndRefresh(RedisConfig.class, SessionRepositoryCustomizerConfiguration.class);
|
registerAndRefresh(RedisConfig.class, SessionRepositoryCustomizerConfiguration.class);
|
||||||
RedisIndexedSessionRepository sessionRepository = this.context.getBean(RedisIndexedSessionRepository.class);
|
RedisIndexedSessionRepository sessionRepository = this.context.getBean(RedisIndexedSessionRepository.class);
|
||||||
assertThat(sessionRepository).extracting("defaultMaxInactiveInterval")
|
assertThat(sessionRepository).extracting("defaultMaxInactiveInterval")
|
||||||
.isEqualTo(Duration.ofSeconds(MAX_INACTIVE_INTERVAL_IN_SECONDS));
|
.isEqualTo(Duration.ofSeconds(MAX_INACTIVE_INTERVAL_IN_SECONDS));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -428,7 +429,7 @@ class RedisIndexedHttpSessionConfigurationTests {
|
|||||||
@Order(1)
|
@Order(1)
|
||||||
SessionRepositoryCustomizer<RedisIndexedSessionRepository> sessionRepositoryCustomizerTwo() {
|
SessionRepositoryCustomizer<RedisIndexedSessionRepository> sessionRepositoryCustomizerTwo() {
|
||||||
return (sessionRepository) -> sessionRepository
|
return (sessionRepository) -> sessionRepository
|
||||||
.setDefaultMaxInactiveInterval(Duration.ofSeconds(MAX_INACTIVE_INTERVAL_IN_SECONDS));
|
.setDefaultMaxInactiveInterval(Duration.ofSeconds(MAX_INACTIVE_INTERVAL_IN_SECONDS));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -85,10 +85,11 @@ class RedisWebSessionConfigurationTests {
|
|||||||
ReactiveRedisSessionRepository repository = this.context.getBean(ReactiveRedisSessionRepository.class);
|
ReactiveRedisSessionRepository repository = this.context.getBean(ReactiveRedisSessionRepository.class);
|
||||||
assertThat(repository).isNotNull();
|
assertThat(repository).isNotNull();
|
||||||
ReactiveRedisOperations<String, Object> springSessionRedisOperations = this.context
|
ReactiveRedisOperations<String, Object> springSessionRedisOperations = this.context
|
||||||
.getBean(SpringSessionRedisOperationsResolvingConfig.class).getSpringSessionRedisOperations();
|
.getBean(SpringSessionRedisOperationsResolvingConfig.class)
|
||||||
|
.getSpringSessionRedisOperations();
|
||||||
assertThat(springSessionRedisOperations).isNotNull();
|
assertThat(springSessionRedisOperations).isNotNull();
|
||||||
assertThat((ReactiveRedisOperations) ReflectionTestUtils.getField(repository, "sessionRedisOperations"))
|
assertThat((ReactiveRedisOperations) ReflectionTestUtils.getField(repository, "sessionRedisOperations"))
|
||||||
.isEqualTo(springSessionRedisOperations);
|
.isEqualTo(springSessionRedisOperations);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -106,7 +107,7 @@ class RedisWebSessionConfigurationTests {
|
|||||||
|
|
||||||
ReactiveRedisSessionRepository repository = this.context.getBean(ReactiveRedisSessionRepository.class);
|
ReactiveRedisSessionRepository repository = this.context.getBean(ReactiveRedisSessionRepository.class);
|
||||||
assertThat(repository).extracting("defaultMaxInactiveInterval")
|
assertThat(repository).extracting("defaultMaxInactiveInterval")
|
||||||
.isEqualTo(Duration.ofSeconds(MAX_INACTIVE_INTERVAL_IN_SECONDS));
|
.isEqualTo(Duration.ofSeconds(MAX_INACTIVE_INTERVAL_IN_SECONDS));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -136,7 +137,7 @@ class RedisWebSessionConfigurationTests {
|
|||||||
"sessionRedisOperations");
|
"sessionRedisOperations");
|
||||||
assertThat(redisOperations).isNotNull();
|
assertThat(redisOperations).isNotNull();
|
||||||
assertThat(ReflectionTestUtils.getField(redisOperations, "connectionFactory"))
|
assertThat(ReflectionTestUtils.getField(redisOperations, "connectionFactory"))
|
||||||
.isEqualTo(redisConnectionFactory);
|
.isEqualTo(redisConnectionFactory);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -152,7 +153,7 @@ class RedisWebSessionConfigurationTests {
|
|||||||
"sessionRedisOperations");
|
"sessionRedisOperations");
|
||||||
assertThat(redisOperations).isNotNull();
|
assertThat(redisOperations).isNotNull();
|
||||||
assertThat(ReflectionTestUtils.getField(redisOperations, "connectionFactory"))
|
assertThat(ReflectionTestUtils.getField(redisOperations, "connectionFactory"))
|
||||||
.isEqualTo(redisConnectionFactory);
|
.isEqualTo(redisConnectionFactory);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -168,7 +169,7 @@ class RedisWebSessionConfigurationTests {
|
|||||||
"sessionRedisOperations");
|
"sessionRedisOperations");
|
||||||
assertThat(redisOperations).isNotNull();
|
assertThat(redisOperations).isNotNull();
|
||||||
assertThat(ReflectionTestUtils.getField(redisOperations, "connectionFactory"))
|
assertThat(ReflectionTestUtils.getField(redisOperations, "connectionFactory"))
|
||||||
.isEqualTo(redisConnectionFactory);
|
.isEqualTo(redisConnectionFactory);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -184,15 +185,16 @@ class RedisWebSessionConfigurationTests {
|
|||||||
"sessionRedisOperations");
|
"sessionRedisOperations");
|
||||||
assertThat(redisOperations).isNotNull();
|
assertThat(redisOperations).isNotNull();
|
||||||
assertThat(ReflectionTestUtils.getField(redisOperations, "connectionFactory"))
|
assertThat(ReflectionTestUtils.getField(redisOperations, "connectionFactory"))
|
||||||
.isEqualTo(redisConnectionFactory);
|
.isEqualTo(redisConnectionFactory);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void multipleConnectionFactoryRedisConfig() {
|
void multipleConnectionFactoryRedisConfig() {
|
||||||
assertThatExceptionOfType(BeanCreationException.class)
|
assertThatExceptionOfType(BeanCreationException.class)
|
||||||
.isThrownBy(() -> registerAndRefresh(RedisConfig.class, MultipleConnectionFactoryRedisConfig.class))
|
.isThrownBy(() -> registerAndRefresh(RedisConfig.class, MultipleConnectionFactoryRedisConfig.class))
|
||||||
.havingRootCause().isInstanceOf(NoUniqueBeanDefinitionException.class)
|
.havingRootCause()
|
||||||
.withMessageContaining("expected single matching bean but found 2");
|
.isInstanceOf(NoUniqueBeanDefinitionException.class)
|
||||||
|
.withMessageContaining("expected single matching bean but found 2");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -210,13 +212,17 @@ class RedisWebSessionConfigurationTests {
|
|||||||
assertThat(redisOperations).isNotNull();
|
assertThat(redisOperations).isNotNull();
|
||||||
RedisSerializationContext serializationContext = redisOperations.getSerializationContext();
|
RedisSerializationContext serializationContext = redisOperations.getSerializationContext();
|
||||||
assertThat(ReflectionTestUtils.getField(serializationContext.getValueSerializationPair().getReader(),
|
assertThat(ReflectionTestUtils.getField(serializationContext.getValueSerializationPair().getReader(),
|
||||||
"serializer")).isEqualTo(redisSerializer);
|
"serializer"))
|
||||||
|
.isEqualTo(redisSerializer);
|
||||||
assertThat(ReflectionTestUtils.getField(serializationContext.getValueSerializationPair().getWriter(),
|
assertThat(ReflectionTestUtils.getField(serializationContext.getValueSerializationPair().getWriter(),
|
||||||
"serializer")).isEqualTo(redisSerializer);
|
"serializer"))
|
||||||
|
.isEqualTo(redisSerializer);
|
||||||
assertThat(ReflectionTestUtils.getField(serializationContext.getHashValueSerializationPair().getReader(),
|
assertThat(ReflectionTestUtils.getField(serializationContext.getHashValueSerializationPair().getReader(),
|
||||||
"serializer")).isEqualTo(redisSerializer);
|
"serializer"))
|
||||||
|
.isEqualTo(redisSerializer);
|
||||||
assertThat(ReflectionTestUtils.getField(serializationContext.getHashValueSerializationPair().getWriter(),
|
assertThat(ReflectionTestUtils.getField(serializationContext.getHashValueSerializationPair().getWriter(),
|
||||||
"serializer")).isEqualTo(redisSerializer);
|
"serializer"))
|
||||||
|
.isEqualTo(redisSerializer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -224,7 +230,7 @@ class RedisWebSessionConfigurationTests {
|
|||||||
registerAndRefresh(RedisConfig.class, SessionRepositoryCustomizerConfiguration.class);
|
registerAndRefresh(RedisConfig.class, SessionRepositoryCustomizerConfiguration.class);
|
||||||
ReactiveRedisSessionRepository sessionRepository = this.context.getBean(ReactiveRedisSessionRepository.class);
|
ReactiveRedisSessionRepository sessionRepository = this.context.getBean(ReactiveRedisSessionRepository.class);
|
||||||
assertThat(sessionRepository).extracting("defaultMaxInactiveInterval")
|
assertThat(sessionRepository).extracting("defaultMaxInactiveInterval")
|
||||||
.isEqualTo(Duration.ofSeconds(MAX_INACTIVE_INTERVAL_IN_SECONDS));
|
.isEqualTo(Duration.ofSeconds(MAX_INACTIVE_INTERVAL_IN_SECONDS));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -385,7 +391,7 @@ class RedisWebSessionConfigurationTests {
|
|||||||
@Order(1)
|
@Order(1)
|
||||||
ReactiveSessionRepositoryCustomizer<ReactiveRedisSessionRepository> sessionRepositoryCustomizerTwo() {
|
ReactiveSessionRepositoryCustomizer<ReactiveRedisSessionRepository> sessionRepositoryCustomizerTwo() {
|
||||||
return (sessionRepository) -> sessionRepository
|
return (sessionRepository) -> sessionRepository
|
||||||
.setDefaultMaxInactiveInterval(Duration.ofSeconds(MAX_INACTIVE_INTERVAL_IN_SECONDS));
|
.setDefaultMaxInactiveInterval(Duration.ofSeconds(MAX_INACTIVE_INTERVAL_IN_SECONDS));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -147,7 +147,8 @@ class IndexDocTests {
|
|||||||
void newReactiveRedisSessionRepository() {
|
void newReactiveRedisSessionRepository() {
|
||||||
LettuceConnectionFactory connectionFactory = new LettuceConnectionFactory();
|
LettuceConnectionFactory connectionFactory = new LettuceConnectionFactory();
|
||||||
RedisSerializationContext<String, Object> serializationContext = RedisSerializationContext
|
RedisSerializationContext<String, Object> serializationContext = RedisSerializationContext
|
||||||
.<String, Object>newSerializationContext(new JdkSerializationRedisSerializer()).build();
|
.<String, Object>newSerializationContext(new JdkSerializationRedisSerializer())
|
||||||
|
.build();
|
||||||
|
|
||||||
// tag::new-reactiveredissessionrepository[]
|
// tag::new-reactiveredissessionrepository[]
|
||||||
// ... create and configure connectionFactory and serializationContext ...
|
// ... create and configure connectionFactory and serializationContext ...
|
||||||
|
|||||||
@@ -41,11 +41,12 @@ public class HazelcastHttpSessionConfig {
|
|||||||
public HazelcastInstance hazelcastInstance() {
|
public HazelcastInstance hazelcastInstance() {
|
||||||
Config config = new Config();
|
Config config = new Config();
|
||||||
AttributeConfig attributeConfig = new AttributeConfig()
|
AttributeConfig attributeConfig = new AttributeConfig()
|
||||||
.setName(HazelcastIndexedSessionRepository.PRINCIPAL_NAME_ATTRIBUTE)
|
.setName(HazelcastIndexedSessionRepository.PRINCIPAL_NAME_ATTRIBUTE)
|
||||||
.setExtractorClassName(PrincipalNameExtractor.class.getName());
|
.setExtractorClassName(PrincipalNameExtractor.class.getName());
|
||||||
config.getMapConfig(HazelcastIndexedSessionRepository.DEFAULT_SESSION_MAP_NAME) // <2>
|
config.getMapConfig(HazelcastIndexedSessionRepository.DEFAULT_SESSION_MAP_NAME) // <2>
|
||||||
.addAttributeConfig(attributeConfig).addIndexConfig(
|
.addAttributeConfig(attributeConfig)
|
||||||
new IndexConfig(IndexType.HASH, HazelcastIndexedSessionRepository.PRINCIPAL_NAME_ATTRIBUTE));
|
.addIndexConfig(
|
||||||
|
new IndexConfig(IndexType.HASH, HazelcastIndexedSessionRepository.PRINCIPAL_NAME_ATTRIBUTE));
|
||||||
SerializerConfig serializerConfig = new SerializerConfig();
|
SerializerConfig serializerConfig = new SerializerConfig();
|
||||||
serializerConfig.setImplementation(new HazelcastSessionSerializer()).setTypeClass(MapSession.class);
|
serializerConfig.setImplementation(new HazelcastSessionSerializer()).setTypeClass(MapSession.class);
|
||||||
config.getSerializationConfig().addSerializerConfig(serializerConfig); // <3>
|
config.getSerializationConfig().addSerializerConfig(serializerConfig); // <3>
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ abstract class AbstractHazelcastIndexedSessionRepositoryITests {
|
|||||||
String sessionId = sessionToSave.getId();
|
String sessionId = sessionToSave.getId();
|
||||||
|
|
||||||
IMap<String, MapSession> hazelcastMap = this.hazelcastInstance
|
IMap<String, MapSession> hazelcastMap = this.hazelcastInstance
|
||||||
.getMap(HazelcastIndexedSessionRepository.DEFAULT_SESSION_MAP_NAME);
|
.getMap(HazelcastIndexedSessionRepository.DEFAULT_SESSION_MAP_NAME);
|
||||||
|
|
||||||
this.repository.save(sessionToSave);
|
this.repository.save(sessionToSave);
|
||||||
|
|
||||||
@@ -222,8 +222,8 @@ abstract class AbstractHazelcastIndexedSessionRepositoryITests {
|
|||||||
this.repository.save(session);
|
this.repository.save(session);
|
||||||
|
|
||||||
assertThat(this.repository
|
assertThat(this.repository
|
||||||
.findByIndexNameAndIndexValue(FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME, username))
|
.findByIndexNameAndIndexValue(FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME, username))
|
||||||
.hasSize(1);
|
.hasSize(1);
|
||||||
|
|
||||||
this.repository.deleteById(session.getId());
|
this.repository.deleteById(session.getId());
|
||||||
}
|
}
|
||||||
@@ -233,7 +233,7 @@ abstract class AbstractHazelcastIndexedSessionRepositoryITests {
|
|||||||
final Duration defaultSessionTimeout = Duration.ofSeconds(1800);
|
final Duration defaultSessionTimeout = Duration.ofSeconds(1800);
|
||||||
|
|
||||||
final IMap<String, MapSession> hazelcastMap = this.hazelcastInstance
|
final IMap<String, MapSession> hazelcastMap = this.hazelcastInstance
|
||||||
.getMap(HazelcastIndexedSessionRepository.DEFAULT_SESSION_MAP_NAME);
|
.getMap(HazelcastIndexedSessionRepository.DEFAULT_SESSION_MAP_NAME);
|
||||||
|
|
||||||
HazelcastSession session = this.repository.createSession();
|
HazelcastSession session = this.repository.createSession();
|
||||||
String sessionId = session.getId();
|
String sessionId = session.getId();
|
||||||
@@ -256,7 +256,7 @@ abstract class AbstractHazelcastIndexedSessionRepositoryITests {
|
|||||||
final Duration individualSessionTimeout = Duration.ofSeconds(23);
|
final Duration individualSessionTimeout = Duration.ofSeconds(23);
|
||||||
|
|
||||||
final IMap<String, MapSession> hazelcastMap = this.hazelcastInstance
|
final IMap<String, MapSession> hazelcastMap = this.hazelcastInstance
|
||||||
.getMap(HazelcastIndexedSessionRepository.DEFAULT_SESSION_MAP_NAME);
|
.getMap(HazelcastIndexedSessionRepository.DEFAULT_SESSION_MAP_NAME);
|
||||||
|
|
||||||
HazelcastSession session = this.repository.createSession();
|
HazelcastSession session = this.repository.createSession();
|
||||||
session.setMaxInactiveInterval(individualSessionTimeout);
|
session.setMaxInactiveInterval(individualSessionTimeout);
|
||||||
|
|||||||
@@ -78,8 +78,11 @@ class ClientServerHazelcastIndexedSessionRepositoryITests extends AbstractHazelc
|
|||||||
HazelcastInstance hazelcastInstance() {
|
HazelcastInstance hazelcastInstance() {
|
||||||
ClientConfig clientConfig = new ClientConfig();
|
ClientConfig clientConfig = new ClientConfig();
|
||||||
clientConfig.getNetworkConfig().addAddress(container.getHost() + ":" + container.getFirstMappedPort());
|
clientConfig.getNetworkConfig().addAddress(container.getHost() + ":" + container.getFirstMappedPort());
|
||||||
clientConfig.getUserCodeDeploymentConfig().setEnabled(true).addClass(Session.class)
|
clientConfig.getUserCodeDeploymentConfig()
|
||||||
.addClass(MapSession.class).addClass(SessionUpdateEntryProcessor.class);
|
.setEnabled(true)
|
||||||
|
.addClass(Session.class)
|
||||||
|
.addClass(MapSession.class)
|
||||||
|
.addClass(SessionUpdateEntryProcessor.class);
|
||||||
return HazelcastClient.newHazelcastClient(clientConfig);
|
return HazelcastClient.newHazelcastClient(clientConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ class FlushImmediateHazelcastIndexedSessionRepositoryITests {
|
|||||||
this.repository.save(session);
|
this.repository.save(session);
|
||||||
|
|
||||||
Map<String, HazelcastIndexedSessionRepository.HazelcastSession> findByPrincipalName = this.repository
|
Map<String, HazelcastIndexedSessionRepository.HazelcastSession> findByPrincipalName = this.repository
|
||||||
.findByPrincipalName(username);
|
.findByPrincipalName(username);
|
||||||
|
|
||||||
assertThat(findByPrincipalName).hasSize(1);
|
assertThat(findByPrincipalName).hasSize(1);
|
||||||
assertThat(findByPrincipalName.keySet()).containsOnly(sessionId);
|
assertThat(findByPrincipalName.keySet()).containsOnly(sessionId);
|
||||||
|
|||||||
@@ -47,11 +47,12 @@ final class HazelcastITestUtils {
|
|||||||
networkConfig.setPort(0);
|
networkConfig.setPort(0);
|
||||||
networkConfig.getJoin().getAutoDetectionConfig().setEnabled(false);
|
networkConfig.getJoin().getAutoDetectionConfig().setEnabled(false);
|
||||||
AttributeConfig attributeConfig = new AttributeConfig()
|
AttributeConfig attributeConfig = new AttributeConfig()
|
||||||
.setName(HazelcastIndexedSessionRepository.PRINCIPAL_NAME_ATTRIBUTE)
|
.setName(HazelcastIndexedSessionRepository.PRINCIPAL_NAME_ATTRIBUTE)
|
||||||
.setExtractorClassName(PrincipalNameExtractor.class.getName());
|
.setExtractorClassName(PrincipalNameExtractor.class.getName());
|
||||||
config.getMapConfig(HazelcastIndexedSessionRepository.DEFAULT_SESSION_MAP_NAME)
|
config.getMapConfig(HazelcastIndexedSessionRepository.DEFAULT_SESSION_MAP_NAME)
|
||||||
.addAttributeConfig(attributeConfig).addIndexConfig(
|
.addAttributeConfig(attributeConfig)
|
||||||
new IndexConfig(IndexType.HASH, HazelcastIndexedSessionRepository.PRINCIPAL_NAME_ATTRIBUTE));
|
.addIndexConfig(
|
||||||
|
new IndexConfig(IndexType.HASH, HazelcastIndexedSessionRepository.PRINCIPAL_NAME_ATTRIBUTE));
|
||||||
SerializerConfig serializerConfig = new SerializerConfig();
|
SerializerConfig serializerConfig = new SerializerConfig();
|
||||||
serializerConfig.setImplementation(new HazelcastSessionSerializer()).setTypeClass(MapSession.class);
|
serializerConfig.setImplementation(new HazelcastSessionSerializer()).setTypeClass(MapSession.class);
|
||||||
config.getSerializationConfig().addSerializerConfig(serializerConfig);
|
config.getSerializationConfig().addSerializerConfig(serializerConfig);
|
||||||
|
|||||||
@@ -91,14 +91,14 @@ class SessionEventHazelcastIndexedSessionRepositoryTests<S extends Session> {
|
|||||||
|
|
||||||
assertThat(this.registry.receivedEvent(sessionToSave.getId())).isTrue();
|
assertThat(this.registry.receivedEvent(sessionToSave.getId())).isTrue();
|
||||||
assertThat(this.registry.<SessionCreatedEvent>getEvent(sessionToSave.getId()))
|
assertThat(this.registry.<SessionCreatedEvent>getEvent(sessionToSave.getId()))
|
||||||
.isInstanceOf(SessionCreatedEvent.class);
|
.isInstanceOf(SessionCreatedEvent.class);
|
||||||
|
|
||||||
Session session = this.repository.findById(sessionToSave.getId());
|
Session session = this.repository.findById(sessionToSave.getId());
|
||||||
|
|
||||||
assertThat(session.getId()).isEqualTo(sessionToSave.getId());
|
assertThat(session.getId()).isEqualTo(sessionToSave.getId());
|
||||||
assertThat(session.getAttributeNames()).isEqualTo(sessionToSave.getAttributeNames());
|
assertThat(session.getAttributeNames()).isEqualTo(sessionToSave.getAttributeNames());
|
||||||
assertThat(session.<String>getAttribute(expectedAttributeName))
|
assertThat(session.<String>getAttribute(expectedAttributeName))
|
||||||
.isEqualTo(sessionToSave.getAttribute(expectedAttributeName));
|
.isEqualTo(sessionToSave.getAttribute(expectedAttributeName));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -109,15 +109,15 @@ class SessionEventHazelcastIndexedSessionRepositoryTests<S extends Session> {
|
|||||||
|
|
||||||
assertThat(this.registry.receivedEvent(sessionToSave.getId())).isTrue();
|
assertThat(this.registry.receivedEvent(sessionToSave.getId())).isTrue();
|
||||||
assertThat(this.registry.<SessionCreatedEvent>getEvent(sessionToSave.getId()))
|
assertThat(this.registry.<SessionCreatedEvent>getEvent(sessionToSave.getId()))
|
||||||
.isInstanceOf(SessionCreatedEvent.class);
|
.isInstanceOf(SessionCreatedEvent.class);
|
||||||
this.registry.clear();
|
this.registry.clear();
|
||||||
|
|
||||||
assertThat(sessionToSave.getMaxInactiveInterval())
|
assertThat(sessionToSave.getMaxInactiveInterval())
|
||||||
.isEqualTo(Duration.ofSeconds(MAX_INACTIVE_INTERVAL_IN_SECONDS));
|
.isEqualTo(Duration.ofSeconds(MAX_INACTIVE_INTERVAL_IN_SECONDS));
|
||||||
|
|
||||||
assertThat(this.registry.receivedEvent(sessionToSave.getId())).isTrue();
|
assertThat(this.registry.receivedEvent(sessionToSave.getId())).isTrue();
|
||||||
assertThat(this.registry.<SessionExpiredEvent>getEvent(sessionToSave.getId()))
|
assertThat(this.registry.<SessionExpiredEvent>getEvent(sessionToSave.getId()))
|
||||||
.isInstanceOf(SessionExpiredEvent.class);
|
.isInstanceOf(SessionExpiredEvent.class);
|
||||||
|
|
||||||
assertThat(this.repository.findById(sessionToSave.getId())).isNull();
|
assertThat(this.repository.findById(sessionToSave.getId())).isNull();
|
||||||
}
|
}
|
||||||
@@ -130,14 +130,14 @@ class SessionEventHazelcastIndexedSessionRepositoryTests<S extends Session> {
|
|||||||
|
|
||||||
assertThat(this.registry.receivedEvent(sessionToSave.getId())).isTrue();
|
assertThat(this.registry.receivedEvent(sessionToSave.getId())).isTrue();
|
||||||
assertThat(this.registry.<SessionCreatedEvent>getEvent(sessionToSave.getId()))
|
assertThat(this.registry.<SessionCreatedEvent>getEvent(sessionToSave.getId()))
|
||||||
.isInstanceOf(SessionCreatedEvent.class);
|
.isInstanceOf(SessionCreatedEvent.class);
|
||||||
this.registry.clear();
|
this.registry.clear();
|
||||||
|
|
||||||
this.repository.deleteById(sessionToSave.getId());
|
this.repository.deleteById(sessionToSave.getId());
|
||||||
|
|
||||||
assertThat(this.registry.receivedEvent(sessionToSave.getId())).isTrue();
|
assertThat(this.registry.receivedEvent(sessionToSave.getId())).isTrue();
|
||||||
assertThat(this.registry.<SessionDeletedEvent>getEvent(sessionToSave.getId()))
|
assertThat(this.registry.<SessionDeletedEvent>getEvent(sessionToSave.getId()))
|
||||||
.isInstanceOf(SessionDeletedEvent.class);
|
.isInstanceOf(SessionDeletedEvent.class);
|
||||||
|
|
||||||
assertThat(this.repository.findById(sessionToSave.getId())).isNull();
|
assertThat(this.repository.findById(sessionToSave.getId())).isNull();
|
||||||
}
|
}
|
||||||
@@ -169,7 +169,7 @@ class SessionEventHazelcastIndexedSessionRepositoryTests<S extends Session> {
|
|||||||
|
|
||||||
assertThat(this.registry.receivedEvent(sessionToSave.getId())).isTrue();
|
assertThat(this.registry.receivedEvent(sessionToSave.getId())).isTrue();
|
||||||
assertThat(this.registry.<SessionCreatedEvent>getEvent(sessionToSave.getId()))
|
assertThat(this.registry.<SessionCreatedEvent>getEvent(sessionToSave.getId()))
|
||||||
.isInstanceOf(SessionCreatedEvent.class);
|
.isInstanceOf(SessionCreatedEvent.class);
|
||||||
this.registry.clear();
|
this.registry.clear();
|
||||||
|
|
||||||
sessionToSave.changeSessionId();
|
sessionToSave.changeSessionId();
|
||||||
@@ -186,7 +186,7 @@ class SessionEventHazelcastIndexedSessionRepositoryTests<S extends Session> {
|
|||||||
|
|
||||||
assertThat(this.registry.receivedEvent(sessionToSave.getId())).isTrue();
|
assertThat(this.registry.receivedEvent(sessionToSave.getId())).isTrue();
|
||||||
assertThat(this.registry.<SessionCreatedEvent>getEvent(sessionToSave.getId()))
|
assertThat(this.registry.<SessionCreatedEvent>getEvent(sessionToSave.getId()))
|
||||||
.isInstanceOf(SessionCreatedEvent.class);
|
.isInstanceOf(SessionCreatedEvent.class);
|
||||||
this.registry.clear();
|
this.registry.clear();
|
||||||
|
|
||||||
S sessionToUpdate = this.repository.findById(sessionToSave.getId());
|
S sessionToUpdate = this.repository.findById(sessionToSave.getId());
|
||||||
@@ -196,7 +196,7 @@ class SessionEventHazelcastIndexedSessionRepositoryTests<S extends Session> {
|
|||||||
|
|
||||||
assertThat(this.registry.receivedEvent(sessionToUpdate.getId())).isTrue();
|
assertThat(this.registry.receivedEvent(sessionToUpdate.getId())).isTrue();
|
||||||
assertThat(this.registry.<SessionExpiredEvent>getEvent(sessionToUpdate.getId()))
|
assertThat(this.registry.<SessionExpiredEvent>getEvent(sessionToUpdate.getId()))
|
||||||
.isInstanceOf(SessionExpiredEvent.class);
|
.isInstanceOf(SessionExpiredEvent.class);
|
||||||
assertThat(this.repository.findById(sessionToUpdate.getId())).isNull();
|
assertThat(this.repository.findById(sessionToUpdate.getId())).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -377,7 +377,7 @@ public class HazelcastIndexedSessionRepository
|
|||||||
this.originalId = cached.getId();
|
this.originalId = cached.getId();
|
||||||
if (this.isNew || (HazelcastIndexedSessionRepository.this.saveMode == SaveMode.ALWAYS)) {
|
if (this.isNew || (HazelcastIndexedSessionRepository.this.saveMode == SaveMode.ALWAYS)) {
|
||||||
getAttributeNames()
|
getAttributeNames()
|
||||||
.forEach((attributeName) -> this.delta.put(attributeName, cached.getAttribute(attributeName)));
|
.forEach((attributeName) -> this.delta.put(attributeName, cached.getAttribute(attributeName)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -448,7 +448,7 @@ public class HazelcastIndexedSessionRepository
|
|||||||
this.delta.put(attributeName, attributeValue);
|
this.delta.put(attributeName, attributeValue);
|
||||||
if (SPRING_SECURITY_CONTEXT.equals(attributeName)) {
|
if (SPRING_SECURITY_CONTEXT.equals(attributeName)) {
|
||||||
Map<String, String> indexes = HazelcastIndexedSessionRepository.this.indexResolver
|
Map<String, String> indexes = HazelcastIndexedSessionRepository.this.indexResolver
|
||||||
.resolveIndexesFor(this);
|
.resolveIndexesFor(this);
|
||||||
String principal = (attributeValue != null) ? indexes.get(PRINCIPAL_NAME_INDEX_NAME) : null;
|
String principal = (attributeValue != null) ? indexes.get(PRINCIPAL_NAME_INDEX_NAME) : null;
|
||||||
this.delegate.setAttribute(PRINCIPAL_NAME_INDEX_NAME, principal);
|
this.delegate.setAttribute(PRINCIPAL_NAME_INDEX_NAME, principal);
|
||||||
this.delta.put(PRINCIPAL_NAME_INDEX_NAME, principal);
|
this.delta.put(PRINCIPAL_NAME_INDEX_NAME, principal);
|
||||||
|
|||||||
@@ -131,7 +131,7 @@ public class HazelcastHttpSessionConfiguration implements ImportAware {
|
|||||||
@Override
|
@Override
|
||||||
public void setImportMetadata(AnnotationMetadata importMetadata) {
|
public void setImportMetadata(AnnotationMetadata importMetadata) {
|
||||||
Map<String, Object> attributeMap = importMetadata
|
Map<String, Object> attributeMap = importMetadata
|
||||||
.getAnnotationAttributes(EnableHazelcastHttpSession.class.getName());
|
.getAnnotationAttributes(EnableHazelcastHttpSession.class.getName());
|
||||||
AnnotationAttributes attributes = AnnotationAttributes.fromMap(attributeMap);
|
AnnotationAttributes attributes = AnnotationAttributes.fromMap(attributeMap);
|
||||||
if (attributes == null) {
|
if (attributes == null) {
|
||||||
return;
|
return;
|
||||||
@@ -159,7 +159,7 @@ public class HazelcastHttpSessionConfiguration implements ImportAware {
|
|||||||
sessionRepository.setFlushMode(this.flushMode);
|
sessionRepository.setFlushMode(this.flushMode);
|
||||||
sessionRepository.setSaveMode(this.saveMode);
|
sessionRepository.setSaveMode(this.saveMode);
|
||||||
this.sessionRepositoryCustomizers
|
this.sessionRepositoryCustomizers
|
||||||
.forEach((sessionRepositoryCustomizer) -> sessionRepositoryCustomizer.customize(sessionRepository));
|
.forEach((sessionRepositoryCustomizer) -> sessionRepositoryCustomizer.customize(sessionRepository));
|
||||||
return sessionRepository;
|
return sessionRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -82,13 +82,13 @@ class HazelcastIndexedSessionRepositoryTests {
|
|||||||
@Test
|
@Test
|
||||||
void constructorNullHazelcastInstance() {
|
void constructorNullHazelcastInstance() {
|
||||||
assertThatIllegalArgumentException().isThrownBy(() -> new HazelcastIndexedSessionRepository(null))
|
assertThatIllegalArgumentException().isThrownBy(() -> new HazelcastIndexedSessionRepository(null))
|
||||||
.withMessage("HazelcastInstance must not be null");
|
.withMessage("HazelcastInstance must not be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void setSaveModeNull() {
|
void setSaveModeNull() {
|
||||||
assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setSaveMode(null))
|
assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setSaveMode(null))
|
||||||
.withMessage("saveMode must not be null");
|
.withMessage("saveMode must not be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -364,7 +364,7 @@ class HazelcastIndexedSessionRepositoryTests {
|
|||||||
String principal = "username";
|
String principal = "username";
|
||||||
|
|
||||||
Map<String, HazelcastSession> sessions = this.repository
|
Map<String, HazelcastSession> sessions = this.repository
|
||||||
.findByIndexNameAndIndexValue(FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME, principal);
|
.findByIndexNameAndIndexValue(FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME, principal);
|
||||||
|
|
||||||
assertThat(sessions).isEmpty();
|
assertThat(sessions).isEmpty();
|
||||||
verify(this.sessions, times(1)).values(isA(EqualPredicate.class));
|
verify(this.sessions, times(1)).values(isA(EqualPredicate.class));
|
||||||
@@ -388,7 +388,7 @@ class HazelcastIndexedSessionRepositoryTests {
|
|||||||
given(this.sessions.values(isA(EqualPredicate.class))).willReturn(saved);
|
given(this.sessions.values(isA(EqualPredicate.class))).willReturn(saved);
|
||||||
|
|
||||||
Map<String, HazelcastSession> sessions = this.repository
|
Map<String, HazelcastSession> sessions = this.repository
|
||||||
.findByIndexNameAndIndexValue(FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME, principal);
|
.findByIndexNameAndIndexValue(FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME, principal);
|
||||||
|
|
||||||
assertThat(sessions).hasSize(2);
|
assertThat(sessions).hasSize(2);
|
||||||
verify(this.sessions, times(1)).values(isA(EqualPredicate.class));
|
verify(this.sessions, times(1)).values(isA(EqualPredicate.class));
|
||||||
|
|||||||
@@ -71,8 +71,10 @@ class HazelcastHttpSessionConfigurationTests {
|
|||||||
@Test
|
@Test
|
||||||
void noHazelcastInstanceConfiguration() {
|
void noHazelcastInstanceConfiguration() {
|
||||||
assertThatExceptionOfType(BeanCreationException.class)
|
assertThatExceptionOfType(BeanCreationException.class)
|
||||||
.isThrownBy(() -> registerAndRefresh(NoHazelcastInstanceConfiguration.class)).havingRootCause()
|
.isThrownBy(() -> registerAndRefresh(NoHazelcastInstanceConfiguration.class))
|
||||||
.isInstanceOf(NoSuchBeanDefinitionException.class).withMessageContaining("HazelcastInstance");
|
.havingRootCause()
|
||||||
|
.isInstanceOf(NoSuchBeanDefinitionException.class)
|
||||||
|
.withMessageContaining("HazelcastInstance");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -108,7 +110,7 @@ class HazelcastHttpSessionConfigurationTests {
|
|||||||
|
|
||||||
HazelcastIndexedSessionRepository repository = this.context.getBean(HazelcastIndexedSessionRepository.class);
|
HazelcastIndexedSessionRepository repository = this.context.getBean(HazelcastIndexedSessionRepository.class);
|
||||||
assertThat(repository).extracting("defaultMaxInactiveInterval")
|
assertThat(repository).extracting("defaultMaxInactiveInterval")
|
||||||
.isEqualTo(Duration.ofSeconds(MAX_INACTIVE_INTERVAL_IN_SECONDS));
|
.isEqualTo(Duration.ofSeconds(MAX_INACTIVE_INTERVAL_IN_SECONDS));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -117,7 +119,7 @@ class HazelcastHttpSessionConfigurationTests {
|
|||||||
|
|
||||||
HazelcastIndexedSessionRepository repository = this.context.getBean(HazelcastIndexedSessionRepository.class);
|
HazelcastIndexedSessionRepository repository = this.context.getBean(HazelcastIndexedSessionRepository.class);
|
||||||
assertThat(repository).extracting("defaultMaxInactiveInterval")
|
assertThat(repository).extracting("defaultMaxInactiveInterval")
|
||||||
.isEqualTo(Duration.ofSeconds(MAX_INACTIVE_INTERVAL_IN_SECONDS));
|
.isEqualTo(Duration.ofSeconds(MAX_INACTIVE_INTERVAL_IN_SECONDS));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -142,14 +144,14 @@ class HazelcastHttpSessionConfigurationTests {
|
|||||||
void customSaveModeAnnotation() {
|
void customSaveModeAnnotation() {
|
||||||
registerAndRefresh(BaseConfiguration.class, CustomSaveModeExpressionAnnotationConfiguration.class);
|
registerAndRefresh(BaseConfiguration.class, CustomSaveModeExpressionAnnotationConfiguration.class);
|
||||||
assertThat(this.context.getBean(HazelcastIndexedSessionRepository.class))
|
assertThat(this.context.getBean(HazelcastIndexedSessionRepository.class))
|
||||||
.hasFieldOrPropertyWithValue("saveMode", SaveMode.ALWAYS);
|
.hasFieldOrPropertyWithValue("saveMode", SaveMode.ALWAYS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void customSaveModeSetter() {
|
void customSaveModeSetter() {
|
||||||
registerAndRefresh(BaseConfiguration.class, CustomSaveModeExpressionSetterConfiguration.class);
|
registerAndRefresh(BaseConfiguration.class, CustomSaveModeExpressionSetterConfiguration.class);
|
||||||
assertThat(this.context.getBean(HazelcastIndexedSessionRepository.class))
|
assertThat(this.context.getBean(HazelcastIndexedSessionRepository.class))
|
||||||
.hasFieldOrPropertyWithValue("saveMode", SaveMode.ALWAYS);
|
.hasFieldOrPropertyWithValue("saveMode", SaveMode.ALWAYS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -162,7 +164,7 @@ class HazelcastHttpSessionConfigurationTests {
|
|||||||
assertThat(repository).isNotNull();
|
assertThat(repository).isNotNull();
|
||||||
assertThat(hazelcastInstance).isNotNull();
|
assertThat(hazelcastInstance).isNotNull();
|
||||||
assertThat(ReflectionTestUtils.getField(repository, "sessions"))
|
assertThat(ReflectionTestUtils.getField(repository, "sessions"))
|
||||||
.isEqualTo(QualifiedHazelcastInstanceConfiguration.qualifiedHazelcastInstanceSessions);
|
.isEqualTo(QualifiedHazelcastInstanceConfiguration.qualifiedHazelcastInstanceSessions);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -174,7 +176,7 @@ class HazelcastHttpSessionConfigurationTests {
|
|||||||
assertThat(repository).isNotNull();
|
assertThat(repository).isNotNull();
|
||||||
assertThat(hazelcastInstance).isNotNull();
|
assertThat(hazelcastInstance).isNotNull();
|
||||||
assertThat(ReflectionTestUtils.getField(repository, "sessions"))
|
assertThat(ReflectionTestUtils.getField(repository, "sessions"))
|
||||||
.isEqualTo(PrimaryHazelcastInstanceConfiguration.primaryHazelcastInstanceSessions);
|
.isEqualTo(PrimaryHazelcastInstanceConfiguration.primaryHazelcastInstanceSessions);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -187,7 +189,7 @@ class HazelcastHttpSessionConfigurationTests {
|
|||||||
assertThat(repository).isNotNull();
|
assertThat(repository).isNotNull();
|
||||||
assertThat(hazelcastInstance).isNotNull();
|
assertThat(hazelcastInstance).isNotNull();
|
||||||
assertThat(ReflectionTestUtils.getField(repository, "sessions"))
|
assertThat(ReflectionTestUtils.getField(repository, "sessions"))
|
||||||
.isEqualTo(QualifiedAndPrimaryHazelcastInstanceConfiguration.qualifiedHazelcastInstanceSessions);
|
.isEqualTo(QualifiedAndPrimaryHazelcastInstanceConfiguration.qualifiedHazelcastInstanceSessions);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -199,15 +201,16 @@ class HazelcastHttpSessionConfigurationTests {
|
|||||||
assertThat(repository).isNotNull();
|
assertThat(repository).isNotNull();
|
||||||
assertThat(hazelcastInstance).isNotNull();
|
assertThat(hazelcastInstance).isNotNull();
|
||||||
assertThat(ReflectionTestUtils.getField(repository, "sessions"))
|
assertThat(ReflectionTestUtils.getField(repository, "sessions"))
|
||||||
.isEqualTo(NamedHazelcastInstanceConfiguration.hazelcastInstanceSessions);
|
.isEqualTo(NamedHazelcastInstanceConfiguration.hazelcastInstanceSessions);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void multipleHazelcastInstanceConfiguration() {
|
void multipleHazelcastInstanceConfiguration() {
|
||||||
assertThatExceptionOfType(BeanCreationException.class)
|
assertThatExceptionOfType(BeanCreationException.class)
|
||||||
.isThrownBy(() -> registerAndRefresh(MultipleHazelcastInstanceConfiguration.class)).havingRootCause()
|
.isThrownBy(() -> registerAndRefresh(MultipleHazelcastInstanceConfiguration.class))
|
||||||
.isInstanceOf(NoUniqueBeanDefinitionException.class)
|
.havingRootCause()
|
||||||
.withMessageContaining("expected single matching bean but found 2");
|
.isInstanceOf(NoUniqueBeanDefinitionException.class)
|
||||||
|
.withMessageContaining("expected single matching bean but found 2");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -225,16 +228,16 @@ class HazelcastHttpSessionConfigurationTests {
|
|||||||
void sessionRepositoryCustomizer() {
|
void sessionRepositoryCustomizer() {
|
||||||
registerAndRefresh(SessionRepositoryCustomizerConfiguration.class);
|
registerAndRefresh(SessionRepositoryCustomizerConfiguration.class);
|
||||||
HazelcastIndexedSessionRepository sessionRepository = this.context
|
HazelcastIndexedSessionRepository sessionRepository = this.context
|
||||||
.getBean(HazelcastIndexedSessionRepository.class);
|
.getBean(HazelcastIndexedSessionRepository.class);
|
||||||
assertThat(sessionRepository).extracting("defaultMaxInactiveInterval")
|
assertThat(sessionRepository).extracting("defaultMaxInactiveInterval")
|
||||||
.isEqualTo(Duration.ofSeconds(MAX_INACTIVE_INTERVAL_IN_SECONDS));
|
.isEqualTo(Duration.ofSeconds(MAX_INACTIVE_INTERVAL_IN_SECONDS));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void importConfigAndCustomize() {
|
void importConfigAndCustomize() {
|
||||||
registerAndRefresh(ImportConfigAndCustomizeConfiguration.class);
|
registerAndRefresh(ImportConfigAndCustomizeConfiguration.class);
|
||||||
HazelcastIndexedSessionRepository sessionRepository = this.context
|
HazelcastIndexedSessionRepository sessionRepository = this.context
|
||||||
.getBean(HazelcastIndexedSessionRepository.class);
|
.getBean(HazelcastIndexedSessionRepository.class);
|
||||||
assertThat(sessionRepository).extracting("defaultMaxInactiveInterval").isEqualTo(Duration.ZERO);
|
assertThat(sessionRepository).extracting("defaultMaxInactiveInterval").isEqualTo(Duration.ZERO);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -449,7 +452,7 @@ class HazelcastHttpSessionConfigurationTests {
|
|||||||
@Order(1)
|
@Order(1)
|
||||||
SessionRepositoryCustomizer<HazelcastIndexedSessionRepository> sessionRepositoryCustomizerTwo() {
|
SessionRepositoryCustomizer<HazelcastIndexedSessionRepository> sessionRepositoryCustomizerTwo() {
|
||||||
return (sessionRepository) -> sessionRepository
|
return (sessionRepository) -> sessionRepository
|
||||||
.setDefaultMaxInactiveInterval(Duration.ofSeconds(MAX_INACTIVE_INTERVAL_IN_SECONDS));
|
.setDefaultMaxInactiveInterval(Duration.ofSeconds(MAX_INACTIVE_INTERVAL_IN_SECONDS));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -134,7 +134,7 @@ abstract class AbstractJdbcIndexedSessionRepositoryITests {
|
|||||||
assertThat(session.getDelta()).isEmpty();
|
assertThat(session.getDelta()).isEmpty();
|
||||||
assertThat(session.getAttributeNames()).isEqualTo(toSave.getAttributeNames());
|
assertThat(session.getAttributeNames()).isEqualTo(toSave.getAttributeNames());
|
||||||
assertThat(session.<String>getAttribute(expectedAttributeName))
|
assertThat(session.<String>getAttribute(expectedAttributeName))
|
||||||
.isEqualTo(toSave.getAttribute(expectedAttributeName));
|
.isEqualTo(toSave.getAttribute(expectedAttributeName));
|
||||||
|
|
||||||
this.repository.deleteById(toSave.getId());
|
this.repository.deleteById(toSave.getId());
|
||||||
|
|
||||||
@@ -190,7 +190,7 @@ abstract class AbstractJdbcIndexedSessionRepositoryITests {
|
|||||||
assertThat(session.getDelta()).isEmpty();
|
assertThat(session.getDelta()).isEmpty();
|
||||||
assertThat(session.isExpired()).isFalse();
|
assertThat(session.isExpired()).isFalse();
|
||||||
assertThat(session.getLastAccessedTime().truncatedTo(ChronoUnit.MILLIS))
|
assertThat(session.getLastAccessedTime().truncatedTo(ChronoUnit.MILLIS))
|
||||||
.isEqualTo(lastAccessedTime.truncatedTo(ChronoUnit.MILLIS));
|
.isEqualTo(lastAccessedTime.truncatedTo(ChronoUnit.MILLIS));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -816,7 +816,7 @@ abstract class AbstractJdbcIndexedSessionRepositoryITests {
|
|||||||
// with DB specific upsert configured we're fine
|
// with DB specific upsert configured we're fine
|
||||||
assertThatCode(() -> this.repository.save(session)).doesNotThrowAnyException();
|
assertThatCode(() -> this.repository.save(session)).doesNotThrowAnyException();
|
||||||
assertThat((String) this.repository.findById(session.getId()).getAttribute(attributeName))
|
assertThat((String) this.repository.findById(session.getId()).getAttribute(attributeName))
|
||||||
.isEqualTo(attributeValue);
|
.isEqualTo(attributeValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -43,7 +43,8 @@ class DerbyJdbcIndexedSessionRepositoryITests extends AbstractJdbcIndexedSession
|
|||||||
@Bean
|
@Bean
|
||||||
EmbeddedDatabase dataSource() {
|
EmbeddedDatabase dataSource() {
|
||||||
return new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.DERBY)
|
return new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.DERBY)
|
||||||
.addScript("org/springframework/session/jdbc/schema-derby.sql").build();
|
.addScript("org/springframework/session/jdbc/schema-derby.sql")
|
||||||
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,7 +43,8 @@ class H2JdbcIndexedSessionRepositoryITests extends AbstractJdbcIndexedSessionRep
|
|||||||
@Bean
|
@Bean
|
||||||
EmbeddedDatabase dataSource() {
|
EmbeddedDatabase dataSource() {
|
||||||
return new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.H2)
|
return new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.H2)
|
||||||
.addScript("org/springframework/session/jdbc/schema-h2.sql").build();
|
.addScript("org/springframework/session/jdbc/schema-h2.sql")
|
||||||
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,7 +43,8 @@ class HsqldbJdbcIndexedSessionRepositoryITests extends AbstractJdbcIndexedSessio
|
|||||||
@Bean
|
@Bean
|
||||||
EmbeddedDatabase dataSource() {
|
EmbeddedDatabase dataSource() {
|
||||||
return new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.HSQL)
|
return new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.HSQL)
|
||||||
.addScript("org/springframework/session/jdbc/schema-hsqldb.sql").build();
|
.addScript("org/springframework/session/jdbc/schema-hsqldb.sql")
|
||||||
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -499,7 +499,7 @@ public class JdbcIndexedSessionRepository implements
|
|||||||
@Override
|
@Override
|
||||||
public void deleteById(final String id) {
|
public void deleteById(final String id) {
|
||||||
this.transactionOperations.executeWithoutResult((status) -> JdbcIndexedSessionRepository.this.jdbcOperations
|
this.transactionOperations.executeWithoutResult((status) -> JdbcIndexedSessionRepository.this.jdbcOperations
|
||||||
.update(JdbcIndexedSessionRepository.this.deleteSessionQuery, id));
|
.update(JdbcIndexedSessionRepository.this.deleteSessionQuery, id));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -509,9 +509,9 @@ public class JdbcIndexedSessionRepository implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
List<JdbcSession> sessions = this.transactionOperations
|
List<JdbcSession> sessions = this.transactionOperations
|
||||||
.execute((status) -> JdbcIndexedSessionRepository.this.jdbcOperations.query(
|
.execute((status) -> JdbcIndexedSessionRepository.this.jdbcOperations.query(
|
||||||
JdbcIndexedSessionRepository.this.listSessionsByPrincipalNameQuery,
|
JdbcIndexedSessionRepository.this.listSessionsByPrincipalNameQuery,
|
||||||
(ps) -> ps.setString(1, indexValue), JdbcIndexedSessionRepository.this.extractor));
|
(ps) -> ps.setString(1, indexValue), JdbcIndexedSessionRepository.this.extractor));
|
||||||
|
|
||||||
Map<String, JdbcSession> sessionMap = new HashMap<>(sessions.size());
|
Map<String, JdbcSession> sessionMap = new HashMap<>(sessions.size());
|
||||||
|
|
||||||
@@ -641,8 +641,8 @@ public class JdbcIndexedSessionRepository implements
|
|||||||
|
|
||||||
public void cleanUpExpiredSessions() {
|
public void cleanUpExpiredSessions() {
|
||||||
Integer deletedCount = this.transactionOperations
|
Integer deletedCount = this.transactionOperations
|
||||||
.execute((status) -> JdbcIndexedSessionRepository.this.jdbcOperations.update(
|
.execute((status) -> JdbcIndexedSessionRepository.this.jdbcOperations
|
||||||
JdbcIndexedSessionRepository.this.deleteSessionsByExpiryTimeQuery, System.currentTimeMillis()));
|
.update(JdbcIndexedSessionRepository.this.deleteSessionsByExpiryTimeQuery, System.currentTimeMillis()));
|
||||||
|
|
||||||
if (logger.isDebugEnabled()) {
|
if (logger.isDebugEnabled()) {
|
||||||
logger.debug("Cleaned up " + deletedCount + " expired sessions");
|
logger.debug("Cleaned up " + deletedCount + " expired sessions");
|
||||||
@@ -873,17 +873,17 @@ public class JdbcIndexedSessionRepository implements
|
|||||||
if (this.isNew) {
|
if (this.isNew) {
|
||||||
JdbcIndexedSessionRepository.this.transactionOperations.executeWithoutResult((status) -> {
|
JdbcIndexedSessionRepository.this.transactionOperations.executeWithoutResult((status) -> {
|
||||||
Map<String, String> indexes = JdbcIndexedSessionRepository.this.indexResolver
|
Map<String, String> indexes = JdbcIndexedSessionRepository.this.indexResolver
|
||||||
.resolveIndexesFor(JdbcSession.this);
|
.resolveIndexesFor(JdbcSession.this);
|
||||||
JdbcIndexedSessionRepository.this.jdbcOperations
|
JdbcIndexedSessionRepository.this.jdbcOperations
|
||||||
.update(JdbcIndexedSessionRepository.this.createSessionQuery, (ps) -> {
|
.update(JdbcIndexedSessionRepository.this.createSessionQuery, (ps) -> {
|
||||||
ps.setString(1, JdbcSession.this.primaryKey);
|
ps.setString(1, JdbcSession.this.primaryKey);
|
||||||
ps.setString(2, getId());
|
ps.setString(2, getId());
|
||||||
ps.setLong(3, getCreationTime().toEpochMilli());
|
ps.setLong(3, getCreationTime().toEpochMilli());
|
||||||
ps.setLong(4, getLastAccessedTime().toEpochMilli());
|
ps.setLong(4, getLastAccessedTime().toEpochMilli());
|
||||||
ps.setInt(5, (int) getMaxInactiveInterval().getSeconds());
|
ps.setInt(5, (int) getMaxInactiveInterval().getSeconds());
|
||||||
ps.setLong(6, getExpiryTime().toEpochMilli());
|
ps.setLong(6, getExpiryTime().toEpochMilli());
|
||||||
ps.setString(7, indexes.get(PRINCIPAL_NAME_INDEX_NAME));
|
ps.setString(7, indexes.get(PRINCIPAL_NAME_INDEX_NAME));
|
||||||
});
|
});
|
||||||
Set<String> attributeNames = getAttributeNames();
|
Set<String> attributeNames = getAttributeNames();
|
||||||
if (!attributeNames.isEmpty()) {
|
if (!attributeNames.isEmpty()) {
|
||||||
insertSessionAttributes(JdbcSession.this, new ArrayList<>(attributeNames));
|
insertSessionAttributes(JdbcSession.this, new ArrayList<>(attributeNames));
|
||||||
@@ -894,32 +894,38 @@ public class JdbcIndexedSessionRepository implements
|
|||||||
JdbcIndexedSessionRepository.this.transactionOperations.executeWithoutResult((status) -> {
|
JdbcIndexedSessionRepository.this.transactionOperations.executeWithoutResult((status) -> {
|
||||||
if (JdbcSession.this.changed) {
|
if (JdbcSession.this.changed) {
|
||||||
Map<String, String> indexes = JdbcIndexedSessionRepository.this.indexResolver
|
Map<String, String> indexes = JdbcIndexedSessionRepository.this.indexResolver
|
||||||
.resolveIndexesFor(JdbcSession.this);
|
.resolveIndexesFor(JdbcSession.this);
|
||||||
JdbcIndexedSessionRepository.this.jdbcOperations
|
JdbcIndexedSessionRepository.this.jdbcOperations
|
||||||
.update(JdbcIndexedSessionRepository.this.updateSessionQuery, (ps) -> {
|
.update(JdbcIndexedSessionRepository.this.updateSessionQuery, (ps) -> {
|
||||||
ps.setString(1, getId());
|
ps.setString(1, getId());
|
||||||
ps.setLong(2, getLastAccessedTime().toEpochMilli());
|
ps.setLong(2, getLastAccessedTime().toEpochMilli());
|
||||||
ps.setInt(3, (int) getMaxInactiveInterval().getSeconds());
|
ps.setInt(3, (int) getMaxInactiveInterval().getSeconds());
|
||||||
ps.setLong(4, getExpiryTime().toEpochMilli());
|
ps.setLong(4, getExpiryTime().toEpochMilli());
|
||||||
ps.setString(5, indexes.get(PRINCIPAL_NAME_INDEX_NAME));
|
ps.setString(5, indexes.get(PRINCIPAL_NAME_INDEX_NAME));
|
||||||
ps.setString(6, JdbcSession.this.primaryKey);
|
ps.setString(6, JdbcSession.this.primaryKey);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
List<String> addedAttributeNames = JdbcSession.this.delta.entrySet().stream()
|
List<String> addedAttributeNames = JdbcSession.this.delta.entrySet()
|
||||||
.filter((entry) -> entry.getValue() == DeltaValue.ADDED).map(Map.Entry::getKey)
|
.stream()
|
||||||
.collect(Collectors.toList());
|
.filter((entry) -> entry.getValue() == DeltaValue.ADDED)
|
||||||
|
.map(Map.Entry::getKey)
|
||||||
|
.collect(Collectors.toList());
|
||||||
if (!addedAttributeNames.isEmpty()) {
|
if (!addedAttributeNames.isEmpty()) {
|
||||||
insertSessionAttributes(JdbcSession.this, addedAttributeNames);
|
insertSessionAttributes(JdbcSession.this, addedAttributeNames);
|
||||||
}
|
}
|
||||||
List<String> updatedAttributeNames = JdbcSession.this.delta.entrySet().stream()
|
List<String> updatedAttributeNames = JdbcSession.this.delta.entrySet()
|
||||||
.filter((entry) -> entry.getValue() == DeltaValue.UPDATED).map(Map.Entry::getKey)
|
.stream()
|
||||||
.collect(Collectors.toList());
|
.filter((entry) -> entry.getValue() == DeltaValue.UPDATED)
|
||||||
|
.map(Map.Entry::getKey)
|
||||||
|
.collect(Collectors.toList());
|
||||||
if (!updatedAttributeNames.isEmpty()) {
|
if (!updatedAttributeNames.isEmpty()) {
|
||||||
updateSessionAttributes(JdbcSession.this, updatedAttributeNames);
|
updateSessionAttributes(JdbcSession.this, updatedAttributeNames);
|
||||||
}
|
}
|
||||||
List<String> removedAttributeNames = JdbcSession.this.delta.entrySet().stream()
|
List<String> removedAttributeNames = JdbcSession.this.delta.entrySet()
|
||||||
.filter((entry) -> entry.getValue() == DeltaValue.REMOVED).map(Map.Entry::getKey)
|
.stream()
|
||||||
.collect(Collectors.toList());
|
.filter((entry) -> entry.getValue() == DeltaValue.REMOVED)
|
||||||
|
.map(Map.Entry::getKey)
|
||||||
|
.collect(Collectors.toList());
|
||||||
if (!removedAttributeNames.isEmpty()) {
|
if (!removedAttributeNames.isEmpty()) {
|
||||||
deleteSessionAttributes(JdbcSession.this, removedAttributeNames);
|
deleteSessionAttributes(JdbcSession.this, removedAttributeNames);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,28 +30,30 @@ class SessionJdbcRuntimeHints implements RuntimeHintsRegistrar {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
|
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
|
||||||
hints.reflection().registerType(TypeReference.of("javax.sql.DataSource"),
|
hints.reflection()
|
||||||
(hint) -> hint.withMembers(MemberCategory.INVOKE_DECLARED_METHODS));
|
.registerType(TypeReference.of("javax.sql.DataSource"),
|
||||||
hints.resources().registerPattern("org/springframework/session/jdbc/schema-db2.sql")
|
(hint) -> hint.withMembers(MemberCategory.INVOKE_DECLARED_METHODS));
|
||||||
.registerPattern("org/springframework/session/jdbc/schema-derby.sql")
|
hints.resources()
|
||||||
.registerPattern("org/springframework/session/jdbc/schema-drop-db2.sql")
|
.registerPattern("org/springframework/session/jdbc/schema-db2.sql")
|
||||||
.registerPattern("org/springframework/session/jdbc/schema-drop-derby.sql")
|
.registerPattern("org/springframework/session/jdbc/schema-derby.sql")
|
||||||
.registerPattern("org/springframework/session/jdbc/schema-drop-h2.sql")
|
.registerPattern("org/springframework/session/jdbc/schema-drop-db2.sql")
|
||||||
.registerPattern("org/springframework/session/jdbc/schema-drop-hsqldb.sql")
|
.registerPattern("org/springframework/session/jdbc/schema-drop-derby.sql")
|
||||||
.registerPattern("org/springframework/session/jdbc/schema-drop-mysql.sql")
|
.registerPattern("org/springframework/session/jdbc/schema-drop-h2.sql")
|
||||||
.registerPattern("org/springframework/session/jdbc/schema-drop-oracle.sql")
|
.registerPattern("org/springframework/session/jdbc/schema-drop-hsqldb.sql")
|
||||||
.registerPattern("org/springframework/session/jdbc/schema-drop-postgresql.sql")
|
.registerPattern("org/springframework/session/jdbc/schema-drop-mysql.sql")
|
||||||
.registerPattern("org/springframework/session/jdbc/schema-drop-sqlite.sql")
|
.registerPattern("org/springframework/session/jdbc/schema-drop-oracle.sql")
|
||||||
.registerPattern("org/springframework/session/jdbc/schema-drop-sqlserver.sql")
|
.registerPattern("org/springframework/session/jdbc/schema-drop-postgresql.sql")
|
||||||
.registerPattern("org/springframework/session/jdbc/schema-drop-sybase.sql")
|
.registerPattern("org/springframework/session/jdbc/schema-drop-sqlite.sql")
|
||||||
.registerPattern("org/springframework/session/jdbc/schema-h2.sql")
|
.registerPattern("org/springframework/session/jdbc/schema-drop-sqlserver.sql")
|
||||||
.registerPattern("org/springframework/session/jdbc/schema-hsqldb.sql")
|
.registerPattern("org/springframework/session/jdbc/schema-drop-sybase.sql")
|
||||||
.registerPattern("org/springframework/session/jdbc/schema-mysql.sql")
|
.registerPattern("org/springframework/session/jdbc/schema-h2.sql")
|
||||||
.registerPattern("org/springframework/session/jdbc/schema-oracle.sql")
|
.registerPattern("org/springframework/session/jdbc/schema-hsqldb.sql")
|
||||||
.registerPattern("org/springframework/session/jdbc/schema-postgresql.sql")
|
.registerPattern("org/springframework/session/jdbc/schema-mysql.sql")
|
||||||
.registerPattern("org/springframework/session/jdbc/schema-sqlite.sql")
|
.registerPattern("org/springframework/session/jdbc/schema-oracle.sql")
|
||||||
.registerPattern("org/springframework/session/jdbc/schema-sqlserver.sql")
|
.registerPattern("org/springframework/session/jdbc/schema-postgresql.sql")
|
||||||
.registerPattern("org/springframework/session/jdbc/schema-sybase.sql");
|
.registerPattern("org/springframework/session/jdbc/schema-sqlite.sql")
|
||||||
|
.registerPattern("org/springframework/session/jdbc/schema-sqlserver.sql")
|
||||||
|
.registerPattern("org/springframework/session/jdbc/schema-sybase.sql");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -145,7 +145,7 @@ public class JdbcHttpSessionConfiguration implements BeanClassLoaderAware, Embed
|
|||||||
sessionRepository.setConversionService(createConversionServiceWithBeanClassLoader(this.classLoader));
|
sessionRepository.setConversionService(createConversionServiceWithBeanClassLoader(this.classLoader));
|
||||||
}
|
}
|
||||||
this.sessionRepositoryCustomizers
|
this.sessionRepositoryCustomizers
|
||||||
.forEach((sessionRepositoryCustomizer) -> sessionRepositoryCustomizer.customize(sessionRepository));
|
.forEach((sessionRepositoryCustomizer) -> sessionRepositoryCustomizer.customize(sessionRepository));
|
||||||
return sessionRepository;
|
return sessionRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -248,7 +248,7 @@ public class JdbcHttpSessionConfiguration implements BeanClassLoaderAware, Embed
|
|||||||
@Override
|
@Override
|
||||||
public void setImportMetadata(AnnotationMetadata importMetadata) {
|
public void setImportMetadata(AnnotationMetadata importMetadata) {
|
||||||
Map<String, Object> attributeMap = importMetadata
|
Map<String, Object> attributeMap = importMetadata
|
||||||
.getAnnotationAttributes(EnableJdbcHttpSession.class.getName());
|
.getAnnotationAttributes(EnableJdbcHttpSession.class.getName());
|
||||||
AnnotationAttributes attributes = AnnotationAttributes.fromMap(attributeMap);
|
AnnotationAttributes attributes = AnnotationAttributes.fromMap(attributeMap);
|
||||||
if (attributes == null) {
|
if (attributes == null) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -89,171 +89,171 @@ class JdbcIndexedSessionRepositoryTests {
|
|||||||
@Test
|
@Test
|
||||||
void constructorNullJdbcOperations() {
|
void constructorNullJdbcOperations() {
|
||||||
assertThatIllegalArgumentException()
|
assertThatIllegalArgumentException()
|
||||||
.isThrownBy(() -> new JdbcIndexedSessionRepository(null, TransactionOperations.withoutTransaction()))
|
.isThrownBy(() -> new JdbcIndexedSessionRepository(null, TransactionOperations.withoutTransaction()))
|
||||||
.withMessage("jdbcOperations must not be null");
|
.withMessage("jdbcOperations must not be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void constructorNullTransactionOperations() {
|
void constructorNullTransactionOperations() {
|
||||||
assertThatIllegalArgumentException()
|
assertThatIllegalArgumentException()
|
||||||
.isThrownBy(() -> new JdbcIndexedSessionRepository(this.jdbcOperations, null))
|
.isThrownBy(() -> new JdbcIndexedSessionRepository(this.jdbcOperations, null))
|
||||||
.withMessage("transactionOperations must not be null");
|
.withMessage("transactionOperations must not be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void setTableNameNull() {
|
void setTableNameNull() {
|
||||||
assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setTableName(null))
|
assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setTableName(null))
|
||||||
.withMessage("Table name must not be empty");
|
.withMessage("Table name must not be empty");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void setTableNameEmpty() {
|
void setTableNameEmpty() {
|
||||||
assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setTableName(" "))
|
assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setTableName(" "))
|
||||||
.withMessage("Table name must not be empty");
|
.withMessage("Table name must not be empty");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void setCreateSessionQueryNull() {
|
void setCreateSessionQueryNull() {
|
||||||
assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setCreateSessionQuery(null))
|
assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setCreateSessionQuery(null))
|
||||||
.withMessage("Query must not be empty");
|
.withMessage("Query must not be empty");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void setCreateSessionQueryEmpty() {
|
void setCreateSessionQueryEmpty() {
|
||||||
assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setCreateSessionQuery(" "))
|
assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setCreateSessionQuery(" "))
|
||||||
.withMessage("Query must not be empty");
|
.withMessage("Query must not be empty");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void setCreateSessionAttributeQueryNull() {
|
void setCreateSessionAttributeQueryNull() {
|
||||||
assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setCreateSessionAttributeQuery(null))
|
assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setCreateSessionAttributeQuery(null))
|
||||||
.withMessage("Query must not be empty");
|
.withMessage("Query must not be empty");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void setCreateSessionAttributeQueryEmpty() {
|
void setCreateSessionAttributeQueryEmpty() {
|
||||||
assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setCreateSessionAttributeQuery(" "))
|
assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setCreateSessionAttributeQuery(" "))
|
||||||
.withMessage("Query must not be empty");
|
.withMessage("Query must not be empty");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void setGetSessionQueryNull() {
|
void setGetSessionQueryNull() {
|
||||||
assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setGetSessionQuery(null))
|
assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setGetSessionQuery(null))
|
||||||
.withMessage("Query must not be empty");
|
.withMessage("Query must not be empty");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void setGetSessionQueryEmpty() {
|
void setGetSessionQueryEmpty() {
|
||||||
assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setGetSessionQuery(" "))
|
assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setGetSessionQuery(" "))
|
||||||
.withMessage("Query must not be empty");
|
.withMessage("Query must not be empty");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void setUpdateSessionQueryNull() {
|
void setUpdateSessionQueryNull() {
|
||||||
assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setUpdateSessionQuery(null))
|
assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setUpdateSessionQuery(null))
|
||||||
.withMessage("Query must not be empty");
|
.withMessage("Query must not be empty");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void setUpdateSessionQueryEmpty() {
|
void setUpdateSessionQueryEmpty() {
|
||||||
assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setUpdateSessionQuery(" "))
|
assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setUpdateSessionQuery(" "))
|
||||||
.withMessage("Query must not be empty");
|
.withMessage("Query must not be empty");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void setUpdateSessionAttributeQueryNull() {
|
void setUpdateSessionAttributeQueryNull() {
|
||||||
assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setUpdateSessionAttributeQuery(null))
|
assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setUpdateSessionAttributeQuery(null))
|
||||||
.withMessage("Query must not be empty");
|
.withMessage("Query must not be empty");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void setUpdateSessionAttributeQueryEmpty() {
|
void setUpdateSessionAttributeQueryEmpty() {
|
||||||
assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setUpdateSessionAttributeQuery(" "))
|
assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setUpdateSessionAttributeQuery(" "))
|
||||||
.withMessage("Query must not be empty");
|
.withMessage("Query must not be empty");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void setDeleteSessionAttributeQueryNull() {
|
void setDeleteSessionAttributeQueryNull() {
|
||||||
assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setDeleteSessionAttributeQuery(null))
|
assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setDeleteSessionAttributeQuery(null))
|
||||||
.withMessage("Query must not be empty");
|
.withMessage("Query must not be empty");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void setDeleteSessionAttributeQueryEmpty() {
|
void setDeleteSessionAttributeQueryEmpty() {
|
||||||
assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setDeleteSessionAttributeQuery(" "))
|
assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setDeleteSessionAttributeQuery(" "))
|
||||||
.withMessage("Query must not be empty");
|
.withMessage("Query must not be empty");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void setDeleteSessionQueryNull() {
|
void setDeleteSessionQueryNull() {
|
||||||
assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setDeleteSessionQuery(null))
|
assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setDeleteSessionQuery(null))
|
||||||
.withMessage("Query must not be empty");
|
.withMessage("Query must not be empty");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void setDeleteSessionQueryEmpty() {
|
void setDeleteSessionQueryEmpty() {
|
||||||
assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setDeleteSessionQuery(" "))
|
assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setDeleteSessionQuery(" "))
|
||||||
.withMessage("Query must not be empty");
|
.withMessage("Query must not be empty");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void setListSessionsByPrincipalNameQueryNull() {
|
void setListSessionsByPrincipalNameQueryNull() {
|
||||||
assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setListSessionsByPrincipalNameQuery(null))
|
assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setListSessionsByPrincipalNameQuery(null))
|
||||||
.withMessage("Query must not be empty");
|
.withMessage("Query must not be empty");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void setListSessionsByPrincipalNameQueryEmpty() {
|
void setListSessionsByPrincipalNameQueryEmpty() {
|
||||||
assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setListSessionsByPrincipalNameQuery(" "))
|
assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setListSessionsByPrincipalNameQuery(" "))
|
||||||
.withMessage("Query must not be empty");
|
.withMessage("Query must not be empty");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void setDeleteSessionsByLastAccessTimeQueryNull() {
|
void setDeleteSessionsByLastAccessTimeQueryNull() {
|
||||||
assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setDeleteSessionsByExpiryTimeQuery(null))
|
assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setDeleteSessionsByExpiryTimeQuery(null))
|
||||||
.withMessage("Query must not be empty");
|
.withMessage("Query must not be empty");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void setDeleteSessionsByLastAccessTimeQueryEmpty() {
|
void setDeleteSessionsByLastAccessTimeQueryEmpty() {
|
||||||
assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setDeleteSessionsByExpiryTimeQuery(" "))
|
assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setDeleteSessionsByExpiryTimeQuery(" "))
|
||||||
.withMessage("Query must not be empty");
|
.withMessage("Query must not be empty");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void setLobHandlerNull() {
|
void setLobHandlerNull() {
|
||||||
assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setLobHandler(null))
|
assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setLobHandler(null))
|
||||||
.withMessage("LobHandler must not be null");
|
.withMessage("LobHandler must not be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void setConversionServiceNull() {
|
void setConversionServiceNull() {
|
||||||
assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setConversionService(null))
|
assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setConversionService(null))
|
||||||
.withMessage("conversionService must not be null");
|
.withMessage("conversionService must not be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void setFlushModeNull() {
|
void setFlushModeNull() {
|
||||||
assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setFlushMode(null))
|
assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setFlushMode(null))
|
||||||
.withMessage("flushMode must not be null");
|
.withMessage("flushMode must not be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void setSaveModeNull() {
|
void setSaveModeNull() {
|
||||||
assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setSaveMode(null))
|
assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setSaveMode(null))
|
||||||
.withMessage("saveMode must not be null");
|
.withMessage("saveMode must not be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void setCleanupCronNull() {
|
void setCleanupCronNull() {
|
||||||
assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setCleanupCron(null))
|
assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setCleanupCron(null))
|
||||||
.withMessage("cleanupCron must not be null");
|
.withMessage("cleanupCron must not be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void setCleanupCronInvalid() {
|
void setCleanupCronInvalid() {
|
||||||
assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setCleanupCron("test"))
|
assertThatIllegalArgumentException().isThrownBy(() -> this.repository.setCleanupCron("test"))
|
||||||
.withMessage("cleanupCron must be valid");
|
.withMessage("cleanupCron must be valid");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -523,7 +523,8 @@ class JdbcIndexedSessionRepositoryTests {
|
|||||||
void getSessionNotFound() {
|
void getSessionNotFound() {
|
||||||
String sessionId = "testSessionId";
|
String sessionId = "testSessionId";
|
||||||
given(this.jdbcOperations.query(isA(String.class), isA(PreparedStatementSetter.class),
|
given(this.jdbcOperations.query(isA(String.class), isA(PreparedStatementSetter.class),
|
||||||
isA(ResultSetExtractor.class))).willReturn(Collections.emptyList());
|
isA(ResultSetExtractor.class)))
|
||||||
|
.willReturn(Collections.emptyList());
|
||||||
|
|
||||||
JdbcSession session = this.repository.findById(sessionId);
|
JdbcSession session = this.repository.findById(sessionId);
|
||||||
|
|
||||||
@@ -538,7 +539,8 @@ class JdbcIndexedSessionRepositoryTests {
|
|||||||
Session expired = this.repository.createSession();
|
Session expired = this.repository.createSession();
|
||||||
expired.setLastAccessedTime(Instant.now().minusSeconds(MapSession.DEFAULT_MAX_INACTIVE_INTERVAL_SECONDS + 1));
|
expired.setLastAccessedTime(Instant.now().minusSeconds(MapSession.DEFAULT_MAX_INACTIVE_INTERVAL_SECONDS + 1));
|
||||||
given(this.jdbcOperations.query(isA(String.class), isA(PreparedStatementSetter.class),
|
given(this.jdbcOperations.query(isA(String.class), isA(PreparedStatementSetter.class),
|
||||||
isA(ResultSetExtractor.class))).willReturn(Collections.singletonList(expired));
|
isA(ResultSetExtractor.class)))
|
||||||
|
.willReturn(Collections.singletonList(expired));
|
||||||
|
|
||||||
JdbcSession session = this.repository.findById(expired.getId());
|
JdbcSession session = this.repository.findById(expired.getId());
|
||||||
|
|
||||||
@@ -554,7 +556,8 @@ class JdbcIndexedSessionRepositoryTests {
|
|||||||
Session saved = this.repository.new JdbcSession(new MapSession(), "primaryKey", false);
|
Session saved = this.repository.new JdbcSession(new MapSession(), "primaryKey", false);
|
||||||
saved.setAttribute("savedName", "savedValue");
|
saved.setAttribute("savedName", "savedValue");
|
||||||
given(this.jdbcOperations.query(isA(String.class), isA(PreparedStatementSetter.class),
|
given(this.jdbcOperations.query(isA(String.class), isA(PreparedStatementSetter.class),
|
||||||
isA(ResultSetExtractor.class))).willReturn(Collections.singletonList(saved));
|
isA(ResultSetExtractor.class)))
|
||||||
|
.willReturn(Collections.singletonList(saved));
|
||||||
|
|
||||||
JdbcSession session = this.repository.findById(saved.getId());
|
JdbcSession session = this.repository.findById(saved.getId());
|
||||||
|
|
||||||
@@ -589,10 +592,11 @@ class JdbcIndexedSessionRepositoryTests {
|
|||||||
void findByIndexNameAndIndexValuePrincipalIndexNameNotFound() {
|
void findByIndexNameAndIndexValuePrincipalIndexNameNotFound() {
|
||||||
String principal = "username";
|
String principal = "username";
|
||||||
given(this.jdbcOperations.query(isA(String.class), isA(PreparedStatementSetter.class),
|
given(this.jdbcOperations.query(isA(String.class), isA(PreparedStatementSetter.class),
|
||||||
isA(ResultSetExtractor.class))).willReturn(Collections.emptyList());
|
isA(ResultSetExtractor.class)))
|
||||||
|
.willReturn(Collections.emptyList());
|
||||||
|
|
||||||
Map<String, JdbcSession> sessions = this.repository
|
Map<String, JdbcSession> sessions = this.repository
|
||||||
.findByIndexNameAndIndexValue(FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME, principal);
|
.findByIndexNameAndIndexValue(FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME, principal);
|
||||||
|
|
||||||
assertThat(sessions).isEmpty();
|
assertThat(sessions).isEmpty();
|
||||||
verify(this.jdbcOperations, times(1)).query(isA(String.class), isA(PreparedStatementSetter.class),
|
verify(this.jdbcOperations, times(1)).query(isA(String.class), isA(PreparedStatementSetter.class),
|
||||||
@@ -613,10 +617,11 @@ class JdbcIndexedSessionRepositoryTests {
|
|||||||
saved2.setAttribute(SPRING_SECURITY_CONTEXT, authentication);
|
saved2.setAttribute(SPRING_SECURITY_CONTEXT, authentication);
|
||||||
saved.add(saved2);
|
saved.add(saved2);
|
||||||
given(this.jdbcOperations.query(isA(String.class), isA(PreparedStatementSetter.class),
|
given(this.jdbcOperations.query(isA(String.class), isA(PreparedStatementSetter.class),
|
||||||
isA(ResultSetExtractor.class))).willReturn(saved);
|
isA(ResultSetExtractor.class)))
|
||||||
|
.willReturn(saved);
|
||||||
|
|
||||||
Map<String, JdbcSession> sessions = this.repository
|
Map<String, JdbcSession> sessions = this.repository
|
||||||
.findByIndexNameAndIndexValue(FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME, principal);
|
.findByIndexNameAndIndexValue(FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME, principal);
|
||||||
|
|
||||||
assertThat(sessions).hasSize(2);
|
assertThat(sessions).hasSize(2);
|
||||||
verify(this.jdbcOperations, times(1)).query(isA(String.class), isA(PreparedStatementSetter.class),
|
verify(this.jdbcOperations, times(1)).query(isA(String.class), isA(PreparedStatementSetter.class),
|
||||||
@@ -671,7 +676,7 @@ class JdbcIndexedSessionRepositoryTests {
|
|||||||
session.setAttribute("attribute3", "value4");
|
session.setAttribute("attribute3", "value4");
|
||||||
this.repository.save(session);
|
this.repository.save(session);
|
||||||
ArgumentCaptor<BatchPreparedStatementSetter> captor = ArgumentCaptor
|
ArgumentCaptor<BatchPreparedStatementSetter> captor = ArgumentCaptor
|
||||||
.forClass(BatchPreparedStatementSetter.class);
|
.forClass(BatchPreparedStatementSetter.class);
|
||||||
verify(this.jdbcOperations).batchUpdate(matches("^UPDATE SPRING_SESSION_ATTRIBUTES\\s*SET.*"),
|
verify(this.jdbcOperations).batchUpdate(matches("^UPDATE SPRING_SESSION_ATTRIBUTES\\s*SET.*"),
|
||||||
captor.capture());
|
captor.capture());
|
||||||
assertThat(captor.getValue().getBatchSize()).isEqualTo(2);
|
assertThat(captor.getValue().getBatchSize()).isEqualTo(2);
|
||||||
@@ -704,7 +709,7 @@ class JdbcIndexedSessionRepositoryTests {
|
|||||||
session.setAttribute("attribute3", "value4");
|
session.setAttribute("attribute3", "value4");
|
||||||
this.repository.save(session);
|
this.repository.save(session);
|
||||||
ArgumentCaptor<BatchPreparedStatementSetter> captor = ArgumentCaptor
|
ArgumentCaptor<BatchPreparedStatementSetter> captor = ArgumentCaptor
|
||||||
.forClass(BatchPreparedStatementSetter.class);
|
.forClass(BatchPreparedStatementSetter.class);
|
||||||
verify(this.jdbcOperations).batchUpdate(matches("^UPDATE SPRING_SESSION_ATTRIBUTES\\s*SET.*"),
|
verify(this.jdbcOperations).batchUpdate(matches("^UPDATE SPRING_SESSION_ATTRIBUTES\\s*SET.*"),
|
||||||
captor.capture());
|
captor.capture());
|
||||||
assertThat(captor.getValue().getBatchSize()).isEqualTo(3);
|
assertThat(captor.getValue().getBatchSize()).isEqualTo(3);
|
||||||
|
|||||||
@@ -48,8 +48,9 @@ class SessionJdbcRuntimeHintsTests {
|
|||||||
@Test
|
@Test
|
||||||
void aotFactoriesContainsRegistrar() {
|
void aotFactoriesContainsRegistrar() {
|
||||||
boolean match = SpringFactoriesLoader.forResourceLocation("META-INF/spring/aot.factories")
|
boolean match = SpringFactoriesLoader.forResourceLocation("META-INF/spring/aot.factories")
|
||||||
.load(RuntimeHintsRegistrar.class).stream()
|
.load(RuntimeHintsRegistrar.class)
|
||||||
.anyMatch((registrar) -> registrar instanceof SessionJdbcRuntimeHints);
|
.stream()
|
||||||
|
.anyMatch((registrar) -> registrar instanceof SessionJdbcRuntimeHints);
|
||||||
assertThat(match).isTrue();
|
assertThat(match).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,21 +59,21 @@ class SessionJdbcRuntimeHintsTests {
|
|||||||
void jdbcSchemasHasHints(String schemaFileName) {
|
void jdbcSchemasHasHints(String schemaFileName) {
|
||||||
this.sessionJdbcRuntimeHints.registerHints(this.hints, getClass().getClassLoader());
|
this.sessionJdbcRuntimeHints.registerHints(this.hints, getClass().getClassLoader());
|
||||||
assertThat(RuntimeHintsPredicates.resource().forResource("org/springframework/session/jdbc/" + schemaFileName))
|
assertThat(RuntimeHintsPredicates.resource().forResource("org/springframework/session/jdbc/" + schemaFileName))
|
||||||
.accepts(this.hints);
|
.accepts(this.hints);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Stream<String> getSchemaFileNames() throws IOException {
|
private static Stream<String> getSchemaFileNames() throws IOException {
|
||||||
return Arrays
|
return Arrays
|
||||||
.stream(new PathMatchingResourcePatternResolver()
|
.stream(new PathMatchingResourcePatternResolver()
|
||||||
.getResources("classpath*:org/springframework/session/jdbc/schema-*.sql"))
|
.getResources("classpath*:org/springframework/session/jdbc/schema-*.sql"))
|
||||||
.map(Resource::getFilename);
|
.map(Resource::getFilename);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void dataSourceHasHints() {
|
void dataSourceHasHints() {
|
||||||
this.sessionJdbcRuntimeHints.registerHints(this.hints, getClass().getClassLoader());
|
this.sessionJdbcRuntimeHints.registerHints(this.hints, getClass().getClassLoader());
|
||||||
assertThat(RuntimeHintsPredicates.reflection().onType(TypeReference.of("javax.sql.DataSource")))
|
assertThat(RuntimeHintsPredicates.reflection().onType(TypeReference.of("javax.sql.DataSource")))
|
||||||
.accepts(this.hints);
|
.accepts(this.hints);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -81,9 +81,10 @@ class JdbcHttpSessionConfigurationTests {
|
|||||||
@Test
|
@Test
|
||||||
void noDataSourceConfiguration() {
|
void noDataSourceConfiguration() {
|
||||||
assertThatExceptionOfType(BeanCreationException.class)
|
assertThatExceptionOfType(BeanCreationException.class)
|
||||||
.isThrownBy(() -> registerAndRefresh(NoDataSourceConfiguration.class))
|
.isThrownBy(() -> registerAndRefresh(NoDataSourceConfiguration.class))
|
||||||
.withRootCauseInstanceOf(NoSuchBeanDefinitionException.class).havingRootCause()
|
.withRootCauseInstanceOf(NoSuchBeanDefinitionException.class)
|
||||||
.withMessageContaining("expected at least 1 bean which qualifies as autowire candidate");
|
.havingRootCause()
|
||||||
|
.withMessageContaining("expected at least 1 bean which qualifies as autowire candidate");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -93,7 +94,7 @@ class JdbcHttpSessionConfigurationTests {
|
|||||||
JdbcIndexedSessionRepository sessionRepository = this.context.getBean(JdbcIndexedSessionRepository.class);
|
JdbcIndexedSessionRepository sessionRepository = this.context.getBean(JdbcIndexedSessionRepository.class);
|
||||||
assertThat(sessionRepository).isNotNull();
|
assertThat(sessionRepository).isNotNull();
|
||||||
assertThat(sessionRepository).extracting("transactionOperations")
|
assertThat(sessionRepository).extracting("transactionOperations")
|
||||||
.hasFieldOrPropertyWithValue("propagationBehavior", TransactionDefinition.PROPAGATION_REQUIRES_NEW);
|
.hasFieldOrPropertyWithValue("propagationBehavior", TransactionDefinition.PROPAGATION_REQUIRES_NEW);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -121,7 +122,7 @@ class JdbcHttpSessionConfigurationTests {
|
|||||||
|
|
||||||
JdbcIndexedSessionRepository repository = this.context.getBean(JdbcIndexedSessionRepository.class);
|
JdbcIndexedSessionRepository repository = this.context.getBean(JdbcIndexedSessionRepository.class);
|
||||||
assertThat(repository).extracting("defaultMaxInactiveInterval")
|
assertThat(repository).extracting("defaultMaxInactiveInterval")
|
||||||
.isEqualTo(Duration.ofSeconds(MAX_INACTIVE_INTERVAL_IN_SECONDS));
|
.isEqualTo(Duration.ofSeconds(MAX_INACTIVE_INTERVAL_IN_SECONDS));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -130,7 +131,7 @@ class JdbcHttpSessionConfigurationTests {
|
|||||||
|
|
||||||
JdbcIndexedSessionRepository repository = this.context.getBean(JdbcIndexedSessionRepository.class);
|
JdbcIndexedSessionRepository repository = this.context.getBean(JdbcIndexedSessionRepository.class);
|
||||||
assertThat(repository).extracting("defaultMaxInactiveInterval")
|
assertThat(repository).extracting("defaultMaxInactiveInterval")
|
||||||
.isEqualTo(Duration.ofSeconds(MAX_INACTIVE_INTERVAL_IN_SECONDS));
|
.isEqualTo(Duration.ofSeconds(MAX_INACTIVE_INTERVAL_IN_SECONDS));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -232,10 +233,10 @@ class JdbcHttpSessionConfigurationTests {
|
|||||||
@Test
|
@Test
|
||||||
void multipleDataSourceConfiguration() {
|
void multipleDataSourceConfiguration() {
|
||||||
assertThatExceptionOfType(BeanCreationException.class)
|
assertThatExceptionOfType(BeanCreationException.class)
|
||||||
.isThrownBy(
|
.isThrownBy(() -> registerAndRefresh(DataSourceConfiguration.class, MultipleDataSourceConfiguration.class))
|
||||||
() -> registerAndRefresh(DataSourceConfiguration.class, MultipleDataSourceConfiguration.class))
|
.withRootCauseInstanceOf(NoUniqueBeanDefinitionException.class)
|
||||||
.withRootCauseInstanceOf(NoUniqueBeanDefinitionException.class).havingRootCause()
|
.havingRootCause()
|
||||||
.withMessageContaining("expected single matching bean but found 2");
|
.withMessageContaining("expected single matching bean but found 2");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -287,7 +288,7 @@ class JdbcHttpSessionConfigurationTests {
|
|||||||
@Test
|
@Test
|
||||||
void resolveTableNameByPropertyPlaceholder() {
|
void resolveTableNameByPropertyPlaceholder() {
|
||||||
this.context
|
this.context
|
||||||
.setEnvironment(new MockEnvironment().withProperty("session.jdbc.tableName", "custom_session_table"));
|
.setEnvironment(new MockEnvironment().withProperty("session.jdbc.tableName", "custom_session_table"));
|
||||||
registerAndRefresh(DataSourceConfiguration.class, CustomJdbcHttpSessionConfiguration.class);
|
registerAndRefresh(DataSourceConfiguration.class, CustomJdbcHttpSessionConfiguration.class);
|
||||||
JdbcHttpSessionConfiguration configuration = this.context.getBean(JdbcHttpSessionConfiguration.class);
|
JdbcHttpSessionConfiguration configuration = this.context.getBean(JdbcHttpSessionConfiguration.class);
|
||||||
assertThat(ReflectionTestUtils.getField(configuration, "tableName")).isEqualTo("custom_session_table");
|
assertThat(ReflectionTestUtils.getField(configuration, "tableName")).isEqualTo("custom_session_table");
|
||||||
@@ -298,7 +299,7 @@ class JdbcHttpSessionConfigurationTests {
|
|||||||
registerAndRefresh(DataSourceConfiguration.class, SessionRepositoryCustomizerConfiguration.class);
|
registerAndRefresh(DataSourceConfiguration.class, SessionRepositoryCustomizerConfiguration.class);
|
||||||
JdbcIndexedSessionRepository sessionRepository = this.context.getBean(JdbcIndexedSessionRepository.class);
|
JdbcIndexedSessionRepository sessionRepository = this.context.getBean(JdbcIndexedSessionRepository.class);
|
||||||
assertThat(sessionRepository).extracting("defaultMaxInactiveInterval")
|
assertThat(sessionRepository).extracting("defaultMaxInactiveInterval")
|
||||||
.isEqualTo(Duration.ofSeconds(MAX_INACTIVE_INTERVAL_IN_SECONDS));
|
.isEqualTo(Duration.ofSeconds(MAX_INACTIVE_INTERVAL_IN_SECONDS));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -559,7 +560,7 @@ class JdbcHttpSessionConfigurationTests {
|
|||||||
@Order(1)
|
@Order(1)
|
||||||
SessionRepositoryCustomizer<JdbcIndexedSessionRepository> sessionRepositoryCustomizerTwo() {
|
SessionRepositoryCustomizer<JdbcIndexedSessionRepository> sessionRepositoryCustomizerTwo() {
|
||||||
return (sessionRepository) -> sessionRepository
|
return (sessionRepository) -> sessionRepository
|
||||||
.setDefaultMaxInactiveInterval(Duration.ofSeconds(MAX_INACTIVE_INTERVAL_IN_SECONDS));
|
.setDefaultMaxInactiveInterval(Duration.ofSeconds(MAX_INACTIVE_INTERVAL_IN_SECONDS));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ class JdbcSchemaUtilsTests {
|
|||||||
|
|
||||||
private static Stream<Resource> getSchemaFiles() throws IOException {
|
private static Stream<Resource> getSchemaFiles() throws IOException {
|
||||||
return Arrays.stream(new PathMatchingResourcePatternResolver()
|
return Arrays.stream(new PathMatchingResourcePatternResolver()
|
||||||
.getResources("classpath*:org/springframework/session/jdbc/schema-*.sql"));
|
.getResources("classpath*:org/springframework/session/jdbc/schema-*.sql"));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,11 +41,12 @@ public class SessionConfig {
|
|||||||
networkConfig.setPort(0);
|
networkConfig.setPort(0);
|
||||||
networkConfig.getJoin().getAutoDetectionConfig().setEnabled(false);
|
networkConfig.getJoin().getAutoDetectionConfig().setEnabled(false);
|
||||||
AttributeConfig attributeConfig = new AttributeConfig()
|
AttributeConfig attributeConfig = new AttributeConfig()
|
||||||
.setName(HazelcastIndexedSessionRepository.PRINCIPAL_NAME_ATTRIBUTE)
|
.setName(HazelcastIndexedSessionRepository.PRINCIPAL_NAME_ATTRIBUTE)
|
||||||
.setExtractorClassName(PrincipalNameExtractor.class.getName());
|
.setExtractorClassName(PrincipalNameExtractor.class.getName());
|
||||||
config.getMapConfig(HazelcastIndexedSessionRepository.DEFAULT_SESSION_MAP_NAME)
|
config.getMapConfig(HazelcastIndexedSessionRepository.DEFAULT_SESSION_MAP_NAME)
|
||||||
.addAttributeConfig(attributeConfig).addIndexConfig(
|
.addAttributeConfig(attributeConfig)
|
||||||
new IndexConfig(IndexType.HASH, HazelcastIndexedSessionRepository.PRINCIPAL_NAME_ATTRIBUTE));
|
.addIndexConfig(
|
||||||
|
new IndexConfig(IndexType.HASH, HazelcastIndexedSessionRepository.PRINCIPAL_NAME_ATTRIBUTE));
|
||||||
SerializerConfig serializerConfig = new SerializerConfig();
|
SerializerConfig serializerConfig = new SerializerConfig();
|
||||||
serializerConfig.setImplementation(new HazelcastSessionSerializer()).setTypeClass(MapSession.class);
|
serializerConfig.setImplementation(new HazelcastSessionSerializer()).setTypeClass(MapSession.class);
|
||||||
config.getSerializationConfig().addSerializerConfig(serializerConfig);
|
config.getSerializationConfig().addSerializerConfig(serializerConfig);
|
||||||
|
|||||||
@@ -70,8 +70,8 @@ public class HomePage {
|
|||||||
public List<Attribute> attributes() {
|
public List<Attribute> attributes() {
|
||||||
|
|
||||||
List<Attribute> rows = this.trs.stream() //
|
List<Attribute> rows = this.trs.stream() //
|
||||||
.map(Attribute::new) //
|
.map(Attribute::new) //
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
this.attributes.addAll(rows);
|
this.attributes.addAll(rows);
|
||||||
|
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ class RedisSerializerTest {
|
|||||||
assertThat(this.sessionRedisTemplate).isNotNull();
|
assertThat(this.sessionRedisTemplate).isNotNull();
|
||||||
assertThat(this.sessionRedisTemplate.getDefaultSerializer()).isNotNull();
|
assertThat(this.sessionRedisTemplate.getDefaultSerializer()).isNotNull();
|
||||||
assertThat(this.sessionRedisTemplate.getDefaultSerializer())
|
assertThat(this.sessionRedisTemplate.getDefaultSerializer())
|
||||||
.isInstanceOf(GenericJackson2JsonRedisSerializer.class);
|
.isInstanceOf(GenericJackson2JsonRedisSerializer.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestConfiguration
|
@TestConfiguration
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ class ApplicationTests {
|
|||||||
"ws://localhost:" + this.port + "/sockjs");
|
"ws://localhost:" + this.port + "/sockjs");
|
||||||
|
|
||||||
assertThatExceptionOfType(ExecutionException.class)
|
assertThatExceptionOfType(ExecutionException.class)
|
||||||
.isThrownBy(() -> wsSession.get().sendMessage(new TextMessage("a")));
|
.isThrownBy(() -> wsSession.get().sendMessage(new TextMessage("a")));
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestConfiguration
|
@TestConfiguration
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ public class SecurityConfig {
|
|||||||
@Autowired
|
@Autowired
|
||||||
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
|
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
|
||||||
auth.inMemoryAuthentication()
|
auth.inMemoryAuthentication()
|
||||||
.withUser(User.withUsername("user").password("{noop}password").roles("USER").build());
|
.withUser(User.withUsername("user").password("{noop}password").roles("USER").build());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,11 +42,12 @@ public class SessionConfig {
|
|||||||
networkConfig.setPort(0);
|
networkConfig.setPort(0);
|
||||||
networkConfig.getJoin().getAutoDetectionConfig().setEnabled(false);
|
networkConfig.getJoin().getAutoDetectionConfig().setEnabled(false);
|
||||||
AttributeConfig attributeConfig = new AttributeConfig()
|
AttributeConfig attributeConfig = new AttributeConfig()
|
||||||
.setName(HazelcastIndexedSessionRepository.PRINCIPAL_NAME_ATTRIBUTE)
|
.setName(HazelcastIndexedSessionRepository.PRINCIPAL_NAME_ATTRIBUTE)
|
||||||
.setExtractorClassName(PrincipalNameExtractor.class.getName());
|
.setExtractorClassName(PrincipalNameExtractor.class.getName());
|
||||||
config.getMapConfig(HazelcastIndexedSessionRepository.DEFAULT_SESSION_MAP_NAME)
|
config.getMapConfig(HazelcastIndexedSessionRepository.DEFAULT_SESSION_MAP_NAME)
|
||||||
.addAttributeConfig(attributeConfig).addIndexConfig(
|
.addAttributeConfig(attributeConfig)
|
||||||
new IndexConfig(IndexType.HASH, HazelcastIndexedSessionRepository.PRINCIPAL_NAME_ATTRIBUTE));
|
.addIndexConfig(
|
||||||
|
new IndexConfig(IndexType.HASH, HazelcastIndexedSessionRepository.PRINCIPAL_NAME_ATTRIBUTE));
|
||||||
return Hazelcast.newHazelcastInstance(config);
|
return Hazelcast.newHazelcastInstance(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -35,7 +35,9 @@ public class Config {
|
|||||||
@Bean
|
@Bean
|
||||||
public EmbeddedDatabase dataSource() {
|
public EmbeddedDatabase dataSource() {
|
||||||
return new EmbeddedDatabaseBuilder() // <2>
|
return new EmbeddedDatabaseBuilder() // <2>
|
||||||
.setType(EmbeddedDatabaseType.H2).addScript("org/springframework/session/jdbc/schema-h2.sql").build();
|
.setType(EmbeddedDatabaseType.H2)
|
||||||
|
.addScript("org/springframework/session/jdbc/schema-h2.sql")
|
||||||
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
|
|||||||
@@ -65,14 +65,18 @@ class RestMockMvcTests {
|
|||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
void setup() {
|
void setup() {
|
||||||
this.mvc = MockMvcBuilders.webAppContextSetup(this.context).alwaysDo(print())
|
this.mvc = MockMvcBuilders.webAppContextSetup(this.context)
|
||||||
.addFilters(this.sessionRepositoryFilter).apply(springSecurity()).build();
|
.alwaysDo(print())
|
||||||
|
.addFilters(this.sessionRepositoryFilter)
|
||||||
|
.apply(springSecurity())
|
||||||
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void noSessionOnNoCredentials() throws Exception {
|
void noSessionOnNoCredentials() throws Exception {
|
||||||
this.mvc.perform(get("/")).andExpect(header().doesNotExist("X-Auth-Token"))
|
this.mvc.perform(get("/"))
|
||||||
.andExpect(status().isUnauthorized());
|
.andExpect(header().doesNotExist("X-Auth-Token"))
|
||||||
|
.andExpect(status().isUnauthorized());
|
||||||
}
|
}
|
||||||
|
|
||||||
@WithMockUser
|
@WithMockUser
|
||||||
|
|||||||
@@ -60,8 +60,8 @@ class RestTests {
|
|||||||
HttpHeaders headers = new HttpHeaders();
|
HttpHeaders headers = new HttpHeaders();
|
||||||
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
|
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
|
||||||
assertThatExceptionOfType(HttpClientErrorException.class)
|
assertThatExceptionOfType(HttpClientErrorException.class)
|
||||||
.isThrownBy(() -> getForUser(this.baseUrl + "/", headers, String.class))
|
.isThrownBy(() -> getForUser(this.baseUrl + "/", headers, String.class))
|
||||||
.satisfies((e) -> assertThat(e.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED));
|
.satisfies((e) -> assertThat(e.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user