46
46
import org .springframework .security .core .authority .mapping .SimpleMappableAttributesRetriever ;
47
47
import org .springframework .security .web .access .AccessDeniedHandlerImpl ;
48
48
import org .springframework .security .web .access .ExceptionTranslationFilter ;
49
+ import org .springframework .security .web .access .RequestMatcherDelegatingAccessDeniedHandler ;
49
50
import org .springframework .security .web .authentication .AnonymousAuthenticationFilter ;
51
+ import org .springframework .security .web .authentication .DelegatingAuthenticationEntryPoint ;
50
52
import org .springframework .security .web .authentication .Http403ForbiddenEntryPoint ;
51
53
import org .springframework .security .web .authentication .logout .SecurityContextLogoutHandler ;
52
54
import org .springframework .security .web .authentication .preauth .PreAuthenticatedAuthenticationProvider ;
@@ -165,6 +167,8 @@ final class AuthenticationConfigBuilder {
165
167
private BeanDefinition authorizationCodeGrantFilter ;
166
168
private BeanReference authorizationCodeAuthenticationProviderRef ;
167
169
170
+ private final Map <BeanDefinition , BeanMetadataElement > defaultDeniedHandlerMappings = new ManagedMap <>();
171
+ private final Map <BeanDefinition , BeanMetadataElement > defaultEntryPointMappings = new ManagedMap <>();
168
172
private final List <BeanDefinition > csrfIgnoreRequestMatchers = new ManagedList <>();
169
173
170
174
AuthenticationConfigBuilder (Element element , boolean forceAutoConfig ,
@@ -806,13 +810,27 @@ private BeanMetadataElement createAccessDeniedHandler(Element element,
806
810
807
811
}
808
812
accessDeniedHandler .addPropertyValue ("errorPage" , errorPage );
813
+ return accessDeniedHandler .getBeanDefinition ();
809
814
}
810
815
else if (StringUtils .hasText (ref )) {
811
816
return new RuntimeBeanReference (ref );
812
817
}
813
818
814
819
}
815
820
821
+ if (this .defaultDeniedHandlerMappings .isEmpty ()) {
822
+ return accessDeniedHandler .getBeanDefinition ();
823
+ }
824
+ if (this .defaultDeniedHandlerMappings .size () == 1 ) {
825
+ return this .defaultDeniedHandlerMappings .values ().iterator ().next ();
826
+ }
827
+
828
+ accessDeniedHandler = BeanDefinitionBuilder
829
+ .rootBeanDefinition (RequestMatcherDelegatingAccessDeniedHandler .class );
830
+ accessDeniedHandler .addConstructorArgValue (this .defaultDeniedHandlerMappings );
831
+ accessDeniedHandler .addConstructorArgValue
832
+ (BeanDefinitionBuilder .rootBeanDefinition (AccessDeniedHandlerImpl .class ));
833
+
816
834
return accessDeniedHandler .getBeanDefinition ();
817
835
}
818
836
@@ -825,6 +843,16 @@ private BeanMetadataElement selectEntryPoint() {
825
843
return new RuntimeBeanReference (customEntryPoint );
826
844
}
827
845
846
+ if (!defaultEntryPointMappings .isEmpty ()) {
847
+ if (defaultEntryPointMappings .size () == 1 ) {
848
+ return defaultEntryPointMappings .values ().iterator ().next ();
849
+ }
850
+ BeanDefinitionBuilder delegatingEntryPoint = BeanDefinitionBuilder
851
+ .rootBeanDefinition (DelegatingAuthenticationEntryPoint .class );
852
+ delegatingEntryPoint .addConstructorArgValue (defaultEntryPointMappings );
853
+ return delegatingEntryPoint .getBeanDefinition ();
854
+ }
855
+
828
856
Element basicAuthElt = DomUtils .getChildElementByTagName (httpElt ,
829
857
Elements .BASIC_AUTH );
830
858
Element formLoginElt = DomUtils .getChildElementByTagName (httpElt ,
0 commit comments