|
87 | 87 | import org.springframework.security.web.authentication.session.SessionAuthenticationException; |
88 | 88 | import org.springframework.security.web.authentication.session.SessionAuthenticationStrategy; |
89 | 89 | import org.springframework.security.web.authentication.ui.DefaultLoginPageGeneratingFilter; |
| 90 | +import org.springframework.security.web.context.SecurityContextRepository; |
90 | 91 | import org.springframework.security.web.csrf.CsrfToken; |
91 | 92 | import org.springframework.security.web.savedrequest.RequestCache; |
92 | 93 | import org.springframework.security.web.util.matcher.AndRequestMatcher; |
@@ -177,6 +178,8 @@ public final class OAuth2LoginConfigurer<B extends HttpSecurityBuilder<B>> |
177 | 178 |
|
178 | 179 | private OAuth2AuthorizedClientRepository authorizedClientRepository; |
179 | 180 |
|
| 181 | + private SecurityContextRepository securityContextRepository; |
| 182 | + |
180 | 183 | /** |
181 | 184 | * Sets the repository of client registrations. |
182 | 185 | * @param clientRegistrationRepository the repository of client registrations |
@@ -230,6 +233,17 @@ public OAuth2LoginConfigurer<B> loginProcessingUrl(String loginProcessingUrl) { |
230 | 233 | return this; |
231 | 234 | } |
232 | 235 |
|
| 236 | + /** |
| 237 | + * Sets the {@link SecurityContextRepository} to use. |
| 238 | + * @param securityContextRepository the {@link SecurityContextRepository} to use |
| 239 | + * @return the {@link OAuth2LoginConfigurer} for further configuration |
| 240 | + */ |
| 241 | + @Override |
| 242 | + public OAuth2LoginConfigurer<B> securityContextRepository(SecurityContextRepository securityContextRepository) { |
| 243 | + this.securityContextRepository = securityContextRepository; |
| 244 | + return this; |
| 245 | + } |
| 246 | + |
233 | 247 | /** |
234 | 248 | * Sets the registry for managing the OIDC client-provider session link |
235 | 249 | * @param oidcSessionRegistry the {@link OidcSessionRegistry} to use |
@@ -348,6 +362,9 @@ public void init(B http) throws Exception { |
348 | 362 | OAuth2LoginAuthenticationFilter authenticationFilter = new OAuth2LoginAuthenticationFilter( |
349 | 363 | this.getClientRegistrationRepository(), this.getAuthorizedClientRepository(), this.loginProcessingUrl); |
350 | 364 | authenticationFilter.setSecurityContextHolderStrategy(getSecurityContextHolderStrategy()); |
| 365 | + if (this.securityContextRepository != null) { |
| 366 | + authenticationFilter.setSecurityContextRepository(this.securityContextRepository); |
| 367 | + } |
351 | 368 | this.setAuthenticationFilter(authenticationFilter); |
352 | 369 | super.loginProcessingUrl(this.loginProcessingUrl); |
353 | 370 | if (this.loginPage != null) { |
|
0 commit comments