Skip to content

Commit 915d68e

Browse files
Remove includeExpiredSessions parameter
The reactive implementation of max sessions does not keep track of expired sessions, therefore we do not need such parameter Issue gh-6192
1 parent 6068e6b commit 915d68e

File tree

8 files changed

+27
-33
lines changed

8 files changed

+27
-33
lines changed

config/src/test/java/org/springframework/security/config/web/server/SessionManagementSpecTests.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -334,7 +334,7 @@ void loginWhenUnlimitedSessionsButSessionsInvalidatedManuallyThenInvalidates() {
334334
.expectStatus()
335335
.isOk();
336336
ReactiveSessionRegistry sessionRegistry = this.spring.getContext().getBean(ReactiveSessionRegistry.class);
337-
sessionRegistry.getAllSessions(PasswordEncodedUser.user(), false)
337+
sessionRegistry.getAllSessions(PasswordEncodedUser.user())
338338
.flatMap(ReactiveSessionInformation::invalidate)
339339
.blockLast();
340340
this.client.get()

core/src/main/java/org/springframework/security/core/session/InMemoryReactiveSessionRegistry.java

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -50,10 +50,9 @@ public InMemoryReactiveSessionRegistry(ConcurrentMap<Object, Set<String>> sessio
5050
}
5151

5252
@Override
53-
public Flux<ReactiveSessionInformation> getAllSessions(Object principal, boolean includeExpiredSessions) {
53+
public Flux<ReactiveSessionInformation> getAllSessions(Object principal) {
5454
return Flux.fromIterable(this.sessionIdsByPrincipal.getOrDefault(principal, Collections.emptySet()))
55-
.map(this.sessionById::get)
56-
.filter((sessionInformation) -> includeExpiredSessions || !sessionInformation.isExpired());
55+
.map(this.sessionById::get);
5756
}
5857

5958
@Override

core/src/main/java/org/springframework/security/core/session/ReactiveSessionRegistry.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -34,7 +34,7 @@ public interface ReactiveSessionRegistry {
3434
* @return the {@link ReactiveSessionInformation} instances associated with the
3535
* principal
3636
*/
37-
Flux<ReactiveSessionInformation> getAllSessions(Object principal, boolean includeExpiredSessions);
37+
Flux<ReactiveSessionInformation> getAllSessions(Object principal);
3838

3939
/**
4040
* Saves the {@link ReactiveSessionInformation}

web/src/main/java/org/springframework/security/web/server/authentication/ConcurrentSessionControlServerAuthenticationSuccessHandler.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -62,7 +62,7 @@ public Mono<Void> onAuthenticationSuccess(WebFilterExchange exchange, Authentica
6262

6363
private Mono<Void> handleConcurrency(WebFilterExchange exchange, Authentication authentication,
6464
Integer maximumSessions) {
65-
return this.sessionRegistry.getAllSessions(authentication.getPrincipal(), false)
65+
return this.sessionRegistry.getAllSessions(authentication.getPrincipal())
6666
.collectList()
6767
.flatMap((registeredSessions) -> exchange.getExchange()
6868
.getSession()

web/src/main/java/org/springframework/security/web/session/WebSessionStoreReactiveSessionRegistry.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -46,8 +46,8 @@ public WebSessionStoreReactiveSessionRegistry(WebSessionStore webSessionStore) {
4646
}
4747

4848
@Override
49-
public Flux<ReactiveSessionInformation> getAllSessions(Object principal, boolean includeExpiredSessions) {
50-
return this.sessionRegistry.getAllSessions(principal, includeExpiredSessions).map(WebSessionInformation::new);
49+
public Flux<ReactiveSessionInformation> getAllSessions(Object principal) {
50+
return this.sessionRegistry.getAllSessions(principal).map(WebSessionInformation::new);
5151
}
5252

5353
@Override

web/src/test/java/org/springframework/security/web/server/authentication/session/ConcurrentSessionControlServerAuthenticationSuccessHandlerTests.java

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -111,7 +111,7 @@ void onAuthenticationWhenMaximumSessionsIsOneAndExceededThenHandlerIsCalled() {
111111
Authentication authentication = TestAuthentication.authenticatedUser();
112112
List<ReactiveSessionInformation> sessions = Arrays.asList(createSessionInformation("100"),
113113
createSessionInformation("101"));
114-
given(this.sessionRegistry.getAllSessions(authentication.getPrincipal(), false))
114+
given(this.sessionRegistry.getAllSessions(authentication.getPrincipal()))
115115
.willReturn(Flux.fromIterable(sessions));
116116
this.strategy.onAuthenticationSuccess(new WebFilterExchange(this.exchange, this.chain), authentication).block();
117117
verify(this.handler).handle(this.contextCaptor.capture());
@@ -127,7 +127,7 @@ void onAuthenticationWhenMaximumSessionsIsGreaterThanOneAndExceededThenHandlerIs
127127
List<ReactiveSessionInformation> sessions = Arrays.asList(createSessionInformation("100"),
128128
createSessionInformation("101"), createSessionInformation("102"), createSessionInformation("103"),
129129
createSessionInformation("104"));
130-
given(this.sessionRegistry.getAllSessions(authentication.getPrincipal(), false))
130+
given(this.sessionRegistry.getAllSessions(authentication.getPrincipal()))
131131
.willReturn(Flux.fromIterable(sessions));
132132
this.strategy.onAuthenticationSuccess(new WebFilterExchange(this.exchange, this.chain), authentication).block();
133133
verify(this.handler).handle(this.contextCaptor.capture());
@@ -151,10 +151,8 @@ void onAuthenticationWhenMaximumSessionsForUsersAreDifferentThenHandlerIsCalledW
151151
List<ReactiveSessionInformation> adminSessions = Arrays.asList(createSessionInformation("200"),
152152
createSessionInformation("201"));
153153

154-
given(this.sessionRegistry.getAllSessions(user.getPrincipal(), false))
155-
.willReturn(Flux.fromIterable(userSessions));
156-
given(this.sessionRegistry.getAllSessions(admin.getPrincipal(), false))
157-
.willReturn(Flux.fromIterable(adminSessions));
154+
given(this.sessionRegistry.getAllSessions(user.getPrincipal())).willReturn(Flux.fromIterable(userSessions));
155+
given(this.sessionRegistry.getAllSessions(admin.getPrincipal())).willReturn(Flux.fromIterable(adminSessions));
158156

159157
this.strategy.onAuthenticationSuccess(new WebFilterExchange(this.exchange, this.chain), user).block();
160158
this.strategy.onAuthenticationSuccess(new WebFilterExchange(this.exchange, this.chain), admin).block();

web/src/test/java/org/springframework/security/web/server/authentication/session/InMemoryReactiveSessionRegistryTests.java

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -46,7 +46,7 @@ void saveWhenPrincipalThenRegisterPrincipalSession() {
4646
"1234", this.now);
4747
this.sessionRegistry.saveSessionInformation(sessionInformation).block();
4848
List<ReactiveSessionInformation> principalSessions = this.sessionRegistry
49-
.getAllSessions(authentication.getPrincipal(), false)
49+
.getAllSessions(authentication.getPrincipal())
5050
.collectList()
5151
.block();
5252
assertThat(principalSessions).hasSize(1);
@@ -65,8 +65,7 @@ void getAllSessionsWhenMultipleSessionsThenReturnAll() {
6565
this.sessionRegistry.saveSessionInformation(sessionInformation1).block();
6666
this.sessionRegistry.saveSessionInformation(sessionInformation2).block();
6767
this.sessionRegistry.saveSessionInformation(sessionInformation3).block();
68-
List<ReactiveSessionInformation> sessions = this.sessionRegistry
69-
.getAllSessions(authentication.getPrincipal(), false)
68+
List<ReactiveSessionInformation> sessions = this.sessionRegistry.getAllSessions(authentication.getPrincipal())
7069
.collectList()
7170
.block();
7271
assertThat(sessions).hasSize(3);
@@ -82,7 +81,7 @@ void removeSessionInformationThenSessionIsRemoved() {
8281
"1234", this.now);
8382
this.sessionRegistry.saveSessionInformation(sessionInformation).block();
8483
this.sessionRegistry.removeSessionInformation("1234").block();
85-
List<ReactiveSessionInformation> sessions = this.sessionRegistry.getAllSessions(authentication.getName(), false)
84+
List<ReactiveSessionInformation> sessions = this.sessionRegistry.getAllSessions(authentication.getName())
8685
.collectList()
8786
.block();
8887
assertThat(this.sessionRegistry.getSessionInformation("1234").block()).isNull();

web/src/test/java/org/springframework/security/web/session/WebSessionStoreReactiveSessionRegistryTests.java

+6-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -31,8 +31,6 @@
3131
import static org.assertj.core.api.Assertions.assertThat;
3232
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
3333
import static org.mockito.ArgumentMatchers.any;
34-
import static org.mockito.ArgumentMatchers.anyBoolean;
35-
import static org.mockito.ArgumentMatchers.eq;
3634
import static org.mockito.BDDMockito.given;
3735
import static org.mockito.Mockito.mock;
3836
import static org.mockito.Mockito.verify;
@@ -101,12 +99,12 @@ void invalidateWhenReturnedFromGetAllSessionsThenWebSessionInvalidatedAndRemoved
10199
given(this.webSessionStore.retrieveSession(session.getSessionId())).willReturn(Mono.just(webSession));
102100

103101
this.registry.saveSessionInformation(session).block();
104-
List<ReactiveSessionInformation> saved = this.registry.getAllSessions(session.getPrincipal(), false)
102+
List<ReactiveSessionInformation> saved = this.registry.getAllSessions(session.getPrincipal())
105103
.collectList()
106104
.block();
107105
saved.forEach((info) -> info.invalidate().block());
108106
verify(webSession).invalidate();
109-
assertThat(this.registry.getAllSessions(session.getPrincipal(), false).collectList().block()).isEmpty();
107+
assertThat(this.registry.getAllSessions(session.getPrincipal()).collectList().block()).isEmpty();
110108
}
111109

112110
@Test
@@ -116,7 +114,7 @@ void setSessionRegistryThenUses() {
116114
given(sessionRegistry.removeSessionInformation(any())).willReturn(Mono.empty());
117115
given(sessionRegistry.updateLastAccessTime(any())).willReturn(Mono.empty());
118116
given(sessionRegistry.getSessionInformation(any())).willReturn(Mono.empty());
119-
given(sessionRegistry.getAllSessions(any(), anyBoolean())).willReturn(Flux.empty());
117+
given(sessionRegistry.getAllSessions(any())).willReturn(Flux.empty());
120118
this.registry.setSessionRegistry(sessionRegistry);
121119
ReactiveSessionInformation session = createSession();
122120
this.registry.saveSessionInformation(session).block();
@@ -127,8 +125,8 @@ void setSessionRegistryThenUses() {
127125
verify(sessionRegistry).updateLastAccessTime(any());
128126
this.registry.getSessionInformation(session.getSessionId()).block();
129127
verify(sessionRegistry).getSessionInformation(any());
130-
this.registry.getAllSessions(session.getPrincipal(), false).blockFirst();
131-
verify(sessionRegistry).getAllSessions(any(), eq(false));
128+
this.registry.getAllSessions(session.getPrincipal()).blockFirst();
129+
verify(sessionRegistry).getAllSessions(any());
132130
}
133131

134132
private static ReactiveSessionInformation createSession() {

0 commit comments

Comments
 (0)