Skip to content

Commit 84cca81

Browse files
Use HttpSessionSecurityContextRepository by default in SwitchUserFilter
Closes gh-12834
1 parent 094bf1b commit 84cca81

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

web/src/main/java/org/springframework/security/web/authentication/switchuser/SwitchUserFilter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
import org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler;
5959
import org.springframework.security.web.authentication.SimpleUrlAuthenticationSuccessHandler;
6060
import org.springframework.security.web.authentication.WebAuthenticationDetailsSource;
61+
import org.springframework.security.web.context.HttpSessionSecurityContextRepository;
6162
import org.springframework.security.web.context.RequestAttributeSecurityContextRepository;
6263
import org.springframework.security.web.context.SecurityContextRepository;
6364
import org.springframework.security.web.util.UrlUtils;
@@ -144,7 +145,7 @@ public class SwitchUserFilter extends GenericFilterBean implements ApplicationEv
144145

145146
private AuthenticationFailureHandler failureHandler;
146147

147-
private SecurityContextRepository securityContextRepository = new RequestAttributeSecurityContextRepository();
148+
private SecurityContextRepository securityContextRepository = new HttpSessionSecurityContextRepository();
148149

149150
@Override
150151
public void afterPropertiesSet() {

web/src/test/java/org/springframework/security/web/authentication/switchuser/SwitchUserFilterTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
import org.springframework.security.util.FieldUtils;
4848
import org.springframework.security.web.DefaultRedirectStrategy;
4949
import org.springframework.security.web.authentication.SimpleUrlAuthenticationSuccessHandler;
50-
import org.springframework.security.web.context.RequestAttributeSecurityContextRepository;
50+
import org.springframework.security.web.context.HttpSessionSecurityContextRepository;
5151
import org.springframework.security.web.context.SecurityContextRepository;
5252
import org.springframework.security.web.util.matcher.AnyRequestMatcher;
5353
import org.springframework.test.util.ReflectionTestUtils;
@@ -491,10 +491,10 @@ public void setSwitchFailureUrlWhenValidThenNoException() {
491491
}
492492

493493
@Test
494-
void filterWhenDefaultSecurityContextRepositoryThenRequestAttributeRepository() {
494+
void filterWhenDefaultSecurityContextRepositoryThenHttpSessionRepository() {
495495
SwitchUserFilter switchUserFilter = new SwitchUserFilter();
496496
assertThat(ReflectionTestUtils.getField(switchUserFilter, "securityContextRepository"))
497-
.isInstanceOf(RequestAttributeSecurityContextRepository.class);
497+
.isInstanceOf(HttpSessionSecurityContextRepository.class);
498498
}
499499

500500
@Test

0 commit comments

Comments
 (0)