Skip to content

Commit 26419e2

Browse files
committed
Cleanup Antora
1 parent faa6c44 commit 26419e2

File tree

53 files changed

+2552
-1359
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+2552
-1359
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ buildscript {
44
snapshotBuild = version.endsWith('SNAPSHOT')
55
milestoneBuild = !(releaseBuild || snapshotBuild)
66

7-
springBootVersion = '2.5.3'
7+
springBootVersion = '2.4.5'
88
}
99

1010
repositories {

gradle/dependency-management.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
dependencyManagement {
22
imports {
3-
mavenBom 'io.projectreactor:reactor-bom:2020.0.10'
3+
mavenBom 'io.projectreactor:reactor-bom:2020.0.7'
44
mavenBom 'org.junit:junit-bom:5.7.2'
5-
mavenBom 'org.springframework:spring-framework-bom:5.3.9'
6-
mavenBom 'org.springframework.data:spring-data-bom:2021.1.0-M2'
5+
mavenBom 'org.springframework:spring-framework-bom:5.3.7'
6+
mavenBom 'org.springframework.data:spring-data-bom:2021.0.1'
77
mavenBom 'org.springframework.security:spring-security-bom:5.5.0'
88
mavenBom 'org.testcontainers:testcontainers-bom:1.15.3'
99
}

spring-session-docs/antora.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,22 @@ asciidoc:
77
page-pagination: true
88
idprefix: ''
99
idseparator: '-'
10+
download-url: "https://github.com/spring-projects/spring-session/archive/main.zip"
11+
gh-samples-url: "https://github.com/spring-projects/spring-session/tree/main/spring-session-samples/"
12+
samples-dir: "example$spring-session-samples/"
13+
session-jdbc-main-resources-dir: "example$session-jdbc-main-resources-dir/"
14+
docs-test-dir: "example$java/"
15+
websocketdoc-test-dir: 'example$java/docs/websocket/'
16+
docs-test-resources-dir: "example$resources/"
17+
indexdoc-tests: "example$java/docs/IndexDocTests.java"
18+
lettuce-version: 6.1.2.RELEASE
19+
hazelcast-version: 3.12.12
20+
spring-boot-version: 2.4.5
21+
spring-data-redis-version: 2.5.1
22+
spring-framework-version: 5.3.7
23+
spring-security-version: 5.5.0
24+
spring-session-version: 2.6.0-SNAPSHOT
25+
26+
1027
nav:
1128
- modules/ROOT/nav.adoc
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Copyright 2014-2019 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package docs;
18+
19+
import java.util.Map;
20+
21+
import org.junit.jupiter.api.BeforeEach;
22+
import org.junit.jupiter.api.Test;
23+
import org.mockito.Mock;
24+
import org.mockito.MockitoAnnotations;
25+
26+
import org.springframework.session.FindByIndexNameSessionRepository;
27+
import org.springframework.session.Session;
28+
29+
/**
30+
* @author Rob Winch
31+
*
32+
*/
33+
class FindByIndexNameSessionRepositoryTests {
34+
35+
@Mock
36+
FindByIndexNameSessionRepository<Session> sessionRepository;
37+
38+
@Mock
39+
Session session;
40+
41+
@BeforeEach
42+
void setUp() {
43+
MockitoAnnotations.initMocks(this);
44+
}
45+
46+
@Test
47+
void setUsername() {
48+
// tag::set-username[]
49+
String username = "username";
50+
this.session.setAttribute(FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME, username);
51+
// end::set-username[]
52+
}
53+
54+
@Test
55+
@SuppressWarnings("unused")
56+
void findByUsername() {
57+
// tag::findby-username[]
58+
String username = "username";
59+
Map<String, Session> sessionIdToSession = this.sessionRepository.findByPrincipalName(username);
60+
// end::findby-username[]
61+
}
62+
63+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright 2014-2019 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package docs;
18+
19+
import org.junit.jupiter.api.Test;
20+
import org.junit.jupiter.api.extension.ExtendWith;
21+
22+
import org.springframework.beans.factory.annotation.Autowired;
23+
import org.springframework.data.redis.connection.RedisConnectionFactory;
24+
import org.springframework.session.Session;
25+
import org.springframework.session.web.http.SessionRepositoryFilter;
26+
import org.springframework.test.context.ContextConfiguration;
27+
import org.springframework.test.context.junit.jupiter.SpringExtension;
28+
import org.springframework.test.context.web.WebAppConfiguration;
29+
30+
import static org.assertj.core.api.Assertions.assertThat;
31+
import static org.mockito.Mockito.mock;
32+
33+
/**
34+
* @author Rob Winch
35+
*/
36+
@ExtendWith(SpringExtension.class)
37+
@ContextConfiguration
38+
@WebAppConfiguration
39+
public class HttpSessionConfigurationNoOpConfigureRedisActionXmlTests {
40+
41+
@Autowired
42+
SessionRepositoryFilter<? extends Session> filter;
43+
44+
@Test
45+
void redisConnectionFactoryNotUsedSinceNoValidation() {
46+
assertThat(this.filter).isNotNull();
47+
}
48+
49+
static RedisConnectionFactory connectionFactory() {
50+
return mock(RedisConnectionFactory.class);
51+
}
52+
53+
}
Lines changed: 211 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,211 @@
1+
/*
2+
* Copyright 2014-2019 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package docs;
18+
19+
import java.time.Duration;
20+
import java.util.concurrent.ConcurrentHashMap;
21+
22+
import com.hazelcast.config.Config;
23+
import com.hazelcast.core.Hazelcast;
24+
import com.hazelcast.core.HazelcastInstance;
25+
import org.junit.jupiter.api.Test;
26+
27+
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
28+
import org.springframework.data.redis.core.ReactiveRedisTemplate;
29+
import org.springframework.data.redis.core.RedisTemplate;
30+
import org.springframework.data.redis.serializer.JdkSerializationRedisSerializer;
31+
import org.springframework.data.redis.serializer.RedisSerializationContext;
32+
import org.springframework.jdbc.core.JdbcTemplate;
33+
import org.springframework.mock.web.MockServletContext;
34+
import org.springframework.session.MapSession;
35+
import org.springframework.session.MapSessionRepository;
36+
import org.springframework.session.ReactiveSessionRepository;
37+
import org.springframework.session.Session;
38+
import org.springframework.session.SessionRepository;
39+
import org.springframework.session.data.redis.ReactiveRedisSessionRepository;
40+
import org.springframework.session.data.redis.RedisIndexedSessionRepository;
41+
import org.springframework.session.hazelcast.HazelcastIndexedSessionRepository;
42+
import org.springframework.session.jdbc.JdbcIndexedSessionRepository;
43+
import org.springframework.session.web.http.SessionRepositoryFilter;
44+
import org.springframework.transaction.support.TransactionTemplate;
45+
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
46+
47+
import static org.assertj.core.api.Assertions.assertThat;
48+
49+
/**
50+
* @author Rob Winch
51+
* @author Vedran Pavic
52+
*/
53+
class IndexDocTests {
54+
55+
private static final String ATTR_USER = "user";
56+
57+
@Test
58+
void repositoryDemo() {
59+
RepositoryDemo<MapSession> demo = new RepositoryDemo<>();
60+
demo.repository = new MapSessionRepository(new ConcurrentHashMap<>());
61+
62+
demo.demo();
63+
}
64+
65+
// tag::repository-demo[]
66+
public class RepositoryDemo<S extends Session> {
67+
68+
private SessionRepository<S> repository; // <1>
69+
70+
public void demo() {
71+
S toSave = this.repository.createSession(); // <2>
72+
73+
// <3>
74+
User rwinch = new User("rwinch");
75+
toSave.setAttribute(ATTR_USER, rwinch);
76+
77+
this.repository.save(toSave); // <4>
78+
79+
S session = this.repository.findById(toSave.getId()); // <5>
80+
81+
// <6>
82+
User user = session.getAttribute(ATTR_USER);
83+
assertThat(user).isEqualTo(rwinch);
84+
}
85+
86+
// ... setter methods ...
87+
88+
}
89+
// end::repository-demo[]
90+
91+
@Test
92+
void expireRepositoryDemo() {
93+
ExpiringRepositoryDemo<MapSession> demo = new ExpiringRepositoryDemo<>();
94+
demo.repository = new MapSessionRepository(new ConcurrentHashMap<>());
95+
96+
demo.demo();
97+
}
98+
99+
// tag::expire-repository-demo[]
100+
public class ExpiringRepositoryDemo<S extends Session> {
101+
102+
private SessionRepository<S> repository; // <1>
103+
104+
public void demo() {
105+
S toSave = this.repository.createSession(); // <2>
106+
// ...
107+
toSave.setMaxInactiveInterval(Duration.ofSeconds(30)); // <3>
108+
109+
this.repository.save(toSave); // <4>
110+
111+
S session = this.repository.findById(toSave.getId()); // <5>
112+
// ...
113+
}
114+
115+
// ... setter methods ...
116+
117+
}
118+
// end::expire-repository-demo[]
119+
120+
@Test
121+
@SuppressWarnings("unused")
122+
void newRedisIndexedSessionRepository() {
123+
// tag::new-redisindexedsessionrepository[]
124+
RedisTemplate<Object, Object> redisTemplate = new RedisTemplate<>();
125+
126+
// ... configure redisTemplate ...
127+
128+
SessionRepository<? extends Session> repository = new RedisIndexedSessionRepository(redisTemplate);
129+
// end::new-redisindexedsessionrepository[]
130+
}
131+
132+
@Test
133+
@SuppressWarnings("unused")
134+
void newReactiveRedisSessionRepository() {
135+
LettuceConnectionFactory connectionFactory = new LettuceConnectionFactory();
136+
RedisSerializationContext<String, Object> serializationContext = RedisSerializationContext
137+
.<String, Object>newSerializationContext(new JdkSerializationRedisSerializer()).build();
138+
139+
// tag::new-reactiveredissessionrepository[]
140+
// ... create and configure connectionFactory and serializationContext ...
141+
142+
ReactiveRedisTemplate<String, Object> redisTemplate = new ReactiveRedisTemplate<>(connectionFactory,
143+
serializationContext);
144+
145+
ReactiveSessionRepository<? extends Session> repository = new ReactiveRedisSessionRepository(redisTemplate);
146+
// end::new-reactiveredissessionrepository[]
147+
}
148+
149+
@Test
150+
@SuppressWarnings("unused")
151+
void mapRepository() {
152+
// tag::new-mapsessionrepository[]
153+
SessionRepository<? extends Session> repository = new MapSessionRepository(new ConcurrentHashMap<>());
154+
// end::new-mapsessionrepository[]
155+
}
156+
157+
@Test
158+
@SuppressWarnings("unused")
159+
void newJdbcIndexedSessionRepository() {
160+
// tag::new-jdbcindexedsessionrepository[]
161+
JdbcTemplate jdbcTemplate = new JdbcTemplate();
162+
163+
// ... configure jdbcTemplate ...
164+
165+
TransactionTemplate transactionTemplate = new TransactionTemplate();
166+
167+
// ... configure transactionTemplate ...
168+
169+
SessionRepository<? extends Session> repository = new JdbcIndexedSessionRepository(jdbcTemplate,
170+
transactionTemplate);
171+
// end::new-jdbcindexedsessionrepository[]
172+
}
173+
174+
@Test
175+
@SuppressWarnings("unused")
176+
void newHazelcastIndexedSessionRepository() {
177+
// tag::new-hazelcastindexedsessionrepository[]
178+
179+
Config config = new Config();
180+
181+
// ... configure Hazelcast ...
182+
183+
HazelcastInstance hazelcastInstance = Hazelcast.newHazelcastInstance(config);
184+
185+
HazelcastIndexedSessionRepository repository = new HazelcastIndexedSessionRepository(hazelcastInstance);
186+
// end::new-hazelcastindexedsessionrepository[]
187+
}
188+
189+
@Test
190+
void runSpringHttpSessionConfig() {
191+
AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
192+
context.register(SpringHttpSessionConfig.class);
193+
context.setServletContext(new MockServletContext());
194+
context.refresh();
195+
196+
try {
197+
context.getBean(SessionRepositoryFilter.class);
198+
}
199+
finally {
200+
context.close();
201+
}
202+
}
203+
204+
private static final class User {
205+
206+
private User(String username) {
207+
}
208+
209+
}
210+
211+
}

0 commit comments

Comments
 (0)