|
106 | 106 | import org.springframework.security.web.authentication.HttpStatusEntryPoint;
|
107 | 107 | import org.springframework.security.web.context.HttpRequestResponseHolder;
|
108 | 108 | import org.springframework.security.web.context.HttpSessionSecurityContextRepository;
|
| 109 | +import org.springframework.security.web.context.NullSecurityContextRepository; |
109 | 110 | import org.springframework.security.web.context.SecurityContextRepository;
|
110 | 111 | import org.springframework.security.web.servlet.TestMockHttpServletRequests;
|
111 | 112 | import org.springframework.security.web.session.HttpSessionDestroyedEvent;
|
|
116 | 117 |
|
117 | 118 | import static org.assertj.core.api.Assertions.assertThat;
|
118 | 119 | import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
| 120 | +import static org.assertj.core.api.Assertions.assertThatNoException; |
119 | 121 | import static org.mockito.ArgumentMatchers.any;
|
120 | 122 | import static org.mockito.ArgumentMatchers.anyString;
|
121 | 123 | import static org.mockito.BDDMockito.given;
|
@@ -717,6 +719,12 @@ public void oauth2LoginWhenAuthenticationProviderPostProcessorThenUses() throws
|
717 | 719 | verify(this.context.getBean(SpyObjectPostProcessor.class).spy).authenticate(any());
|
718 | 720 | }
|
719 | 721 |
|
| 722 | + // gh-16623 |
| 723 | + @Test |
| 724 | + public void oauth2LoginWithCustomSecurityContextRepository() { |
| 725 | + assertThatNoException().isThrownBy(() -> loadConfig(OAuth2LoginConfigSecurityContextRepository.class)); |
| 726 | + } |
| 727 | + |
720 | 728 | private void loadConfig(Class<?>... configs) {
|
721 | 729 | AnnotationConfigWebApplicationContext applicationContext = new AnnotationConfigWebApplicationContext();
|
722 | 730 | applicationContext.register(configs);
|
@@ -961,6 +969,24 @@ SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
|
961 | 969 |
|
962 | 970 | }
|
963 | 971 |
|
| 972 | + @Configuration |
| 973 | + @EnableWebSecurity |
| 974 | + static class OAuth2LoginConfigSecurityContextRepository extends CommonSecurityFilterChainConfig { |
| 975 | + |
| 976 | + @Bean |
| 977 | + SecurityFilterChain filterChain(HttpSecurity http) throws Exception { |
| 978 | + // @formatter:off |
| 979 | + http |
| 980 | + .oauth2Login((login) -> login |
| 981 | + .clientRegistrationRepository( |
| 982 | + new InMemoryClientRegistrationRepository(GOOGLE_CLIENT_REGISTRATION)) |
| 983 | + .securityContextRepository(new NullSecurityContextRepository())); |
| 984 | + // @formatter:on |
| 985 | + return super.configureFilterChain(http); |
| 986 | + } |
| 987 | + |
| 988 | + } |
| 989 | + |
964 | 990 | @Configuration
|
965 | 991 | @EnableWebSecurity
|
966 | 992 | static class OAuth2LoginConfigCustomAuthorizationRequestResolver extends CommonSecurityFilterChainConfig {
|
|
0 commit comments