From 219633b023eefc5fd253c594fc8f4fe1963b74a5 Mon Sep 17 00:00:00 2001 From: Vedran Pavic Date: Mon, 29 Aug 2022 07:45:00 +0200 Subject: [PATCH 1/3] Configure nohttp to ignore docs build output At present, project build fails with checkstyleNohttp task error if not cleaned beforehand. This commit updates nohttp configuration so that it ignores build output of examples in spring-session-docs module. Closes gh-2127 --- build.gradle | 2 ++ 1 file changed, 2 insertions(+) diff --git a/build.gradle b/build.gradle index edfcb2df9..5eecda0ca 100644 --- a/build.gradle +++ b/build.gradle @@ -45,4 +45,6 @@ subprojects { nohttp { source.exclude "buildSrc/build/**" + source.exclude "spring-session-docs/.gradle/nodejs/**" + source.exclude "spring-session-docs/modules/ROOT/examples/**/build/**" } From a3843148e4b64d4b650e93262198e4484fff2a6a Mon Sep 17 00:00:00 2001 From: Vedran Pavic Date: Mon, 29 Aug 2022 07:48:28 +0200 Subject: [PATCH 2/3] Update .gitignore This commit updates .gitignore to include NPM files created by Antora tasks of spring-session-docs module. --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 8b42ff9b2..5213fb46d 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,5 @@ out !etc/eclipse/.checkstyle !**/src/**/build .DS_Store +spring-session-docs/package-lock.json +spring-session-docs/node_modules/ From cc0f93c0faad7a55a8b64325c6c5b80f119984ef Mon Sep 17 00:00:00 2001 From: Vedran Pavic Date: Mon, 29 Aug 2022 07:50:55 +0200 Subject: [PATCH 3/3] Remove unused test sources in docs This commit removes test sources that are already present in modules/ROOT/examples path of spring-session-docs module. --- ...FindByIndexNameSessionRepositoryTests.java | 63 ------ ...ationNoOpConfigureRedisActionXmlTests.java | 53 ----- .../src/test/java/docs/IndexDocTests.java | 211 ------------------ ...gurationNoOpConfigureRedisActionTests.java | 63 ------ .../java/docs/SpringHttpSessionConfig.java | 37 --- .../java/docs/SpringWebSessionConfig.java | 36 --- .../AbstractHttpSessionListenerTests.java | 92 -------- .../docs/http/HazelcastHttpSessionConfig.java | 55 ----- .../HttpSessionListenerJavaConfigTests.java | 46 ---- .../http/HttpSessionListenerXmlTests.java | 28 --- .../docs/http/RedisHttpSessionConfig.java | 37 --- .../RememberMeSecurityConfiguration.java | 82 ------- .../RememberMeSecurityConfigurationTests.java | 92 -------- ...memberMeSecurityConfigurationXmlTests.java | 92 -------- .../docs/security/SecurityConfiguration.java | 56 ----- .../java/docs/websocket/WebSocketConfig.java | 47 ---- ...OpConfigureRedisActionXmlTests-context.xml | 22 -- .../HttpSessionListenerXmlTests-context.xml | 22 -- ...eSecurityConfigurationXmlTests-context.xml | 32 --- .../docs/security/security-config.xml | 22 -- 20 files changed, 1188 deletions(-) delete mode 100644 spring-session-docs/src/test/java/docs/FindByIndexNameSessionRepositoryTests.java delete mode 100644 spring-session-docs/src/test/java/docs/HttpSessionConfigurationNoOpConfigureRedisActionXmlTests.java delete mode 100644 spring-session-docs/src/test/java/docs/IndexDocTests.java delete mode 100644 spring-session-docs/src/test/java/docs/RedisHttpSessionConfigurationNoOpConfigureRedisActionTests.java delete mode 100644 spring-session-docs/src/test/java/docs/SpringHttpSessionConfig.java delete mode 100644 spring-session-docs/src/test/java/docs/SpringWebSessionConfig.java delete mode 100644 spring-session-docs/src/test/java/docs/http/AbstractHttpSessionListenerTests.java delete mode 100644 spring-session-docs/src/test/java/docs/http/HazelcastHttpSessionConfig.java delete mode 100644 spring-session-docs/src/test/java/docs/http/HttpSessionListenerJavaConfigTests.java delete mode 100644 spring-session-docs/src/test/java/docs/http/HttpSessionListenerXmlTests.java delete mode 100644 spring-session-docs/src/test/java/docs/http/RedisHttpSessionConfig.java delete mode 100644 spring-session-docs/src/test/java/docs/security/RememberMeSecurityConfiguration.java delete mode 100644 spring-session-docs/src/test/java/docs/security/RememberMeSecurityConfigurationTests.java delete mode 100644 spring-session-docs/src/test/java/docs/security/RememberMeSecurityConfigurationXmlTests.java delete mode 100644 spring-session-docs/src/test/java/docs/security/SecurityConfiguration.java delete mode 100644 spring-session-docs/src/test/java/docs/websocket/WebSocketConfig.java delete mode 100644 spring-session-docs/src/test/resources/docs/HttpSessionConfigurationNoOpConfigureRedisActionXmlTests-context.xml delete mode 100644 spring-session-docs/src/test/resources/docs/http/HttpSessionListenerXmlTests-context.xml delete mode 100644 spring-session-docs/src/test/resources/docs/security/RememberMeSecurityConfigurationXmlTests-context.xml delete mode 100644 spring-session-docs/src/test/resources/docs/security/security-config.xml diff --git a/spring-session-docs/src/test/java/docs/FindByIndexNameSessionRepositoryTests.java b/spring-session-docs/src/test/java/docs/FindByIndexNameSessionRepositoryTests.java deleted file mode 100644 index 9514987d0..000000000 --- a/spring-session-docs/src/test/java/docs/FindByIndexNameSessionRepositoryTests.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright 2014-2019 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 docs; - -import java.util.Map; - -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; - -import org.springframework.session.FindByIndexNameSessionRepository; -import org.springframework.session.Session; - -/** - * @author Rob Winch - * - */ -class FindByIndexNameSessionRepositoryTests { - - @Mock - FindByIndexNameSessionRepository sessionRepository; - - @Mock - Session session; - - @BeforeEach - void setUp() { - MockitoAnnotations.initMocks(this); - } - - @Test - void setUsername() { - // tag::set-username[] - String username = "username"; - this.session.setAttribute(FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME, username); - // end::set-username[] - } - - @Test - @SuppressWarnings("unused") - void findByUsername() { - // tag::findby-username[] - String username = "username"; - Map sessionIdToSession = this.sessionRepository.findByPrincipalName(username); - // end::findby-username[] - } - -} diff --git a/spring-session-docs/src/test/java/docs/HttpSessionConfigurationNoOpConfigureRedisActionXmlTests.java b/spring-session-docs/src/test/java/docs/HttpSessionConfigurationNoOpConfigureRedisActionXmlTests.java deleted file mode 100644 index f3e3d25d3..000000000 --- a/spring-session-docs/src/test/java/docs/HttpSessionConfigurationNoOpConfigureRedisActionXmlTests.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright 2014-2019 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 docs; - -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.redis.connection.RedisConnectionFactory; -import org.springframework.session.Session; -import org.springframework.session.web.http.SessionRepositoryFilter; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit.jupiter.SpringExtension; -import org.springframework.test.context.web.WebAppConfiguration; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; - -/** - * @author Rob Winch - */ -@ExtendWith(SpringExtension.class) -@ContextConfiguration -@WebAppConfiguration -public class HttpSessionConfigurationNoOpConfigureRedisActionXmlTests { - - @Autowired - SessionRepositoryFilter filter; - - @Test - void redisConnectionFactoryNotUsedSinceNoValidation() { - assertThat(this.filter).isNotNull(); - } - - static RedisConnectionFactory connectionFactory() { - return mock(RedisConnectionFactory.class); - } - -} diff --git a/spring-session-docs/src/test/java/docs/IndexDocTests.java b/spring-session-docs/src/test/java/docs/IndexDocTests.java deleted file mode 100644 index a9410e66a..000000000 --- a/spring-session-docs/src/test/java/docs/IndexDocTests.java +++ /dev/null @@ -1,211 +0,0 @@ -/* - * Copyright 2014-2019 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 docs; - -import java.time.Duration; -import java.util.concurrent.ConcurrentHashMap; - -import com.hazelcast.config.Config; -import com.hazelcast.core.Hazelcast; -import com.hazelcast.core.HazelcastInstance; -import org.junit.jupiter.api.Test; - -import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; -import org.springframework.data.redis.core.ReactiveRedisTemplate; -import org.springframework.data.redis.core.RedisTemplate; -import org.springframework.data.redis.serializer.JdkSerializationRedisSerializer; -import org.springframework.data.redis.serializer.RedisSerializationContext; -import org.springframework.jdbc.core.JdbcTemplate; -import org.springframework.mock.web.MockServletContext; -import org.springframework.session.MapSession; -import org.springframework.session.MapSessionRepository; -import org.springframework.session.ReactiveSessionRepository; -import org.springframework.session.Session; -import org.springframework.session.SessionRepository; -import org.springframework.session.data.redis.ReactiveRedisSessionRepository; -import org.springframework.session.data.redis.RedisIndexedSessionRepository; -import org.springframework.session.hazelcast.HazelcastIndexedSessionRepository; -import org.springframework.session.jdbc.JdbcIndexedSessionRepository; -import org.springframework.session.web.http.SessionRepositoryFilter; -import org.springframework.transaction.support.TransactionTemplate; -import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * @author Rob Winch - * @author Vedran Pavic - */ -class IndexDocTests { - - private static final String ATTR_USER = "user"; - - @Test - void repositoryDemo() { - RepositoryDemo demo = new RepositoryDemo<>(); - demo.repository = new MapSessionRepository(new ConcurrentHashMap<>()); - - demo.demo(); - } - - // tag::repository-demo[] - public class RepositoryDemo { - - private SessionRepository repository; // <1> - - public void demo() { - S toSave = this.repository.createSession(); // <2> - - // <3> - User rwinch = new User("rwinch"); - toSave.setAttribute(ATTR_USER, rwinch); - - this.repository.save(toSave); // <4> - - S session = this.repository.findById(toSave.getId()); // <5> - - // <6> - User user = session.getAttribute(ATTR_USER); - assertThat(user).isEqualTo(rwinch); - } - - // ... setter methods ... - - } - // end::repository-demo[] - - @Test - void expireRepositoryDemo() { - ExpiringRepositoryDemo demo = new ExpiringRepositoryDemo<>(); - demo.repository = new MapSessionRepository(new ConcurrentHashMap<>()); - - demo.demo(); - } - - // tag::expire-repository-demo[] - public class ExpiringRepositoryDemo { - - private SessionRepository repository; // <1> - - public void demo() { - S toSave = this.repository.createSession(); // <2> - // ... - toSave.setMaxInactiveInterval(Duration.ofSeconds(30)); // <3> - - this.repository.save(toSave); // <4> - - S session = this.repository.findById(toSave.getId()); // <5> - // ... - } - - // ... setter methods ... - - } - // end::expire-repository-demo[] - - @Test - @SuppressWarnings("unused") - void newRedisIndexedSessionRepository() { - // tag::new-redisindexedsessionrepository[] - RedisTemplate redisTemplate = new RedisTemplate<>(); - - // ... configure redisTemplate ... - - SessionRepository repository = new RedisIndexedSessionRepository(redisTemplate); - // end::new-redisindexedsessionrepository[] - } - - @Test - @SuppressWarnings("unused") - void newReactiveRedisSessionRepository() { - LettuceConnectionFactory connectionFactory = new LettuceConnectionFactory(); - RedisSerializationContext serializationContext = RedisSerializationContext - .newSerializationContext(new JdkSerializationRedisSerializer()).build(); - - // tag::new-reactiveredissessionrepository[] - // ... create and configure connectionFactory and serializationContext ... - - ReactiveRedisTemplate redisTemplate = new ReactiveRedisTemplate<>(connectionFactory, - serializationContext); - - ReactiveSessionRepository repository = new ReactiveRedisSessionRepository(redisTemplate); - // end::new-reactiveredissessionrepository[] - } - - @Test - @SuppressWarnings("unused") - void mapRepository() { - // tag::new-mapsessionrepository[] - SessionRepository repository = new MapSessionRepository(new ConcurrentHashMap<>()); - // end::new-mapsessionrepository[] - } - - @Test - @SuppressWarnings("unused") - void newJdbcIndexedSessionRepository() { - // tag::new-jdbcindexedsessionrepository[] - JdbcTemplate jdbcTemplate = new JdbcTemplate(); - - // ... configure jdbcTemplate ... - - TransactionTemplate transactionTemplate = new TransactionTemplate(); - - // ... configure transactionTemplate ... - - SessionRepository repository = new JdbcIndexedSessionRepository(jdbcTemplate, - transactionTemplate); - // end::new-jdbcindexedsessionrepository[] - } - - @Test - @SuppressWarnings("unused") - void newHazelcastIndexedSessionRepository() { - // tag::new-hazelcastindexedsessionrepository[] - - Config config = new Config(); - - // ... configure Hazelcast ... - - HazelcastInstance hazelcastInstance = Hazelcast.newHazelcastInstance(config); - - HazelcastIndexedSessionRepository repository = new HazelcastIndexedSessionRepository(hazelcastInstance); - // end::new-hazelcastindexedsessionrepository[] - } - - @Test - void runSpringHttpSessionConfig() { - AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); - context.register(SpringHttpSessionConfig.class); - context.setServletContext(new MockServletContext()); - context.refresh(); - - try { - context.getBean(SessionRepositoryFilter.class); - } - finally { - context.close(); - } - } - - private static final class User { - - private User(String username) { - } - - } - -} diff --git a/spring-session-docs/src/test/java/docs/RedisHttpSessionConfigurationNoOpConfigureRedisActionTests.java b/spring-session-docs/src/test/java/docs/RedisHttpSessionConfigurationNoOpConfigureRedisActionTests.java deleted file mode 100644 index 27b1ebd89..000000000 --- a/spring-session-docs/src/test/java/docs/RedisHttpSessionConfigurationNoOpConfigureRedisActionTests.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright 2014-2019 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 docs; - -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; - -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.data.redis.connection.RedisConnectionFactory; -import org.springframework.session.data.redis.config.ConfigureRedisAction; -import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit.jupiter.SpringExtension; -import org.springframework.test.context.web.WebAppConfiguration; - -import static org.mockito.Mockito.mock; - -/** - * @author Rob Winch - */ -@ExtendWith(SpringExtension.class) -@ContextConfiguration -@WebAppConfiguration -class RedisHttpSessionConfigurationNoOpConfigureRedisActionTests { - - @Test - void redisConnectionFactoryNotUsedSinceNoValidation() { - } - - @EnableRedisHttpSession - @Configuration - static class Config { - - // tag::configure-redis-action[] - @Bean - ConfigureRedisAction configureRedisAction() { - return ConfigureRedisAction.NO_OP; - } - // end::configure-redis-action[] - - @Bean - RedisConnectionFactory redisConnectionFactory() { - return mock(RedisConnectionFactory.class); - } - - } - -} diff --git a/spring-session-docs/src/test/java/docs/SpringHttpSessionConfig.java b/spring-session-docs/src/test/java/docs/SpringHttpSessionConfig.java deleted file mode 100644 index f257503b1..000000000 --- a/spring-session-docs/src/test/java/docs/SpringHttpSessionConfig.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright 2014-2019 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 docs; - -import java.util.concurrent.ConcurrentHashMap; - -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.session.MapSessionRepository; -import org.springframework.session.config.annotation.web.http.EnableSpringHttpSession; - -// tag::class[] -@EnableSpringHttpSession -@Configuration -public class SpringHttpSessionConfig { - - @Bean - public MapSessionRepository sessionRepository() { - return new MapSessionRepository(new ConcurrentHashMap<>()); - } - -} -// end::class[] diff --git a/spring-session-docs/src/test/java/docs/SpringWebSessionConfig.java b/spring-session-docs/src/test/java/docs/SpringWebSessionConfig.java deleted file mode 100644 index 69e22fcae..000000000 --- a/spring-session-docs/src/test/java/docs/SpringWebSessionConfig.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright 2014-2019 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 docs; - -import java.util.concurrent.ConcurrentHashMap; - -import org.springframework.context.annotation.Bean; -import org.springframework.session.ReactiveMapSessionRepository; -import org.springframework.session.ReactiveSessionRepository; -import org.springframework.session.config.annotation.web.server.EnableSpringWebSession; - -// tag::class[] -@EnableSpringWebSession -public class SpringWebSessionConfig { - - @Bean - public ReactiveSessionRepository reactiveSessionRepository() { - return new ReactiveMapSessionRepository(new ConcurrentHashMap<>()); - } - -} -// end::class[] diff --git a/spring-session-docs/src/test/java/docs/http/AbstractHttpSessionListenerTests.java b/spring-session-docs/src/test/java/docs/http/AbstractHttpSessionListenerTests.java deleted file mode 100644 index ea6b6171e..000000000 --- a/spring-session-docs/src/test/java/docs/http/AbstractHttpSessionListenerTests.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright 2014-2021 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 docs.http; - -import java.util.Properties; - -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.ApplicationEventPublisher; -import org.springframework.context.ApplicationListener; -import org.springframework.data.redis.connection.RedisConnection; -import org.springframework.data.redis.connection.RedisConnectionFactory; -import org.springframework.security.core.session.SessionDestroyedEvent; -import org.springframework.session.MapSession; -import org.springframework.session.Session; -import org.springframework.test.context.junit.jupiter.SpringExtension; -import org.springframework.test.context.web.WebAppConfiguration; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.mock; - -/** - * @author Rob Winch - * @author Mark Paluch - * @since 1.2 - */ -@ExtendWith(SpringExtension.class) -@WebAppConfiguration -public abstract class AbstractHttpSessionListenerTests { - - @Autowired - ApplicationEventPublisher publisher; - - @Autowired - SecuritySessionDestroyedListener listener; - - @Test - void springSessionDestroyedTranslatedToSpringSecurityDestroyed() { - Session session = new MapSession(); - - this.publisher.publishEvent(new org.springframework.session.events.SessionDestroyedEvent(this, session)); - - assertThat(this.listener.getEvent().getId()).isEqualTo(session.getId()); - } - - static RedisConnectionFactory createMockRedisConnection() { - RedisConnectionFactory factory = mock(RedisConnectionFactory.class); - RedisConnection connection = mock(RedisConnection.class); - - given(factory.getConnection()).willReturn(connection); - given(connection.getConfig(anyString())).willReturn(new Properties()); - return factory; - } - - static class SecuritySessionDestroyedListener implements ApplicationListener { - - private SessionDestroyedEvent event; - - /* - * @see org.springframework.context.ApplicationListener#onApplicationEvent(org. - * springframework.context.ApplicationEvent) - */ - @Override - public void onApplicationEvent(SessionDestroyedEvent event) { - this.event = event; - } - - SessionDestroyedEvent getEvent() { - return this.event; - } - - } - -} diff --git a/spring-session-docs/src/test/java/docs/http/HazelcastHttpSessionConfig.java b/spring-session-docs/src/test/java/docs/http/HazelcastHttpSessionConfig.java deleted file mode 100644 index c77bc1d32..000000000 --- a/spring-session-docs/src/test/java/docs/http/HazelcastHttpSessionConfig.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2014-2019 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 docs.http; - -import com.hazelcast.config.Config; -import com.hazelcast.config.MapAttributeConfig; -import com.hazelcast.config.MapIndexConfig; -import com.hazelcast.config.SerializerConfig; -import com.hazelcast.core.Hazelcast; -import com.hazelcast.core.HazelcastInstance; - -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.session.MapSession; -import org.springframework.session.hazelcast.HazelcastIndexedSessionRepository; -import org.springframework.session.hazelcast.HazelcastSessionSerializer; -import org.springframework.session.hazelcast.PrincipalNameExtractor; -import org.springframework.session.hazelcast.config.annotation.web.http.EnableHazelcastHttpSession; - -//tag::config[] -@EnableHazelcastHttpSession // <1> -@Configuration -public class HazelcastHttpSessionConfig { - - @Bean - public HazelcastInstance hazelcastInstance() { - Config config = new Config(); - MapAttributeConfig attributeConfig = new MapAttributeConfig() - .setName(HazelcastIndexedSessionRepository.PRINCIPAL_NAME_ATTRIBUTE) - .setExtractor(PrincipalNameExtractor.class.getName()); - config.getMapConfig(HazelcastIndexedSessionRepository.DEFAULT_SESSION_MAP_NAME) // <2> - .addMapAttributeConfig(attributeConfig).addMapIndexConfig( - new MapIndexConfig(HazelcastIndexedSessionRepository.PRINCIPAL_NAME_ATTRIBUTE, false)); - SerializerConfig serializerConfig = new SerializerConfig(); - serializerConfig.setImplementation(new HazelcastSessionSerializer()).setTypeClass(MapSession.class); - config.getSerializationConfig().addSerializerConfig(serializerConfig); // <3> - return Hazelcast.newHazelcastInstance(config); // <4> - } - -} -// end::config[] diff --git a/spring-session-docs/src/test/java/docs/http/HttpSessionListenerJavaConfigTests.java b/spring-session-docs/src/test/java/docs/http/HttpSessionListenerJavaConfigTests.java deleted file mode 100644 index e47bb696b..000000000 --- a/spring-session-docs/src/test/java/docs/http/HttpSessionListenerJavaConfigTests.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2014-2019 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 docs.http; - -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.data.redis.connection.RedisConnectionFactory; -import org.springframework.test.context.ContextConfiguration; - -/** - * @author Rob Winch - * - */ -@ContextConfiguration(classes = { HttpSessionListenerJavaConfigTests.MockConfig.class, RedisHttpSessionConfig.class }) -class HttpSessionListenerJavaConfigTests extends AbstractHttpSessionListenerTests { - - @Configuration - static class MockConfig { - - @Bean - static RedisConnectionFactory redisConnectionFactory() { - return AbstractHttpSessionListenerTests.createMockRedisConnection(); - } - - @Bean - SecuritySessionDestroyedListener securitySessionDestroyedListener() { - return new SecuritySessionDestroyedListener(); - } - - } - -} diff --git a/spring-session-docs/src/test/java/docs/http/HttpSessionListenerXmlTests.java b/spring-session-docs/src/test/java/docs/http/HttpSessionListenerXmlTests.java deleted file mode 100644 index c6c89d67c..000000000 --- a/spring-session-docs/src/test/java/docs/http/HttpSessionListenerXmlTests.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2014-2019 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 docs.http; - -import org.springframework.test.context.ContextConfiguration; - -/** - * @author Rob Winch - * - */ -@ContextConfiguration -class HttpSessionListenerXmlTests extends AbstractHttpSessionListenerTests { - -} diff --git a/spring-session-docs/src/test/java/docs/http/RedisHttpSessionConfig.java b/spring-session-docs/src/test/java/docs/http/RedisHttpSessionConfig.java deleted file mode 100644 index 85caeb48c..000000000 --- a/spring-session-docs/src/test/java/docs/http/RedisHttpSessionConfig.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright 2014-2019 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 docs.http; - -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.security.web.session.HttpSessionEventPublisher; -import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession; - -// tag::config[] -@Configuration -@EnableRedisHttpSession -public class RedisHttpSessionConfig { - - @Bean - public HttpSessionEventPublisher httpSessionEventPublisher() { - return new HttpSessionEventPublisher(); - } - - // ... - -} -// end::config[] diff --git a/spring-session-docs/src/test/java/docs/security/RememberMeSecurityConfiguration.java b/spring-session-docs/src/test/java/docs/security/RememberMeSecurityConfiguration.java deleted file mode 100644 index d8061e30e..000000000 --- a/spring-session-docs/src/test/java/docs/security/RememberMeSecurityConfiguration.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright 2014-2019 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 docs.security; - -import java.util.concurrent.ConcurrentHashMap; - -import org.springframework.context.annotation.Bean; -import org.springframework.security.config.Customizer; -import org.springframework.security.config.annotation.web.builders.HttpSecurity; -import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; -import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; -import org.springframework.security.core.userdetails.User; -import org.springframework.security.provisioning.InMemoryUserDetailsManager; -import org.springframework.session.MapSessionRepository; -import org.springframework.session.config.annotation.web.http.EnableSpringHttpSession; -import org.springframework.session.security.web.authentication.SpringSessionRememberMeServices; - -/** - * @author rwinch - */ -@EnableWebSecurity -@EnableSpringHttpSession -public class RememberMeSecurityConfiguration extends WebSecurityConfigurerAdapter { - - // @formatter:off - // tag::http-rememberme[] - @Override - protected void configure(HttpSecurity http) throws Exception { - http - // ... additional configuration ... - .rememberMe((rememberMe) -> rememberMe - .rememberMeServices(rememberMeServices()) - ); - // end::http-rememberme[] - - http - .formLogin(Customizer.withDefaults()) - .authorizeRequests((authorize) -> authorize - .anyRequest().authenticated() - ); - } - - // tag::rememberme-bean[] - @Bean - public SpringSessionRememberMeServices rememberMeServices() { - SpringSessionRememberMeServices rememberMeServices = - new SpringSessionRememberMeServices(); - // optionally customize - rememberMeServices.setAlwaysRemember(true); - return rememberMeServices; - } - // end::rememberme-bean[] - // @formatter:on - - @Override - @Bean - public InMemoryUserDetailsManager userDetailsService() { - return new InMemoryUserDetailsManager( - User.withUsername("user").password("{noop}password").roles("USER").build()); - } - - @Bean - MapSessionRepository sessionRepository() { - return new MapSessionRepository(new ConcurrentHashMap<>()); - } - -} -// end::class[] diff --git a/spring-session-docs/src/test/java/docs/security/RememberMeSecurityConfigurationTests.java b/spring-session-docs/src/test/java/docs/security/RememberMeSecurityConfigurationTests.java deleted file mode 100644 index f59afe07a..000000000 --- a/spring-session-docs/src/test/java/docs/security/RememberMeSecurityConfigurationTests.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright 2014-2019 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 docs.security; - -import java.time.Duration; -import java.util.Base64; - -import jakarta.servlet.http.Cookie; - -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.session.Session; -import org.springframework.session.SessionRepository; -import org.springframework.session.web.http.SessionRepositoryFilter; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit.jupiter.SpringExtension; -import org.springframework.test.context.web.WebAppConfiguration; -import org.springframework.test.web.servlet.MockMvc; -import org.springframework.test.web.servlet.MvcResult; -import org.springframework.test.web.servlet.setup.MockMvcBuilders; -import org.springframework.web.context.WebApplicationContext; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestBuilders.formLogin; -import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity; - -/** - * @author rwinch - * @author Vedran Pavic - */ -@ExtendWith(SpringExtension.class) -@ContextConfiguration(classes = RememberMeSecurityConfiguration.class) -@WebAppConfiguration -@SuppressWarnings("rawtypes") -class RememberMeSecurityConfigurationTests { - - @Autowired - WebApplicationContext context; - - @Autowired - SessionRepositoryFilter springSessionRepositoryFilter; - - @Autowired - SessionRepository sessions; - - private MockMvc mockMvc; - - @BeforeEach - void setup() { - // @formatter:off - this.mockMvc = MockMvcBuilders - .webAppContextSetup(this.context) - .addFilters(this.springSessionRepositoryFilter) - .apply(springSecurity()) - .build(); - // @formatter:on - } - - @Test - void authenticateWhenSpringSessionRememberMeEnabledThenCookieMaxAgeAndSessionExpirationSet() throws Exception { - // @formatter:off - MvcResult result = this.mockMvc - .perform(formLogin()) - .andReturn(); - // @formatter:on - - Cookie cookie = result.getResponse().getCookie("SESSION"); - assertThat(cookie.getMaxAge()).isEqualTo(Integer.MAX_VALUE); - T session = this.sessions.findById(new String(Base64.getDecoder().decode(cookie.getValue()))); - assertThat(session.getMaxInactiveInterval()).isEqualTo(Duration.ofDays(30)); - - } - -} -// end::class[] diff --git a/spring-session-docs/src/test/java/docs/security/RememberMeSecurityConfigurationXmlTests.java b/spring-session-docs/src/test/java/docs/security/RememberMeSecurityConfigurationXmlTests.java deleted file mode 100644 index 4977b3aae..000000000 --- a/spring-session-docs/src/test/java/docs/security/RememberMeSecurityConfigurationXmlTests.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright 2014-2019 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 docs.security; - -import java.time.Duration; -import java.util.Base64; - -import jakarta.servlet.http.Cookie; - -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.session.Session; -import org.springframework.session.SessionRepository; -import org.springframework.session.web.http.SessionRepositoryFilter; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit.jupiter.SpringExtension; -import org.springframework.test.context.web.WebAppConfiguration; -import org.springframework.test.web.servlet.MockMvc; -import org.springframework.test.web.servlet.MvcResult; -import org.springframework.test.web.servlet.setup.MockMvcBuilders; -import org.springframework.web.context.WebApplicationContext; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestBuilders.formLogin; -import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity; - -/** - * @author rwinch - * @author Vedran Pavic - */ -@ExtendWith(SpringExtension.class) -@ContextConfiguration -@WebAppConfiguration -@SuppressWarnings("rawtypes") -class RememberMeSecurityConfigurationXmlTests { - - @Autowired - WebApplicationContext context; - - @Autowired - SessionRepositoryFilter springSessionRepositoryFilter; - - @Autowired - SessionRepository sessions; - - private MockMvc mockMvc; - - @BeforeEach - void setup() { - // @formatter:off - this.mockMvc = MockMvcBuilders - .webAppContextSetup(this.context) - .addFilters(this.springSessionRepositoryFilter) - .apply(springSecurity()) - .build(); - // @formatter:on - } - - @Test - void authenticateWhenSpringSessionRememberMeEnabledThenCookieMaxAgeAndSessionExpirationSet() throws Exception { - // @formatter:off - MvcResult result = this.mockMvc - .perform(formLogin()) - .andReturn(); - // @formatter:on - - Cookie cookie = result.getResponse().getCookie("SESSION"); - assertThat(cookie.getMaxAge()).isEqualTo(Integer.MAX_VALUE); - T session = this.sessions.findById(new String(Base64.getDecoder().decode(cookie.getValue()))); - assertThat(session.getMaxInactiveInterval()).isEqualTo(Duration.ofDays(30)); - - } - -} -// end::class[] diff --git a/spring-session-docs/src/test/java/docs/security/SecurityConfiguration.java b/spring-session-docs/src/test/java/docs/security/SecurityConfiguration.java deleted file mode 100644 index a5498bd05..000000000 --- a/spring-session-docs/src/test/java/docs/security/SecurityConfiguration.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright 2014-2019 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 docs.security; - -import org.springframework.beans.factory.annotation.Autowired; -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.configuration.WebSecurityConfigurerAdapter; -import org.springframework.session.FindByIndexNameSessionRepository; -import org.springframework.session.Session; -import org.springframework.session.security.SpringSessionBackedSessionRegistry; - -/** - * @author Joris Kuipers - */ -// tag::class[] -@Configuration -public class SecurityConfiguration extends WebSecurityConfigurerAdapter { - - @Autowired - private FindByIndexNameSessionRepository sessionRepository; - - @Override - protected void configure(HttpSecurity http) throws Exception { - // @formatter:off - http - // other config goes here... - .sessionManagement((sessionManagement) -> sessionManagement - .maximumSessions(2) - .sessionRegistry(sessionRegistry()) - ); - // @formatter:on - } - - @Bean - public SpringSessionBackedSessionRegistry sessionRegistry() { - return new SpringSessionBackedSessionRegistry<>(this.sessionRepository); - } - -} -// end::class[] diff --git a/spring-session-docs/src/test/java/docs/websocket/WebSocketConfig.java b/spring-session-docs/src/test/java/docs/websocket/WebSocketConfig.java deleted file mode 100644 index 92e07ef50..000000000 --- a/spring-session-docs/src/test/java/docs/websocket/WebSocketConfig.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright 2014-2019 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 docs.websocket; - -import org.springframework.context.annotation.Configuration; -import org.springframework.messaging.simp.config.MessageBrokerRegistry; -import org.springframework.scheduling.annotation.EnableScheduling; -import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker; -import org.springframework.web.socket.config.annotation.StompEndpointRegistry; -import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer; - -/** - * @author Rob Winch - */ -// tag::class[] -@Configuration -@EnableScheduling -@EnableWebSocketMessageBroker -public class WebSocketConfig implements WebSocketMessageBrokerConfigurer { - - @Override - public void registerStompEndpoints(StompEndpointRegistry registry) { - registry.addEndpoint("/messages").withSockJS(); - } - - @Override - public void configureMessageBroker(MessageBrokerRegistry registry) { - registry.enableSimpleBroker("/queue/", "/topic/"); - registry.setApplicationDestinationPrefixes("/app"); - } - -} -// end::class[] diff --git a/spring-session-docs/src/test/resources/docs/HttpSessionConfigurationNoOpConfigureRedisActionXmlTests-context.xml b/spring-session-docs/src/test/resources/docs/HttpSessionConfigurationNoOpConfigureRedisActionXmlTests-context.xml deleted file mode 100644 index 631a86dd4..000000000 --- a/spring-session-docs/src/test/resources/docs/HttpSessionConfigurationNoOpConfigureRedisActionXmlTests-context.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - - - - - - diff --git a/spring-session-docs/src/test/resources/docs/http/HttpSessionListenerXmlTests-context.xml b/spring-session-docs/src/test/resources/docs/http/HttpSessionListenerXmlTests-context.xml deleted file mode 100644 index aafcaa6e7..000000000 --- a/spring-session-docs/src/test/resources/docs/http/HttpSessionListenerXmlTests-context.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - - - - - - - diff --git a/spring-session-docs/src/test/resources/docs/security/RememberMeSecurityConfigurationXmlTests-context.xml b/spring-session-docs/src/test/resources/docs/security/RememberMeSecurityConfigurationXmlTests-context.xml deleted file mode 100644 index 1996c58f7..000000000 --- a/spring-session-docs/src/test/resources/docs/security/RememberMeSecurityConfigurationXmlTests-context.xml +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/spring-session-docs/src/test/resources/docs/security/security-config.xml b/spring-session-docs/src/test/resources/docs/security/security-config.xml deleted file mode 100644 index 42a5a4a3d..000000000 --- a/spring-session-docs/src/test/resources/docs/security/security-config.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - - - - - - - - - -