Skip to content

Commit c7d54c8

Browse files
committed
Polish
1 parent 8ad14ae commit c7d54c8

File tree

5 files changed

+47
-38
lines changed

5 files changed

+47
-38
lines changed

spring-web/src/main/java/org/springframework/web/server/session/DefaultWebSession.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class DefaultWebSession implements WebSession {
6060

6161

6262
/**
63-
* Constructor for creating a brand, new session.
63+
* Constructor for creating a new session instance.
6464
* @param idGenerator the session id generator
6565
* @param clock for access to current time
6666
*/
@@ -86,7 +86,8 @@ class DefaultWebSession implements WebSession {
8686
}
8787

8888
/**
89-
* Constructor for creating a new session with an updated last access time.
89+
* Copy constructor to re-create a session at the start of a new request
90+
* refreshing the last access time of the session.
9091
* @param existingSession the existing session to copy
9192
* @param lastAccessTime the new last access time
9293
*/

spring-web/src/main/java/org/springframework/web/server/session/DefaultWebSessionManager.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public class DefaultWebSessionManager implements WebSessionManager {
4040

4141
private WebSessionStore sessionStore = new InMemoryWebSessionStore();
4242

43+
4344
/**
4445
* Configure the id resolution strategy.
4546
* <p>By default an instance of {@link CookieWebSessionIdResolver}.
@@ -74,6 +75,7 @@ public WebSessionStore getSessionStore() {
7475
return this.sessionStore;
7576
}
7677

78+
7779
@Override
7880
public Mono<WebSession> getSession(ServerWebExchange exchange) {
7981
return Mono.defer(() ->

spring-web/src/main/java/org/springframework/web/server/session/HeaderWebSessionIdResolver.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@
3131
*/
3232
public class HeaderWebSessionIdResolver implements WebSessionIdResolver {
3333

34-
/**
35-
* The default header name
36-
*/
34+
/** Default value for {@link #setHeaderName(String)}. */
3735
public static final String DEFAULT_HEADER_NAME = "SESSION";
3836

37+
3938
private String headerName = DEFAULT_HEADER_NAME;
4039

40+
4141
/**
4242
* Set the name of the session header to use for the session id.
4343
* The name is used to extract the session id from the request headers as
@@ -50,6 +50,15 @@ public void setHeaderName(String headerName) {
5050
this.headerName = headerName;
5151
}
5252

53+
/**
54+
* Return the configured header name.
55+
* @return the configured header name
56+
*/
57+
public String getHeaderName() {
58+
return this.headerName;
59+
}
60+
61+
5362
@Override
5463
public List<String> resolveSessionIds(ServerWebExchange exchange) {
5564
HttpHeaders headers = exchange.getRequest().getHeaders();
@@ -67,11 +76,4 @@ public void expireSession(ServerWebExchange exchange) {
6776
this.setSessionId(exchange, "");
6877
}
6978

70-
/**
71-
* Return the configured header name.
72-
* @return the configured header name
73-
*/
74-
private String getHeaderName() {
75-
return this.headerName;
76-
}
7779
}

spring-web/src/main/java/org/springframework/web/server/session/InMemoryWebSessionStore.java

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,34 @@ public class InMemoryWebSessionStore implements WebSessionStore {
3939

4040
private static final IdGenerator idGenerator = new JdkIdGenerator();
4141

42+
4243
private Clock clock = Clock.system(ZoneId.of("GMT"));
4344

4445
private final Map<String, WebSession> sessions = new ConcurrentHashMap<>();
4546

4647

48+
/**
49+
* Configure the {@link Clock} to use to set lastAccessTime on every created
50+
* session and to calculate if it is expired.
51+
* <p>This may be useful to align to different timezone or to set the clock
52+
* back in a test, e.g. {@code Clock.offset(clock, Duration.ofMinutes(-31))}
53+
* in order to simulate session expiration.
54+
* <p>By default this is {@code Clock.system(ZoneId.of("GMT"))}.
55+
* @param clock the clock to use
56+
*/
57+
public void setClock(Clock clock) {
58+
Assert.notNull(clock, "'clock' is required.");
59+
this.clock = clock;
60+
}
61+
62+
/**
63+
* Return the configured clock for session lastAccessTime calculations.
64+
*/
65+
public Clock getClock() {
66+
return this.clock;
67+
}
68+
69+
4770
@Override
4871
public Mono<WebSession> retrieveSession(String id) {
4972
return (this.sessions.containsKey(id) ? Mono.just(this.sessions.get(id)) : Mono.empty());
@@ -70,27 +93,6 @@ public Mono<WebSession> updateLastAccessTime(WebSession webSession) {
7093
});
7194
}
7295

73-
/**
74-
* Configure the {@link Clock} to use to set lastAccessTime on every created
75-
* session and to calculate if it is expired.
76-
* <p>This may be useful to align to different timezone or to set the clock
77-
* back in a test, e.g. {@code Clock.offset(clock, Duration.ofMinutes(-31))}
78-
* in order to simulate session expiration.
79-
* <p>By default this is {@code Clock.system(ZoneId.of("GMT"))}.
80-
* @param clock the clock to use
81-
*/
82-
public void setClock(Clock clock) {
83-
Assert.notNull(clock, "'clock' is required.");
84-
this.clock = clock;
85-
}
86-
87-
/**
88-
* Return the configured clock for session lastAccessTime calculations.
89-
*/
90-
public Clock getClock() {
91-
return this.clock;
92-
}
93-
9496
private Mono<Void> changeSessionId(String oldId, WebSession session) {
9597
this.sessions.remove(oldId);
9698
this.sessions.put(session.getId(), session);

spring-web/src/main/java/org/springframework/web/server/session/WebSessionStore.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919

2020
import org.springframework.web.server.WebSession;
2121

22-
import java.time.Instant;
23-
2422
/**
2523
* Strategy for {@link WebSession} persistence.
2624
*
@@ -31,8 +29,12 @@
3129
public interface WebSessionStore {
3230

3331
/**
34-
* Creates the WebSession that can be stored by this WebSessionStore.
35-
* @return the session
32+
* Create a new WebSession.
33+
* <p>Note that this does nothing more than create a new instance.
34+
* The session can later be started explicitly via {@link WebSession#start()}
35+
* or implicitly by adding attributes -- and then persisted via
36+
* {@link WebSession#save()}.
37+
* @return the created session instance
3638
*/
3739
Mono<WebSession> createWebSession();
3840

@@ -51,7 +53,7 @@ public interface WebSessionStore {
5153
Mono<Void> removeSession(String sessionId);
5254

5355
/**
54-
* Update the last accessed time to now.
56+
* Update the last accessed timestamp to "now".
5557
* @param webSession the session to update
5658
* @return the session with the updated last access time
5759
*/

0 commit comments

Comments
 (0)