@@ -216,8 +216,8 @@ final class AuthenticationConfigBuilder {
216
216
217
217
AuthenticationConfigBuilder (Element element , boolean forceAutoConfig , ParserContext pc ,
218
218
SessionCreationPolicy sessionPolicy , BeanReference requestCache , BeanReference authenticationManager ,
219
- BeanReference sessionStrategy , BeanReference portMapper , BeanReference portResolver ,
220
- BeanMetadataElement csrfLogoutHandler ) {
219
+ BeanReference authenticationFilterSecurityContextRepositoryRef , BeanReference sessionStrategy ,
220
+ BeanReference portMapper , BeanReference portResolver , BeanMetadataElement csrfLogoutHandler ) {
221
221
this .httpElt = element ;
222
222
this .pc = pc ;
223
223
this .requestCache = requestCache ;
@@ -231,9 +231,10 @@ final class AuthenticationConfigBuilder {
231
231
createRememberMeFilter (authenticationManager );
232
232
createBasicFilter (authenticationManager );
233
233
createBearerTokenAuthenticationFilter (authenticationManager );
234
- createFormLoginFilter (sessionStrategy , authenticationManager );
235
- createOAuth2ClientFilters (sessionStrategy , requestCache , authenticationManager );
236
- createSaml2LoginFilter (authenticationManager );
234
+ createFormLoginFilter (sessionStrategy , authenticationManager , authenticationFilterSecurityContextRepositoryRef );
235
+ createOAuth2ClientFilters (sessionStrategy , requestCache , authenticationManager ,
236
+ authenticationFilterSecurityContextRepositoryRef );
237
+ createSaml2LoginFilter (authenticationManager , authenticationFilterSecurityContextRepositoryRef );
237
238
createX509Filter (authenticationManager );
238
239
createJeeFilter (authenticationManager );
239
240
createLogoutFilter ();
@@ -269,7 +270,8 @@ private void createRememberMeProvider(String key) {
269
270
this .rememberMeProviderRef = new RuntimeBeanReference (id );
270
271
}
271
272
272
- void createFormLoginFilter (BeanReference sessionStrategy , BeanReference authManager ) {
273
+ void createFormLoginFilter (BeanReference sessionStrategy , BeanReference authManager ,
274
+ BeanReference authenticationFilterSecurityContextRepositoryRef ) {
273
275
Element formLoginElt = DomUtils .getChildElementByTagName (this .httpElt , Elements .FORM_LOGIN );
274
276
RootBeanDefinition formFilter = null ;
275
277
if (formLoginElt != null || this .autoConfig ) {
@@ -285,6 +287,10 @@ void createFormLoginFilter(BeanReference sessionStrategy, BeanReference authMana
285
287
if (formFilter != null ) {
286
288
formFilter .getPropertyValues ().addPropertyValue ("allowSessionCreation" , this .allowSessionCreation );
287
289
formFilter .getPropertyValues ().addPropertyValue ("authenticationManager" , authManager );
290
+ if (authenticationFilterSecurityContextRepositoryRef != null ) {
291
+ formFilter .getPropertyValues ().addPropertyValue ("securityContextRepository" ,
292
+ authenticationFilterSecurityContextRepositoryRef );
293
+ }
288
294
// Id is required by login page filter
289
295
this .formFilterId = this .pc .getReaderContext ().generateBeanName (formFilter );
290
296
this .pc .registerBeanComponent (new BeanComponentDefinition (formFilter , this .formFilterId ));
@@ -293,13 +299,15 @@ void createFormLoginFilter(BeanReference sessionStrategy, BeanReference authMana
293
299
}
294
300
295
301
void createOAuth2ClientFilters (BeanReference sessionStrategy , BeanReference requestCache ,
296
- BeanReference authenticationManager ) {
297
- createOAuth2LoginFilter (sessionStrategy , authenticationManager );
298
- createOAuth2ClientFilter (requestCache , authenticationManager );
302
+ BeanReference authenticationManager , BeanReference authenticationFilterSecurityContextRepositoryRef ) {
303
+ createOAuth2LoginFilter (sessionStrategy , authenticationManager ,
304
+ authenticationFilterSecurityContextRepositoryRef );
305
+ createOAuth2ClientFilter (requestCache , authenticationManager , authenticationFilterSecurityContextRepositoryRef );
299
306
registerOAuth2ClientPostProcessors ();
300
307
}
301
308
302
- void createOAuth2LoginFilter (BeanReference sessionStrategy , BeanReference authManager ) {
309
+ void createOAuth2LoginFilter (BeanReference sessionStrategy , BeanReference authManager ,
310
+ BeanReference authenticationFilterSecurityContextRepositoryRef ) {
303
311
Element oauth2LoginElt = DomUtils .getChildElementByTagName (this .httpElt , Elements .OAUTH2_LOGIN );
304
312
if (oauth2LoginElt == null ) {
305
313
return ;
@@ -311,6 +319,10 @@ void createOAuth2LoginFilter(BeanReference sessionStrategy, BeanReference authMa
311
319
BeanDefinition defaultAuthorizedClientRepository = parser .getDefaultAuthorizedClientRepository ();
312
320
registerDefaultAuthorizedClientRepositoryIfNecessary (defaultAuthorizedClientRepository );
313
321
oauth2LoginFilterBean .getPropertyValues ().addPropertyValue ("authenticationManager" , authManager );
322
+ if (authenticationFilterSecurityContextRepositoryRef != null ) {
323
+ oauth2LoginFilterBean .getPropertyValues ().addPropertyValue ("securityContextRepository" ,
324
+ authenticationFilterSecurityContextRepositoryRef );
325
+ }
314
326
315
327
// retrieve the other bean result
316
328
BeanDefinition oauth2LoginAuthProvider = parser .getOAuth2LoginAuthenticationProvider ();
@@ -340,14 +352,15 @@ void createOAuth2LoginFilter(BeanReference sessionStrategy, BeanReference authMa
340
352
this .oauth2LoginOidcAuthenticationProviderRef = new RuntimeBeanReference (oauth2LoginOidcAuthProviderId );
341
353
}
342
354
343
- void createOAuth2ClientFilter (BeanReference requestCache , BeanReference authenticationManager ) {
355
+ void createOAuth2ClientFilter (BeanReference requestCache , BeanReference authenticationManager ,
356
+ BeanReference authenticationFilterSecurityContextRepositoryRef ) {
344
357
Element oauth2ClientElt = DomUtils .getChildElementByTagName (this .httpElt , Elements .OAUTH2_CLIENT );
345
358
if (oauth2ClientElt == null ) {
346
359
return ;
347
360
}
348
361
this .oauth2ClientEnabled = true ;
349
362
OAuth2ClientBeanDefinitionParser parser = new OAuth2ClientBeanDefinitionParser (requestCache ,
350
- authenticationManager );
363
+ authenticationManager , authenticationFilterSecurityContextRepositoryRef );
351
364
parser .parse (oauth2ClientElt , this .pc );
352
365
BeanDefinition defaultAuthorizedClientRepository = parser .getDefaultAuthorizedClientRepository ();
353
366
registerDefaultAuthorizedClientRepositoryIfNecessary (defaultAuthorizedClientRepository );
@@ -392,14 +405,16 @@ private void registerOAuth2ClientPostProcessors() {
392
405
}
393
406
}
394
407
395
- private void createSaml2LoginFilter (BeanReference authenticationManager ) {
408
+ private void createSaml2LoginFilter (BeanReference authenticationManager ,
409
+ BeanReference authenticationFilterSecurityContextRepositoryRef ) {
396
410
Element saml2LoginElt = DomUtils .getChildElementByTagName (this .httpElt , Elements .SAML2_LOGIN );
397
411
if (saml2LoginElt == null ) {
398
412
return ;
399
413
}
400
414
Saml2LoginBeanDefinitionParser parser = new Saml2LoginBeanDefinitionParser (this .csrfIgnoreRequestMatchers ,
401
415
this .portMapper , this .portResolver , this .requestCache , this .allowSessionCreation , authenticationManager ,
402
- this .authenticationProviders , this .defaultEntryPointMappings );
416
+ authenticationFilterSecurityContextRepositoryRef , this .authenticationProviders ,
417
+ this .defaultEntryPointMappings );
403
418
BeanDefinition saml2WebSsoAuthenticationFilter = parser .parse (saml2LoginElt , this .pc );
404
419
this .saml2AuthorizationRequestFilter = parser .getSaml2WebSsoAuthenticationRequestFilter ();
405
420
0 commit comments