From c70fc8378bd5e40dd3d60c8f09b6805b14956f7b Mon Sep 17 00:00:00 2001 From: Greg Turnquist Date: Wed, 2 Aug 2017 14:46:31 -0500 Subject: [PATCH] Polish --- src/main/asciidoc/guides/boot-mongo.adoc | 2 +- ...FindByIndexNameSessionRepositoryTests.java | 60 ------ ...ationNoOpConfigureRedisActionXmlTests.java | 51 ----- .../asciidoc/java/docs/IndexDocTests.java | 182 ------------------ ...gurationNoOpConfigureRedisActionTests.java | 61 ------ .../java/docs/SpringHttpSessionConfig.java | 33 ---- .../AbstractHttpSessionListenerTests.java | 88 --------- .../docs/http/HazelcastHttpSessionConfig.java | 53 ----- .../HttpSessionListenerJavaConfigTests.java | 45 ----- .../http/HttpSessionListenerXmlTests.java | 28 --- .../MongoJacksonSessionConfiguration.java | 48 ----- .../http/MongoJdkSessionConfiguration.java | 40 ---- .../java/docs/http/MyJacksonModule.java | 22 --- .../docs/http/RedisHttpSessionConfig.java | 36 ---- .../RememberMeSecurityConfiguration.java | 79 -------- .../RememberMeSecurityConfigurationTests.java | 90 --------- ...memberMeSecurityConfigurationXmlTests.java | 90 --------- .../docs/security/SecurityConfiguration.java | 52 ----- .../java/docs/websocket/WebSocketConfig.java | 45 ----- 19 files changed, 1 insertion(+), 1104 deletions(-) delete mode 100644 src/main/asciidoc/java/docs/FindByIndexNameSessionRepositoryTests.java delete mode 100644 src/main/asciidoc/java/docs/HttpSessionConfigurationNoOpConfigureRedisActionXmlTests.java delete mode 100644 src/main/asciidoc/java/docs/IndexDocTests.java delete mode 100644 src/main/asciidoc/java/docs/RedisHttpSessionConfigurationNoOpConfigureRedisActionTests.java delete mode 100644 src/main/asciidoc/java/docs/SpringHttpSessionConfig.java delete mode 100644 src/main/asciidoc/java/docs/http/AbstractHttpSessionListenerTests.java delete mode 100644 src/main/asciidoc/java/docs/http/HazelcastHttpSessionConfig.java delete mode 100644 src/main/asciidoc/java/docs/http/HttpSessionListenerJavaConfigTests.java delete mode 100644 src/main/asciidoc/java/docs/http/HttpSessionListenerXmlTests.java delete mode 100644 src/main/asciidoc/java/docs/http/MongoJacksonSessionConfiguration.java delete mode 100644 src/main/asciidoc/java/docs/http/MongoJdkSessionConfiguration.java delete mode 100644 src/main/asciidoc/java/docs/http/MyJacksonModule.java delete mode 100644 src/main/asciidoc/java/docs/http/RedisHttpSessionConfig.java delete mode 100644 src/main/asciidoc/java/docs/security/RememberMeSecurityConfiguration.java delete mode 100644 src/main/asciidoc/java/docs/security/RememberMeSecurityConfigurationTests.java delete mode 100644 src/main/asciidoc/java/docs/security/RememberMeSecurityConfigurationXmlTests.java delete mode 100644 src/main/asciidoc/java/docs/security/SecurityConfiguration.java delete mode 100644 src/main/asciidoc/java/docs/websocket/WebSocketConfig.java diff --git a/src/main/asciidoc/guides/boot-mongo.adoc b/src/main/asciidoc/guides/boot-mongo.adoc index ac63ee0..e528145 100644 --- a/src/main/asciidoc/guides/boot-mongo.adoc +++ b/src/main/asciidoc/guides/boot-mongo.adoc @@ -74,7 +74,7 @@ All you have to do is to add the following Spring Configuration: [source,java] ---- -include::{samples-dir}/spring-session-data-mongodb-traditional-boot/src/main/java/sample/config/HttpSessionConfig.java[tag=class] +include::{samples-dir}/spring-session-data-mongodb-traditional-boot/src/main/java/org/springframework/session/mongodb/examples/config/HttpSessionConfig.java[tag=class] ---- <1> The `@EnableMongoHttpSession` annotation creates a Spring Bean with the name of `springSessionRepositoryFilter` that implements Filter. diff --git a/src/main/asciidoc/java/docs/FindByIndexNameSessionRepositoryTests.java b/src/main/asciidoc/java/docs/FindByIndexNameSessionRepositoryTests.java deleted file mode 100644 index c574b11..0000000 --- a/src/main/asciidoc/java/docs/FindByIndexNameSessionRepositoryTests.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright 2014-2017 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 - * - * http://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.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; - -import org.springframework.session.FindByIndexNameSessionRepository; -import org.springframework.session.Session; - -/** - * @author Rob Winch - * - */ -@RunWith(MockitoJUnitRunner.class) -public class FindByIndexNameSessionRepositoryTests { - @Mock - FindByIndexNameSessionRepository sessionRepository; - @Mock - Session session; - - @Test - public void setUsername() { - // tag::set-username[] - String username = "username"; - this.session.setAttribute( - FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME, username); - // end::set-username[] - } - - @Test - @SuppressWarnings("unused") - public void findByUsername() { - // tag::findby-username[] - String username = "username"; - Map sessionIdToSession = this.sessionRepository - .findByIndexNameAndIndexValue( - FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME, - username); - // end::findby-username[] - } -} diff --git a/src/main/asciidoc/java/docs/HttpSessionConfigurationNoOpConfigureRedisActionXmlTests.java b/src/main/asciidoc/java/docs/HttpSessionConfigurationNoOpConfigureRedisActionXmlTests.java deleted file mode 100644 index 9b4d33c..0000000 --- a/src/main/asciidoc/java/docs/HttpSessionConfigurationNoOpConfigureRedisActionXmlTests.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2014-2016 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 - * - * http://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.Test; -import org.junit.runner.RunWith; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.redis.connection.RedisConnectionFactory; -import org.springframework.session.ExpiringSession; -import org.springframework.session.web.http.SessionRepositoryFilter; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.test.context.web.WebAppConfiguration; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; - -/** - * @author Rob Winch - */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration -@WebAppConfiguration -public class HttpSessionConfigurationNoOpConfigureRedisActionXmlTests { - @Autowired - SessionRepositoryFilter filter; - - @Test - public void redisConnectionFactoryNotUsedSinceNoValidation() { - assertThat(this.filter).isNotNull(); - } - - static RedisConnectionFactory connectionFactory() { - return mock(RedisConnectionFactory.class); - } -} diff --git a/src/main/asciidoc/java/docs/IndexDocTests.java b/src/main/asciidoc/java/docs/IndexDocTests.java deleted file mode 100644 index af2b874..0000000 --- a/src/main/asciidoc/java/docs/IndexDocTests.java +++ /dev/null @@ -1,182 +0,0 @@ -/* - * Copyright 2014-2016 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 - * - * http://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 com.hazelcast.config.Config; -import com.hazelcast.core.Hazelcast; -import com.hazelcast.core.HazelcastInstance; -import com.hazelcast.core.IMap; -import org.junit.Test; - -import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; -import org.springframework.jdbc.core.JdbcTemplate; -import org.springframework.jdbc.datasource.DataSourceTransactionManager; -import org.springframework.mock.web.MockServletContext; -import org.springframework.session.ExpiringSession; -import org.springframework.session.MapSession; -import org.springframework.session.MapSessionRepository; -import org.springframework.session.Session; -import org.springframework.session.SessionRepository; -import org.springframework.session.data.redis.RedisOperationsSessionRepository; -import org.springframework.session.hazelcast.HazelcastSessionRepository; -import org.springframework.session.jdbc.JdbcOperationsSessionRepository; -import org.springframework.session.web.http.SessionRepositoryFilter; -import org.springframework.transaction.PlatformTransactionManager; -import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * @author Rob Winch - * @author Vedran Pavic - */ -public class IndexDocTests { - static final String ATTR_USER = "user"; - - @Test - public void repositoryDemo() { - RepositoryDemo demo = new RepositoryDemo(); - demo.repository = new MapSessionRepository(); - - 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.getSession(toSave.getId()); // <5> - - // <6> - User user = session.getAttribute(ATTR_USER); - assertThat(user).isEqualTo(rwinch); - } - - // ... setter methods ... - } - // end::repository-demo[] - - @Test - public void expireRepositoryDemo() { - ExpiringRepositoryDemo demo = new ExpiringRepositoryDemo(); - demo.repository = new MapSessionRepository(); - - demo.demo(); - } - - // tag::expire-repository-demo[] - public class ExpiringRepositoryDemo { - private SessionRepository repository; // <1> - - public void demo() { - S toSave = this.repository.createSession(); // <2> - // ... - toSave.setMaxInactiveIntervalInSeconds(30); // <3> - - this.repository.save(toSave); // <4> - - S session = this.repository.getSession(toSave.getId()); // <5> - // ... - } - - // ... setter methods ... - } - // end::expire-repository-demo[] - - @Test - @SuppressWarnings("unused") - public void newRedisOperationsSessionRepository() { - // tag::new-redisoperationssessionrepository[] - LettuceConnectionFactory factory = new LettuceConnectionFactory(); - SessionRepository repository = new RedisOperationsSessionRepository( - factory); - // end::new-redisoperationssessionrepository[] - } - - @Test - @SuppressWarnings("unused") - public void mapRepository() { - // tag::new-mapsessionrepository[] - SessionRepository repository = new MapSessionRepository(); - // end::new-mapsessionrepository[] - } - - @Test - @SuppressWarnings("unused") - public void newJdbcOperationsSessionRepository() { - // tag::new-jdbcoperationssessionrepository[] - JdbcTemplate jdbcTemplate = new JdbcTemplate(); - - // ... configure JdbcTemplate ... - - PlatformTransactionManager transactionManager = new DataSourceTransactionManager(); - - // ... configure transactionManager ... - - SessionRepository repository = - new JdbcOperationsSessionRepository(jdbcTemplate, transactionManager); - // end::new-jdbcoperationssessionrepository[] - } - - @Test - @SuppressWarnings("unused") - public void newHazelcastSessionRepository() { - // tag::new-hazelcastsessionrepository[] - - Config config = new Config(); - - // ... configure Hazelcast ... - - HazelcastInstance hazelcastInstance = Hazelcast.newHazelcastInstance(config); - - IMap sessions = hazelcastInstance - .getMap("spring:session:sessions"); - - HazelcastSessionRepository repository = - new HazelcastSessionRepository(sessions); - // end::new-hazelcastsessionrepository[] - } - - @Test - public 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/src/main/asciidoc/java/docs/RedisHttpSessionConfigurationNoOpConfigureRedisActionTests.java b/src/main/asciidoc/java/docs/RedisHttpSessionConfigurationNoOpConfigureRedisActionTests.java deleted file mode 100644 index 21fa560..0000000 --- a/src/main/asciidoc/java/docs/RedisHttpSessionConfigurationNoOpConfigureRedisActionTests.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright 2014-2016 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 - * - * http://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.Test; -import org.junit.runner.RunWith; - -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.junit4.SpringJUnit4ClassRunner; -import org.springframework.test.context.web.WebAppConfiguration; - -import static org.mockito.Mockito.mock; - -/** - * @author Rob Winch - */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration -@WebAppConfiguration -public class RedisHttpSessionConfigurationNoOpConfigureRedisActionTests { - - @Test - public void redisConnectionFactoryNotUsedSinceNoValidation() { - } - - @EnableRedisHttpSession - @Configuration - static class Config { - - // tag::configure-redis-action[] - @Bean - public static ConfigureRedisAction configureRedisAction() { - return ConfigureRedisAction.NO_OP; - } - // end::configure-redis-action[] - - @Bean - public RedisConnectionFactory redisConnectionFactory() { - return mock(RedisConnectionFactory.class); - } - } -} diff --git a/src/main/asciidoc/java/docs/SpringHttpSessionConfig.java b/src/main/asciidoc/java/docs/SpringHttpSessionConfig.java deleted file mode 100644 index 30694cd..0000000 --- a/src/main/asciidoc/java/docs/SpringHttpSessionConfig.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2014-2016 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 - * - * http://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.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(); - } -} -// end::class[] diff --git a/src/main/asciidoc/java/docs/http/AbstractHttpSessionListenerTests.java b/src/main/asciidoc/java/docs/http/AbstractHttpSessionListenerTests.java deleted file mode 100644 index 7ea8fb7..0000000 --- a/src/main/asciidoc/java/docs/http/AbstractHttpSessionListenerTests.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright 2014-2016 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 - * - * http://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.junit.Test; -import org.junit.runner.RunWith; - -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.junit4.SpringJUnit4ClassRunner; -import org.springframework.test.context.web.WebAppConfiguration; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.mock; - -/** - * @author Rob Winch - * @since 1.2 - */ -@RunWith(SpringJUnit4ClassRunner.class) -@WebAppConfiguration -public abstract class AbstractHttpSessionListenerTests { - @Autowired - ApplicationEventPublisher publisher; - - @Autowired - SecuritySessionDestroyedListener listener; - - @Test - public 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); - return factory; - } - - static class SecuritySessionDestroyedListener - implements ApplicationListener { - - private SessionDestroyedEvent event; - - /* - * (non-Javadoc) - * - * @see org.springframework.context.ApplicationListener#onApplicationEvent(org. - * springframework.context.ApplicationEvent) - */ - public void onApplicationEvent(SessionDestroyedEvent event) { - this.event = event; - } - - public SessionDestroyedEvent getEvent() { - return this.event; - } - } -} diff --git a/src/main/asciidoc/java/docs/http/HazelcastHttpSessionConfig.java b/src/main/asciidoc/java/docs/http/HazelcastHttpSessionConfig.java deleted file mode 100644 index 2075bd6..0000000 --- a/src/main/asciidoc/java/docs/http/HazelcastHttpSessionConfig.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright 2014-2016 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 - * - * http://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.core.Hazelcast; -import com.hazelcast.core.HazelcastInstance; - -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.session.hazelcast.HazelcastSessionRepository; -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() { - MapAttributeConfig attributeConfig = new MapAttributeConfig() - .setName(HazelcastSessionRepository.PRINCIPAL_NAME_ATTRIBUTE) - .setExtractor(PrincipalNameExtractor.class.getName()); - - Config config = new Config(); - - config.getMapConfig("spring:session:sessions") // <2> - .addMapAttributeConfig(attributeConfig) - .addMapIndexConfig(new MapIndexConfig( - HazelcastSessionRepository.PRINCIPAL_NAME_ATTRIBUTE, false)); - - return Hazelcast.newHazelcastInstance(config); // <3> - } - -} -// end::config[] diff --git a/src/main/asciidoc/java/docs/http/HttpSessionListenerJavaConfigTests.java b/src/main/asciidoc/java/docs/http/HttpSessionListenerJavaConfigTests.java deleted file mode 100644 index f051976..0000000 --- a/src/main/asciidoc/java/docs/http/HttpSessionListenerJavaConfigTests.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2014-2016 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 - * - * http://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 }) -public class HttpSessionListenerJavaConfigTests extends AbstractHttpSessionListenerTests { - - @Configuration - static class MockConfig { - - @Bean - public static RedisConnectionFactory redisConnectionFactory() { - return AbstractHttpSessionListenerTests.createMockRedisConnection(); - } - - @Bean - public SecuritySessionDestroyedListener securitySessionDestroyedListener() { - return new SecuritySessionDestroyedListener(); - } - } -} diff --git a/src/main/asciidoc/java/docs/http/HttpSessionListenerXmlTests.java b/src/main/asciidoc/java/docs/http/HttpSessionListenerXmlTests.java deleted file mode 100644 index aa359e2..0000000 --- a/src/main/asciidoc/java/docs/http/HttpSessionListenerXmlTests.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2014-2016 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 - * - * http://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 -public class HttpSessionListenerXmlTests extends AbstractHttpSessionListenerTests { - -} diff --git a/src/main/asciidoc/java/docs/http/MongoJacksonSessionConfiguration.java b/src/main/asciidoc/java/docs/http/MongoJacksonSessionConfiguration.java deleted file mode 100644 index 8995af5..0000000 --- a/src/main/asciidoc/java/docs/http/MongoJacksonSessionConfiguration.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 2014-2016 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 - * - * http://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.Collections; - -import com.fasterxml.jackson.databind.Module; - -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.session.data.mongo.AbstractMongoSessionConverter; -import org.springframework.session.data.mongo.JacksonMongoSessionConverter; -import org.springframework.session.data.mongo.config.annotation.web.http.EnableMongoHttpSession; - -/** - * - * @author Jakub Kubrynski - * @author Rob Winch - */ -// tag::config[] -@Configuration -@EnableMongoHttpSession -public class MongoJacksonSessionConfiguration { - - @Bean - public AbstractMongoSessionConverter mongoSessionConverter() { - return new JacksonMongoSessionConverter(getJacksonModules()); - } - - public Iterable getJacksonModules() { - return Collections.singletonList(new MyJacksonModule()); - } -} -// end::config[] diff --git a/src/main/asciidoc/java/docs/http/MongoJdkSessionConfiguration.java b/src/main/asciidoc/java/docs/http/MongoJdkSessionConfiguration.java deleted file mode 100644 index 42a6efd..0000000 --- a/src/main/asciidoc/java/docs/http/MongoJdkSessionConfiguration.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2014-2016 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 - * - * http://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.session.data.mongo.AbstractMongoSessionConverter; -import org.springframework.session.data.mongo.JdkMongoSessionConverter; -import org.springframework.session.data.mongo.config.annotation.web.http.EnableMongoHttpSession; - -/** - * - * @author Jakub Kubrynski - * @author Rob Winch - */ -// tag::config[] -@Configuration -@EnableMongoHttpSession -public class MongoJdkSessionConfiguration { - - @Bean - public AbstractMongoSessionConverter mongoSessionConverter() { - return new JdkMongoSessionConverter(); - } -} -// end::config[] diff --git a/src/main/asciidoc/java/docs/http/MyJacksonModule.java b/src/main/asciidoc/java/docs/http/MyJacksonModule.java deleted file mode 100644 index bc2ce89..0000000 --- a/src/main/asciidoc/java/docs/http/MyJacksonModule.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright 2014-2016 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 - * - * http://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.fasterxml.jackson.databind.module.SimpleModule; - -class MyJacksonModule extends SimpleModule { -} diff --git a/src/main/asciidoc/java/docs/http/RedisHttpSessionConfig.java b/src/main/asciidoc/java/docs/http/RedisHttpSessionConfig.java deleted file mode 100644 index 948de07..0000000 --- a/src/main/asciidoc/java/docs/http/RedisHttpSessionConfig.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright 2014-2016 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 - * - * http://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/src/main/asciidoc/java/docs/security/RememberMeSecurityConfiguration.java b/src/main/asciidoc/java/docs/security/RememberMeSecurityConfiguration.java deleted file mode 100644 index 3f24333..0000000 --- a/src/main/asciidoc/java/docs/security/RememberMeSecurityConfiguration.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright 2014-2016 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 - * - * http://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.context.annotation.Bean; -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.security.web.authentication.RememberMeServices; -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() - .rememberMeServices(rememberMeServices()); - // end::http-rememberme[] - - http - .formLogin().and() - .authorizeRequests() - .anyRequest().authenticated(); - } - - // tag::rememberme-bean[] - @Bean - RememberMeServices rememberMeServices() { - SpringSessionRememberMeServices rememberMeServices = - new SpringSessionRememberMeServices(); - // optionally customize - rememberMeServices.setAlwaysRemember(true); - return rememberMeServices; - } - // end::rememberme-bean[] - // @formatter:on - - @Override - @Bean - public InMemoryUserDetailsManager userDetailsService() { - InMemoryUserDetailsManager uds = new InMemoryUserDetailsManager(); - uds.createUser( - User.withUsername("user").password("password").roles("USER").build()); - return uds; - } - - @Bean - MapSessionRepository sessionRepository() { - return new MapSessionRepository(); - } -} -// end::class[] diff --git a/src/main/asciidoc/java/docs/security/RememberMeSecurityConfigurationTests.java b/src/main/asciidoc/java/docs/security/RememberMeSecurityConfigurationTests.java deleted file mode 100644 index 2b45cac..0000000 --- a/src/main/asciidoc/java/docs/security/RememberMeSecurityConfigurationTests.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright 2014-2017 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 - * - * http://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.Base64; -import java.util.concurrent.TimeUnit; - -import javax.servlet.http.Cookie; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.session.ExpiringSession; -import org.springframework.session.SessionRepository; -import org.springframework.session.web.http.SessionRepositoryFilter; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -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 - */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = RememberMeSecurityConfiguration.class) -@WebAppConfiguration -@SuppressWarnings("rawtypes") -public class RememberMeSecurityConfigurationTests { - @Autowired - WebApplicationContext context; - @Autowired - SessionRepositoryFilter springSessionRepositoryFilter; - @Autowired - SessionRepository sessions; - - MockMvc mockMvc; - - @Before - public void setup() { - // @formatter:off - this.mockMvc = MockMvcBuilders - .webAppContextSetup(this.context) - .addFilters(this.springSessionRepositoryFilter) - .apply(springSecurity()) - .build(); - // @formatter:on - } - - @Test - public 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 - .getSession(new String(Base64.getDecoder().decode(cookie.getValue()))); - assertThat(session.getMaxInactiveIntervalInSeconds()) - .isEqualTo((int) TimeUnit.DAYS.toSeconds(30)); - - } -} -// end::class[] diff --git a/src/main/asciidoc/java/docs/security/RememberMeSecurityConfigurationXmlTests.java b/src/main/asciidoc/java/docs/security/RememberMeSecurityConfigurationXmlTests.java deleted file mode 100644 index 982bf05..0000000 --- a/src/main/asciidoc/java/docs/security/RememberMeSecurityConfigurationXmlTests.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright 2014-2017 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 - * - * http://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.Base64; -import java.util.concurrent.TimeUnit; - -import javax.servlet.http.Cookie; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.session.ExpiringSession; -import org.springframework.session.SessionRepository; -import org.springframework.session.web.http.SessionRepositoryFilter; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -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 - */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration -@WebAppConfiguration -@SuppressWarnings("rawtypes") -public class RememberMeSecurityConfigurationXmlTests { - @Autowired - WebApplicationContext context; - @Autowired - SessionRepositoryFilter springSessionRepositoryFilter; - @Autowired - SessionRepository sessions; - - MockMvc mockMvc; - - @Before - public void setup() { - // @formatter:off - this.mockMvc = MockMvcBuilders - .webAppContextSetup(this.context) - .addFilters(this.springSessionRepositoryFilter) - .apply(springSecurity()) - .build(); - // @formatter:on - } - - @Test - public 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 - .getSession(new String(Base64.getDecoder().decode(cookie.getValue()))); - assertThat(session.getMaxInactiveIntervalInSeconds()) - .isEqualTo((int) TimeUnit.DAYS.toSeconds(30)); - - } -} -// end::class[] diff --git a/src/main/asciidoc/java/docs/security/SecurityConfiguration.java b/src/main/asciidoc/java/docs/security/SecurityConfiguration.java deleted file mode 100644 index 8bc3512..0000000 --- a/src/main/asciidoc/java/docs/security/SecurityConfiguration.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright 2014-2016 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 - * - * http://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.ExpiringSession; -import org.springframework.session.FindByIndexNameSessionRepository; -import org.springframework.session.security.SpringSessionBackedSessionRegistry; - -/** - * @author Joris Kuipers - */ -// tag::class[] -@Configuration -public class SecurityConfiguration extends WebSecurityConfigurerAdapter { - - @Autowired - FindByIndexNameSessionRepository sessionRepository; - - @Override - protected void configure(HttpSecurity http) throws Exception { - http - // other config goes here... - .sessionManagement() - .maximumSessions(2) - .sessionRegistry(sessionRegistry()); - } - - @Bean - SpringSessionBackedSessionRegistry sessionRegistry() { - return new SpringSessionBackedSessionRegistry(this.sessionRepository); - } -} -// end::class[] diff --git a/src/main/asciidoc/java/docs/websocket/WebSocketConfig.java b/src/main/asciidoc/java/docs/websocket/WebSocketConfig.java deleted file mode 100644 index b4c168a..0000000 --- a/src/main/asciidoc/java/docs/websocket/WebSocketConfig.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2014-2016 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 - * - * http://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.AbstractWebSocketMessageBrokerConfigurer; -import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker; -import org.springframework.web.socket.config.annotation.StompEndpointRegistry; - -/** - * @author Rob Winch - */ -// tag::class[] -@Configuration -@EnableScheduling -@EnableWebSocketMessageBroker -public class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer { - - public void registerStompEndpoints(StompEndpointRegistry registry) { - registry.addEndpoint("/messages").withSockJS(); - } - - @Override - public void configureMessageBroker(MessageBrokerRegistry registry) { - registry.enableSimpleBroker("/queue/", "/topic/"); - registry.setApplicationDestinationPrefixes("/app"); - } -} -// end::class[]