Browse Source

Remove support for Spring Session Hazelcast

Closes gh-47661
pull/47664/head
Phillip Webb 2 months ago
parent
commit
61c8fa2e1c
  1. 1
      configuration-metadata/spring-boot-configuration-metadata-changelog-generator/build.gradle
  2. 4
      documentation/spring-boot-docs/src/docs/antora/modules/reference/pages/web/spring-session.adoc
  3. 3
      module/spring-boot-autoconfigure-classic-modules/build.gradle
  4. 48
      module/spring-boot-session-hazelcast/build.gradle
  5. 77
      module/spring-boot-session-hazelcast/src/main/java/org/springframework/boot/session/hazelcast/autoconfigure/HazelcastSessionAutoConfiguration.java
  6. 73
      module/spring-boot-session-hazelcast/src/main/java/org/springframework/boot/session/hazelcast/autoconfigure/HazelcastSessionProperties.java
  7. 23
      module/spring-boot-session-hazelcast/src/main/java/org/springframework/boot/session/hazelcast/autoconfigure/package-info.java
  8. 4
      module/spring-boot-session-hazelcast/src/main/resources/META-INF/additional-spring-configuration-metadata.json
  9. 1
      module/spring-boot-session-hazelcast/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
  10. 142
      module/spring-boot-session-hazelcast/src/test/java/org/springframework/boot/session/hazelcast/autoconfigure/HazelcastSessionAutoConfigurationTests.java
  11. 3
      platform/spring-boot-dependencies/build.gradle
  12. 4
      settings.gradle
  13. 35
      smoke-test/spring-boot-smoke-test-session-hazelcast/build.gradle
  14. 29
      smoke-test/spring-boot-smoke-test-session-hazelcast/src/main/java/smoketest/session/hazelcast/SampleSessionHazelcastApplication.java
  15. 49
      smoke-test/spring-boot-smoke-test-session-hazelcast/src/main/java/smoketest/session/hazelcast/SecurityConfiguration.java
  16. 20
      smoke-test/spring-boot-smoke-test-session-hazelcast/src/main/java/smoketest/session/hazelcast/package-info.java
  17. 4
      smoke-test/spring-boot-smoke-test-session-hazelcast/src/main/resources/application.properties
  18. 19
      smoke-test/spring-boot-smoke-test-session-hazelcast/src/main/resources/hazelcast.xml
  19. 94
      smoke-test/spring-boot-smoke-test-session-hazelcast/src/test/java/smoketest/session/hazelcast/SampleSessionHazelcastApplicationTests.java
  20. 27
      starter/spring-boot-starter-session-hazelcast-test/build.gradle
  21. 29
      starter/spring-boot-starter-session-hazelcast/build.gradle

1
configuration-metadata/spring-boot-configuration-metadata-changelog-generator/build.gradle

