@@ -236,6 +236,7 @@ final class AuthenticationConfigBuilder {
236
236
237
237
AuthenticationConfigBuilder (Element element , boolean forceAutoConfig , ParserContext pc ,
238
238
SessionCreationPolicy sessionPolicy , BeanReference requestCache , BeanReference authenticationManager ,
239
+ BeanReference authenticationFilterSecurityContextHolderStrategyRef ,
239
240
BeanReference authenticationFilterSecurityContextRepositoryRef , BeanReference sessionStrategy ,
240
241
BeanReference portMapper , BeanReference portResolver , BeanMetadataElement csrfLogoutHandler ) {
241
242
this .httpElt = element ;
@@ -247,23 +248,24 @@ final class AuthenticationConfigBuilder {
247
248
this .portMapper = portMapper ;
248
249
this .portResolver = portResolver ;
249
250
this .csrfLogoutHandler = csrfLogoutHandler ;
250
- createAnonymousFilter ();
251
+ createAnonymousFilter (authenticationFilterSecurityContextHolderStrategyRef );
251
252
createRememberMeFilter (authenticationManager );
252
- createBasicFilter (authenticationManager );
253
+ createBasicFilter (authenticationManager , authenticationFilterSecurityContextHolderStrategyRef );
253
254
createBearerTokenAuthenticationFilter (authenticationManager );
254
- createFormLoginFilter (sessionStrategy , authenticationManager , authenticationFilterSecurityContextRepositoryRef );
255
+ createFormLoginFilter (sessionStrategy , authenticationManager ,
256
+ authenticationFilterSecurityContextHolderStrategyRef , authenticationFilterSecurityContextRepositoryRef );
255
257
createOAuth2ClientFilters (sessionStrategy , requestCache , authenticationManager ,
256
258
authenticationFilterSecurityContextRepositoryRef );
257
259
createOpenIDLoginFilter (sessionStrategy , authenticationManager ,
258
260
authenticationFilterSecurityContextRepositoryRef );
259
261
createSaml2LoginFilter (authenticationManager , authenticationFilterSecurityContextRepositoryRef );
260
262
createX509Filter (authenticationManager );
261
263
createJeeFilter (authenticationManager );
262
- createLogoutFilter ();
264
+ createLogoutFilter (authenticationFilterSecurityContextHolderStrategyRef );
263
265
createSaml2LogoutFilter ();
264
266
createLoginPageFilterIfNeeded ();
265
267
createUserDetailsServiceFactory ();
266
- createExceptionTranslationFilter ();
268
+ createExceptionTranslationFilter (authenticationFilterSecurityContextHolderStrategyRef );
267
269
}
268
270
269
271
void createRememberMeFilter (BeanReference authenticationManager ) {
@@ -293,6 +295,7 @@ private void createRememberMeProvider(String key) {
293
295
}
294
296
295
297
void createFormLoginFilter (BeanReference sessionStrategy , BeanReference authManager ,
298
+ BeanReference authenticationFilterSecurityContextHolderStrategyRef ,
296
299
BeanReference authenticationFilterSecurityContextRepositoryRef ) {
297
300
Element formLoginElt = DomUtils .getChildElementByTagName (this .httpElt , Elements .FORM_LOGIN );
298
301
RootBeanDefinition formFilter = null ;
@@ -313,6 +316,8 @@ void createFormLoginFilter(BeanReference sessionStrategy, BeanReference authMana
313
316
formFilter .getPropertyValues ().addPropertyValue ("securityContextRepository" ,
314
317
authenticationFilterSecurityContextRepositoryRef );
315
318
}
319
+ formFilter .getPropertyValues ().addPropertyValue ("securityContextHolderStrategy" ,
320
+ authenticationFilterSecurityContextHolderStrategyRef );
316
321
// Id is required by login page filter
317
322
this .formFilterId = this .pc .getReaderContext ().generateBeanName (formFilter );
318
323
this .pc .registerBeanComponent (new BeanComponentDefinition (formFilter , this .formFilterId ));
@@ -564,7 +569,8 @@ private void injectRememberMeServicesRef(RootBeanDefinition bean, String remembe
564
569
}
565
570
}
566
571
567
- void createBasicFilter (BeanReference authManager ) {
572
+ void createBasicFilter (BeanReference authManager ,
573
+ BeanReference authenticationFilterSecurityContextHolderStrategyRef ) {
568
574
Element basicAuthElt = DomUtils .getChildElementByTagName (this .httpElt , Elements .BASIC_AUTH );
569
575
if (basicAuthElt == null && !this .autoConfig ) {
570
576
// No basic auth, do nothing
@@ -592,6 +598,8 @@ void createBasicFilter(BeanReference authManager) {
592
598
}
593
599
filterBuilder .addConstructorArgValue (authManager );
594
600
filterBuilder .addConstructorArgValue (this .basicEntryPoint );
601
+ filterBuilder .addPropertyValue ("securityContextHolderStrategy" ,
602
+ authenticationFilterSecurityContextHolderStrategyRef );
595
603
this .basicFilter = filterBuilder .getBeanDefinition ();
596
604
}
597
605
@@ -739,15 +747,16 @@ void createLoginPageFilterIfNeeded() {
739
747
}
740
748
}
741
749
742
- void createLogoutFilter () {
750
+ void createLogoutFilter (BeanReference authenticationFilterSecurityContextHolderStrategyRef ) {
743
751
Element logoutElt = DomUtils .getChildElementByTagName (this .httpElt , Elements .LOGOUT );
744
752
if (logoutElt != null || this .autoConfig ) {
745
753
String formLoginPage = this .formLoginPage ;
746
754
if (formLoginPage == null ) {
747
755
formLoginPage = DefaultLoginPageGeneratingFilter .DEFAULT_LOGIN_PAGE_URL ;
748
756
}
749
757
LogoutBeanDefinitionParser logoutParser = new LogoutBeanDefinitionParser (formLoginPage ,
750
- this .rememberMeServicesId , this .csrfLogoutHandler );
758
+ this .rememberMeServicesId , this .csrfLogoutHandler ,
759
+ authenticationFilterSecurityContextHolderStrategyRef );
751
760
this .logoutFilter = logoutParser .parse (logoutElt , this .pc );
752
761
this .logoutHandlers = logoutParser .getLogoutHandlers ();
753
762
this .logoutSuccessHandler = logoutParser .getLogoutSuccessHandler ();
@@ -803,7 +812,7 @@ List<BeanDefinition> getCsrfIgnoreRequestMatchers() {
803
812
return this .csrfIgnoreRequestMatchers ;
804
813
}
805
814
806
- void createAnonymousFilter () {
815
+ void createAnonymousFilter (BeanReference authenticationFilterSecurityContextHolderStrategyRef ) {
807
816
Element anonymousElt = DomUtils .getChildElementByTagName (this .httpElt , Elements .ANONYMOUS );
808
817
if (anonymousElt != null && "false" .equals (anonymousElt .getAttribute ("enabled" ))) {
809
818
return ;
@@ -833,6 +842,8 @@ void createAnonymousFilter() {
833
842
this .anonymousFilter .getConstructorArgumentValues ().addIndexedArgumentValue (1 , username );
834
843
this .anonymousFilter .getConstructorArgumentValues ().addIndexedArgumentValue (2 ,
835
844
AuthorityUtils .commaSeparatedStringToAuthorityList (grantedAuthority ));
845
+ this .anonymousFilter .getPropertyValues ().addPropertyValue ("securityContextHolderStrategy" ,
846
+ authenticationFilterSecurityContextHolderStrategyRef );
836
847
this .anonymousFilter .setSource (source );
837
848
RootBeanDefinition anonymousProviderBean = new RootBeanDefinition (AnonymousAuthenticationProvider .class );
838
849
anonymousProviderBean .getConstructorArgumentValues ().addIndexedArgumentValue (0 , key );
@@ -847,14 +858,16 @@ private String createKey() {
847
858
return Long .toString (random .nextLong ());
848
859
}
849
860
850
- void createExceptionTranslationFilter () {
861
+ void createExceptionTranslationFilter (BeanReference authenticationFilterSecurityContextHolderStrategyRef ) {
851
862
BeanDefinitionBuilder etfBuilder = BeanDefinitionBuilder .rootBeanDefinition (ExceptionTranslationFilter .class );
852
863
this .accessDeniedHandler = createAccessDeniedHandler (this .httpElt , this .pc );
853
864
etfBuilder .addPropertyValue ("accessDeniedHandler" , this .accessDeniedHandler );
854
865
Assert .state (this .requestCache != null , "No request cache found" );
855
866
this .mainEntryPoint = selectEntryPoint ();
856
867
etfBuilder .addConstructorArgValue (this .mainEntryPoint );
857
868
etfBuilder .addConstructorArgValue (this .requestCache );
869
+ etfBuilder .addPropertyValue ("securityContextHolderStrategy" ,
870
+ authenticationFilterSecurityContextHolderStrategyRef );
858
871
this .etf = etfBuilder .getBeanDefinition ();
859
872
}
860
873
0 commit comments