@ -117,7 +117,6 @@ def dependenciesOf(String version) { @@ -117,7 +117,6 @@ def dependenciesOf(String version) {
"spring-boot-servlet",
"spring-boot-session",
"spring-boot-session-data-redis",
"spring-boot-session-hazelcast",
"spring-boot-session-jdbc",
"spring-boot-sql",
"spring-boot-test-autoconfigure",

4
documentation/spring-boot-docs/src/docs/antora/modules/reference/pages/web/spring-session.adoc

@ -6,7 +6,6 @@ When building a servlet web application, the following stores can be auto-config @@ -6,7 +6,6 @@ When building a servlet web application, the following stores can be auto-config
* Redis
* JDBC
* Hazelcast
Additionally, {url-spring-boot-for-apache-geode-site}[Spring Boot for Apache Geode] provides {url-spring-boot-for-apache-geode-docs}#geode-session[auto-configuration for using Apache Geode as a session store].
@ -17,8 +16,7 @@ If you have more than one implementation, Spring Boot uses the following order f @@ -17,8 +16,7 @@ If you have more than one implementation, Spring Boot uses the following order f
. Redis
. JDBC
. Hazelcast
. If none of Redis, JDBC, and Hazelcast are available, we do not configure a javadoc:org.springframework.session.SessionRepository[].
. If neither Redis or JDBC are available, we do not configure a javadoc:org.springframework.session.SessionRepository[].
When building a reactive web application, the Redis store can be auto-configured.

3
module/spring-boot-autoconfigure-classic-modules/build.gradle

@ -238,9 +238,6 @@ dependencies { @@ -238,9 +238,6 @@ dependencies {
api(project(":module:spring-boot-session-data-redis")) {
transitive = false
}
api(project(":module:spring-boot-session-hazelcast")) {
transitive = false
}
api(project(":module:spring-boot-session-jdbc")) {
transitive = false
}

48
module/spring-boot-session-hazelcast/build.gradle

@ -1,48 +0,0 @@ @@ -1,48 +0,0 @@
/*
* Copyright 2012-present the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the License);
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
plugins {
id "java-library"
id "org.springframework.boot.auto-configuration"
id "org.springframework.boot.configuration-properties"
id "org.springframework.boot.deployed"
id "org.springframework.boot.optional-dependencies"
}
description = "Spring Boot Session Hazelcast"
dependencies {
api(project(":core:spring-boot"))
api(project(":module:spring-boot-session"))
api("org.springframework.session:spring-session-hazelcast")
implementation(project(":module:spring-boot-hazelcast"))
implementation(project(":module:spring-boot-web-server"))
optional(project(":core:spring-boot-autoconfigure"))
testImplementation(project(":core:spring-boot-test"))
testImplementation(project(":test-support:spring-boot-test-support"))
testImplementation(testFixtures(project(":module:spring-boot-session")))
testImplementation("jakarta.servlet:jakarta.servlet-api")
testImplementation("org.springframework:spring-web")
testRuntimeOnly("ch.qos.logback:logback-classic")
}
tasks.named("compileTestJava") {
options.nullability.checking = "tests"
}

77
module/spring-boot-session-hazelcast/src/main/java/org/springframework/boot/session/hazelcast/autoconfigure/HazelcastSessionAutoConfiguration.java

@ -1,77 +0,0 @@ @@ -1,77 +0,0 @@
/*
* Copyright 2012-present the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.session.hazelcast.autoconfigure;
import com.hazelcast.core.HazelcastInstance;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.context.properties.PropertyMapper;
import org.springframework.boot.hazelcast.autoconfigure.HazelcastAutoConfiguration;
import org.springframework.boot.session.autoconfigure.SessionAutoConfiguration;
import org.springframework.boot.session.autoconfigure.SessionProperties;
import org.springframework.boot.web.server.autoconfigure.ServerProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Import;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.session.Session;
import org.springframework.session.SessionRepository;
import org.springframework.session.config.SessionRepositoryCustomizer;
import org.springframework.session.hazelcast.HazelcastIndexedSessionRepository;
import org.springframework.session.hazelcast.config.annotation.web.http.HazelcastHttpSessionConfiguration;
/**
* {@link EnableAutoConfiguration Auto-configuration} for Spring Session Hazelcast.
*
* @author Tommy Ludwig
* @author Eddú Meléndez
* @author Stephane Nicoll
* @author Vedran Pavic
* @since 4.0.0
*/
@AutoConfiguration(before = SessionAutoConfiguration.class, after = HazelcastAutoConfiguration.class)
@ConditionalOnWebApplication(type = Type.SERVLET)
@ConditionalOnClass({ Session.class, HazelcastIndexedSessionRepository.class })
@ConditionalOnMissingBean(SessionRepository.class)
@ConditionalOnBean(HazelcastInstance.class)
@EnableConfigurationProperties({ HazelcastSessionProperties.class, ServerProperties.class, SessionProperties.class })
@Import(HazelcastHttpSessionConfiguration.class)
public final class HazelcastSessionAutoConfiguration {
@Bean
@Order(Ordered.HIGHEST_PRECEDENCE)
SessionRepositoryCustomizer<HazelcastIndexedSessionRepository> springBootSessionRepositoryCustomizer(
SessionProperties sessionProperties, HazelcastSessionProperties hazelcastSessionProperties,
ServerProperties serverProperties) {
return (sessionRepository) -> {
PropertyMapper map = PropertyMapper.get();
map.from(sessionProperties.determineTimeout(() -> serverProperties.getServlet().getSession().getTimeout()))
.to(sessionRepository::setDefaultMaxInactiveInterval);
map.from(hazelcastSessionProperties::getMapName).to(sessionRepository::setSessionMapName);
map.from(hazelcastSessionProperties::getFlushMode).to(sessionRepository::setFlushMode);
map.from(hazelcastSessionProperties::getSaveMode).to(sessionRepository::setSaveMode);
};
}
}

73
module/spring-boot-session-hazelcast/src/main/java/org/springframework/boot/session/hazelcast/autoconfigure/HazelcastSessionProperties.java

@ -1,73 +0,0 @@ @@ -1,73 +0,0 @@
/*
* Copyright 2012-present the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.session.hazelcast.autoconfigure;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.session.FlushMode;
import org.springframework.session.SaveMode;
/**
* Configuration properties for Hazelcast backed Spring Session.
*
* @author Vedran Pavic
* @since 4.0.0
*/
@ConfigurationProperties("spring.session.hazelcast")
public class HazelcastSessionProperties {
/**
* Name of the map used to store sessions.
*/
private String mapName = "spring:session:sessions";
/**
* Sessions flush mode. Determines when session changes are written to the session
* store.
*/
private FlushMode flushMode = FlushMode.ON_SAVE;
/**
* Sessions save mode. Determines how session changes are tracked and saved to the
* session store.
*/
private SaveMode saveMode = SaveMode.ON_SET_ATTRIBUTE;
public String getMapName() {
return this.mapName;
}
public void setMapName(String mapName) {
this.mapName = mapName;
}
public FlushMode getFlushMode() {
return this.flushMode;
}
public void setFlushMode(FlushMode flushMode) {
this.flushMode = flushMode;
}
public SaveMode getSaveMode() {
return this.saveMode;
}
public void setSaveMode(SaveMode saveMode) {
this.saveMode = saveMode;
}
}

23
module/spring-boot-session-hazelcast/src/main/java/org/springframework/boot/session/hazelcast/autoconfigure/package-info.java

@ -1,23 +0,0 @@ @@ -1,23 +0,0 @@
/*
* Copyright 2012-present the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Auto-configuration for Spring Session Hazelcast.
*/
@NullMarked
package org.springframework.boot.session.hazelcast.autoconfigure;
import org.jspecify.annotations.NullMarked;

4
module/spring-boot-session-hazelcast/src/main/resources/META-INF/additional-spring-configuration-metadata.json

@ -1,4 +0,0 @@ @@ -1,4 +0,0 @@
{
"groups": [],
"properties": []
}

1
module/spring-boot-session-hazelcast/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports

@ -1 +0,0 @@ @@ -1 +0,0 @@
org.springframework.boot.session.hazelcast.autoconfigure.HazelcastSessionAutoConfiguration

142
module/spring-boot-session-hazelcast/src/test/java/org/springframework/boot/session/hazelcast/autoconfigure/HazelcastSessionAutoConfigurationTests.java

@ -1,142 +0,0 @@ @@ -1,142 +0,0 @@
/*
* Copyright 2012-present the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.session.hazelcast.autoconfigure;
import java.time.Duration;
import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.map.IMap;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.session.autoconfigure.AbstractSessionAutoConfigurationTests;
import org.springframework.boot.session.autoconfigure.SessionAutoConfiguration;
import org.springframework.boot.test.context.runner.WebApplicationContextRunner;
import org.springframework.boot.web.server.autoconfigure.ServerProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.session.FlushMode;
import org.springframework.session.SaveMode;
import org.springframework.session.config.SessionRepositoryCustomizer;
import org.springframework.session.hazelcast.HazelcastIndexedSessionRepository;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;
import static org.mockito.BDDMockito.then;
import static org.mockito.Mockito.mock;
/**
* Tests for {@link HazelcastSessionAutoConfiguration}.
*
* @author Vedran Pavic
*/
class HazelcastSessionAutoConfigurationTests extends AbstractSessionAutoConfigurationTests {
@BeforeEach
void prepareContextRunner() {
this.contextRunner = new WebApplicationContextRunner()
.withConfiguration(
AutoConfigurations.of(SessionAutoConfiguration.class, HazelcastSessionAutoConfiguration.class))
.withUserConfiguration(HazelcastConfiguration.class);
}
@Test
void defaultConfig() {
this.contextRunner.run((context) -> {
HazelcastIndexedSessionRepository repository = validateSessionRepository(context,
HazelcastIndexedSessionRepository.class);
assertThat(repository).hasFieldOrPropertyWithValue("defaultMaxInactiveInterval",
new ServerProperties().getServlet().getSession().getTimeout());
HazelcastInstance hazelcastInstance = context.getBean(HazelcastInstance.class);
then(hazelcastInstance).should().getMap("spring:session:sessions");
});
}
@Test
void defaultConfigWithCustomTimeout() {
this.contextRunner.withPropertyValues("spring.session.timeout=1m").run((context) -> {
HazelcastIndexedSessionRepository repository = validateSessionRepository(context,
HazelcastIndexedSessionRepository.class);
assertThat(repository).hasFieldOrPropertyWithValue("defaultMaxInactiveInterval", Duration.ofMinutes(1));
});
}
@Test
void customMapName() {
this.contextRunner.withPropertyValues("spring.session.hazelcast.map-name=foo:bar:biz").run((context) -> {
validateSessionRepository(context, HazelcastIndexedSessionRepository.class);
HazelcastInstance hazelcastInstance = context.getBean(HazelcastInstance.class);
then(hazelcastInstance).should().getMap("foo:bar:biz");
});
}
@Test
void customFlushMode() {
this.contextRunner.withPropertyValues("spring.session.hazelcast.flush-mode=immediate").run((context) -> {
HazelcastIndexedSessionRepository repository = validateSessionRepository(context,
HazelcastIndexedSessionRepository.class);
assertThat(repository).hasFieldOrPropertyWithValue("flushMode", FlushMode.IMMEDIATE);
});
}
@Test
void customSaveMode() {
this.contextRunner.withPropertyValues("spring.session.hazelcast.save-mode=on-get-attribute").run((context) -> {
HazelcastIndexedSessionRepository repository = validateSessionRepository(context,
HazelcastIndexedSessionRepository.class);
assertThat(repository).hasFieldOrPropertyWithValue("saveMode", SaveMode.ON_GET_ATTRIBUTE);
});
}
@Test
void whenTheUserDefinesTheirOwnSessionRepositoryCustomizerThenDefaultConfigurationIsOverwritten() {
this.contextRunner.withUserConfiguration(CustomizerConfiguration.class)
.withPropertyValues("spring.session.hazelcast.save-mode=on-get-attribute")
.run((context) -> {
HazelcastIndexedSessionRepository repository = validateSessionRepository(context,
HazelcastIndexedSessionRepository.class);
assertThat(repository).hasFieldOrPropertyWithValue("saveMode", SaveMode.ALWAYS);
});
}
@Configuration(proxyBeanMethods = false)
static class HazelcastConfiguration {
@Bean
@SuppressWarnings("unchecked")
HazelcastInstance hazelcastInstance() {
IMap<Object, Object> map = mock(IMap.class);
HazelcastInstance mock = mock(HazelcastInstance.class);
given(mock.getMap("spring:session:sessions")).willReturn(map);
given(mock.getMap("foo:bar:biz")).willReturn(map);
return mock;
}
}
@Configuration(proxyBeanMethods = false)
static class CustomizerConfiguration {
@Bean
SessionRepositoryCustomizer<HazelcastIndexedSessionRepository> sessionRepositoryCustomizer() {
return (repository) -> repository.setSaveMode(SaveMode.ALWAYS);
}
}
}

3
platform/spring-boot-dependencies/build.gradle

@ -2088,7 +2088,6 @@ bom { @@ -2088,7 +2088,6 @@ bom {
"spring-boot-servlet",
"spring-boot-session",
"spring-boot-session-data-redis",
"spring-boot-session-hazelcast",
"spring-boot-session-jdbc",
"spring-boot-sql",
"spring-boot-starter",
@ -2228,8 +2227,6 @@ bom { @@ -2228,8 +2227,6 @@ bom {
"spring-boot-starter-sendgrid-test",
"spring-boot-starter-session-data-redis",
"spring-boot-starter-session-data-redis-test",
"spring-boot-starter-session-hazelcast",
"spring-boot-starter-session-hazelcast-test",
"spring-boot-starter-session-jdbc",
"spring-boot-starter-session-jdbc-test",
"spring-boot-starter-sql",

4
settings.gradle

@ -178,7 +178,6 @@ include "module:spring-boot-sendgrid" @@ -178,7 +178,6 @@ include "module:spring-boot-sendgrid"
include "module:spring-boot-servlet"
include "module:spring-boot-session"
include "module:spring-boot-session-data-redis"
include "module:spring-boot-session-hazelcast"
include "module:spring-boot-session-jdbc"
include "module:spring-boot-sql"
include "module:spring-boot-test-classic-modules"
@ -337,8 +336,6 @@ include "starter:spring-boot-starter-sendgrid" @@ -337,8 +336,6 @@ include "starter:spring-boot-starter-sendgrid"
include "starter:spring-boot-starter-sendgrid-test"
include "starter:spring-boot-starter-session-data-redis"
include "starter:spring-boot-starter-session-data-redis-test"
include "starter:spring-boot-starter-session-hazelcast"
include "starter:spring-boot-starter-session-hazelcast-test"
include "starter:spring-boot-starter-session-jdbc"
include "starter:spring-boot-starter-session-jdbc-test"
include "starter:spring-boot-starter-sql"
@ -438,7 +435,6 @@ include ":smoke-test:spring-boot-smoke-test-saml2-service-provider" @@ -438,7 +435,6 @@ include ":smoke-test:spring-boot-smoke-test-saml2-service-provider"
include ":smoke-test:spring-boot-smoke-test-secure"
include ":smoke-test:spring-boot-smoke-test-secure-webflux"
include ":smoke-test:spring-boot-smoke-test-servlet"
include ":smoke-test:spring-boot-smoke-test-session-hazelcast"
include ":smoke-test:spring-boot-smoke-test-session-jdbc"
include ":smoke-test:spring-boot-smoke-test-session-data-redis"
include ":smoke-test:spring-boot-smoke-test-session-data-redis-webflux"

35
smoke-test/spring-boot-smoke-test-session-hazelcast/build.gradle

@ -1,35 +0,0 @@ @@ -1,35 +0,0 @@
/*
* Copyright 2012-present the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the License);
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
plugins {
id "java"
}
description = "Spring Boot Session smoke test"
dependencies {
implementation(project(":starter:spring-boot-starter-actuator"))
implementation(project(":starter:spring-boot-starter-security"))
implementation(project(":starter:spring-boot-starter-session-hazelcast"))
implementation(project(":starter:spring-boot-starter-webmvc"))
testImplementation(project(":starter:spring-boot-starter-webmvc-test"))
testImplementation(project(":starter:spring-boot-starter-test"))
}
tasks.named("compileTestJava") {
options.nullability.checking = "tests"
}

29
smoke-test/spring-boot-smoke-test-session-hazelcast/src/main/java/smoketest/session/hazelcast/SampleSessionHazelcastApplication.java

@ -1,29 +0,0 @@ @@ -1,29 +0,0 @@
/*
* Copyright 2012-present the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package smoketest.session.hazelcast;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class SampleSessionHazelcastApplication {
public static void main(String[] args) {
SpringApplication.run(SampleSessionHazelcastApplication.class);
}
}

49
smoke-test/spring-boot-smoke-test-session-hazelcast/src/main/java/smoketest/session/hazelcast/SecurityConfiguration.java

@ -1,49 +0,0 @@ @@ -1,49 +0,0 @@
/*
* Copyright 2012-present the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package smoketest.session.hazelcast;
import org.springframework.boot.health.actuate.endpoint.HealthEndpoint;
import org.springframework.boot.security.autoconfigure.actuate.servlet.EndpointRequest;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configurers.CsrfConfigurer;
import org.springframework.security.web.SecurityFilterChain;
import static org.springframework.security.config.Customizer.withDefaults;
/**
* Security configuration.
*
* @author Madhura Bhave
*/
@Configuration(proxyBeanMethods = false)
class SecurityConfiguration {
@Bean
SecurityFilterChain managementSecurityFilterChain(HttpSecurity http) {
http.authorizeHttpRequests((requests) -> {
requests.requestMatchers(EndpointRequest.to(HealthEndpoint.class)).permitAll();
requests.anyRequest().authenticated();
});
http.formLogin(withDefaults());
http.httpBasic(withDefaults());
http.csrf(CsrfConfigurer::disable);
return http.build();
}
}

20
smoke-test/spring-boot-smoke-test-session-hazelcast/src/main/java/smoketest/session/hazelcast/package-info.java

@ -1,20 +0,0 @@ @@ -1,20 +0,0 @@
/*
* Copyright 2012-present the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@NullMarked
package smoketest.session.hazelcast;
import org.jspecify.annotations.NullMarked;

4
smoke-test/spring-boot-smoke-test-session-hazelcast/src/main/resources/application.properties

@ -1,4 +0,0 @@ @@ -1,4 +0,0 @@
spring.security.user.name=user
spring.security.user.password=password
management.endpoints.web.exposure.include=*

19
smoke-test/spring-boot-smoke-test-session-hazelcast/src/main/resources/hazelcast.xml

@ -1,19 +0,0 @@ @@ -1,19 +0,0 @@
<hazelcast xmlns="http://www.hazelcast.com/schema/config"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.hazelcast.com/schema/config
http://www.hazelcast.com/schema/config/hazelcast-config-4.2.xsd">
<map name="spring:session:sessions">
<attributes>
<attribute extractor-class-name="org.springframework.session.hazelcast.PrincipalNameExtractor">principalName</attribute>
</attributes>
</map>
<network>
<join>
<auto-detection enabled="false"/>
<multicast enabled="false"/>
</join>
</network>
</hazelcast>

94
smoke-test/spring-boot-smoke-test-session-hazelcast/src/test/java/smoketest/session/hazelcast/SampleSessionHazelcastApplicationTests.java

@ -1,94 +0,0 @@ @@ -1,94 +0,0 @@
/*
* Copyright 2012-present the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package smoketest.session.hazelcast;
import java.net.URI;
import java.util.Base64;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.resttestclient.TestRestTemplate;
import org.springframework.boot.resttestclient.autoconfigure.AutoConfigureTestRestTemplate;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.RequestEntity;
import org.springframework.http.ResponseEntity;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for {@link SampleSessionHazelcastApplication}.
*
* @author Susmitha Kandula
* @author Madhura Bhave
*/
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@AutoConfigureTestRestTemplate
class SampleSessionHazelcastApplicationTests {
@Autowired
private TestRestTemplate restTemplate;
@Test
@SuppressWarnings("unchecked")
void sessionsEndpointShouldReturnUserSession() {
performLogin();
ResponseEntity<Map<String, Object>> entity = getSessions();
assertThat(entity).isNotNull();
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
Map<String, Object> body = entity.getBody();
assertThat(body).isNotNull();
List<Map<String, Object>> sessions = (List<Map<String, Object>>) body.get("sessions");
assertThat(sessions).hasSize(1);
}
private void performLogin() {
HttpHeaders headers = new HttpHeaders();
headers.setAccept(Collections.singletonList(MediaType.TEXT_HTML));
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
MultiValueMap<String, String> form = new LinkedMultiValueMap<>();
form.set("username", "user");
form.set("password", "password");
this.restTemplate.exchange("/login", HttpMethod.POST, new HttpEntity<>(form, headers), String.class);
}
private ResponseEntity<Map<String, Object>> getSessions() {
HttpHeaders headers = new HttpHeaders();
headers.set("Authorization", getBasicAuth());
RequestEntity<Object> request = new RequestEntity<>(headers, HttpMethod.GET,
URI.create("/actuator/sessions?username=user"));
ParameterizedTypeReference<Map<String, Object>> stringObjectMap = new ParameterizedTypeReference<>() {
};
return this.restTemplate.exchange(request, stringObjectMap);
}
private String getBasicAuth() {
return "Basic " + Base64.getEncoder().encodeToString("user:password".getBytes());
}
}

27
starter/spring-boot-starter-session-hazelcast-test/build.gradle

@ -1,27 +0,0 @@ @@ -1,27 +0,0 @@
/*
* Copyright 2012-present the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the License);
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
plugins {
id "org.springframework.boot.starter"
}
description = "Starter for testing Spring Session with Hazelcast"
dependencies {
api(project(":starter:spring-boot-starter-session-hazelcast"))
api(project(":starter:spring-boot-starter-test"))
api(project(":starter:spring-boot-starter-hazelcast-test"))
}

29
starter/spring-boot-starter-session-hazelcast/build.gradle

@ -1,29 +0,0 @@ @@ -1,29 +0,0 @@
/*
* Copyright 2012-present the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the License);
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
plugins {
id "org.springframework.boot.starter"
}
description = "Starter for using Spring Session with Hazelcast"
dependencies {
api(project(":starter:spring-boot-starter"))
api(project(":starter:spring-boot-starter-hazelcast"))
api(project(":module:spring-boot-session-hazelcast"))
api(project(":module:spring-boot-hazelcast"))
}
Loading…
Cancel
Save