2424import org .w3c .dom .Element ;
2525
2626import org .springframework .beans .BeanMetadataElement ;
27+ import org .springframework .beans .BeansException ;
2728import org .springframework .beans .factory .config .BeanDefinition ;
2829import org .springframework .beans .factory .config .BeanReference ;
30+ import org .springframework .beans .factory .config .ConfigurableListableBeanFactory ;
2931import org .springframework .beans .factory .config .ListFactoryBean ;
3032import org .springframework .beans .factory .config .MethodInvokingFactoryBean ;
3133import org .springframework .beans .factory .config .RuntimeBeanReference ;
3234import org .springframework .beans .factory .parsing .BeanComponentDefinition ;
3335import org .springframework .beans .factory .parsing .CompositeComponentDefinition ;
36+ import org .springframework .beans .factory .support .AbstractBeanDefinition ;
3437import org .springframework .beans .factory .support .BeanDefinitionBuilder ;
38+ import org .springframework .beans .factory .support .BeanDefinitionRegistry ;
39+ import org .springframework .beans .factory .support .BeanDefinitionRegistryPostProcessor ;
3540import org .springframework .beans .factory .support .ManagedList ;
3641import org .springframework .beans .factory .support .RootBeanDefinition ;
3742import org .springframework .beans .factory .xml .BeanDefinitionParser ;
@@ -393,7 +398,8 @@ else if (StringUtils.hasText(before)) {
393398 }
394399
395400 static void registerFilterChainProxyIfNecessary (ParserContext pc , Object source ) {
396- if (pc .getRegistry ().containsBeanDefinition (BeanIds .FILTER_CHAIN_PROXY )) {
401+ BeanDefinitionRegistry registry = pc .getRegistry ();
402+ if (registry .containsBeanDefinition (BeanIds .FILTER_CHAIN_PROXY )) {
397403 return ;
398404 }
399405 // Not already registered, so register the list of filter chains and the
@@ -412,10 +418,46 @@ static void registerFilterChainProxyIfNecessary(ParserContext pc, Object source)
412418 BeanDefinition fcpBean = fcpBldr .getBeanDefinition ();
413419 pc .registerBeanComponent (new BeanComponentDefinition (fcpBean ,
414420 BeanIds .FILTER_CHAIN_PROXY ));
415- pc . getRegistry () .registerAlias (BeanIds .FILTER_CHAIN_PROXY ,
421+ registry .registerAlias (BeanIds .FILTER_CHAIN_PROXY ,
416422 BeanIds .SPRING_SECURITY_FILTER_CHAIN );
423+
424+ BeanDefinitionBuilder requestRejected = BeanDefinitionBuilder .rootBeanDefinition (RequestRejectedHandlerPostProcessor .class );
425+ requestRejected .setRole (BeanDefinition .ROLE_INFRASTRUCTURE );
426+ requestRejected .addConstructorArgValue ("requestRejectedHandler" );
427+ requestRejected .addConstructorArgValue (BeanIds .FILTER_CHAIN_PROXY );
428+ requestRejected .addConstructorArgValue ("requestRejectedHandler" );
429+ AbstractBeanDefinition requestRejectedBean = requestRejected .getBeanDefinition ();
430+ String requestRejectedPostProcessorName = pc .getReaderContext ().generateBeanName (requestRejectedBean );
431+ registry .registerBeanDefinition (requestRejectedPostProcessorName , requestRejectedBean );
432+ }
433+
434+ }
435+
436+ class RequestRejectedHandlerPostProcessor implements BeanDefinitionRegistryPostProcessor {
437+ private final String beanName ;
438+
439+ private final String targetBeanName ;
440+
441+ private final String targetPropertyName ;
442+
443+ RequestRejectedHandlerPostProcessor (String beanName , String targetBeanName , String targetPropertyName ) {
444+ this .beanName = beanName ;
445+ this .targetBeanName = targetBeanName ;
446+ this .targetPropertyName = targetPropertyName ;
417447 }
418448
449+ @ Override
450+ public void postProcessBeanDefinitionRegistry (BeanDefinitionRegistry registry ) throws BeansException {
451+ if (registry .containsBeanDefinition (this .beanName )) {
452+ BeanDefinition beanDefinition = registry .getBeanDefinition (this .targetBeanName );
453+ beanDefinition .getPropertyValues ().add (this .targetPropertyName , new RuntimeBeanReference (this .beanName ));
454+ }
455+ }
456+
457+ @ Override
458+ public void postProcessBeanFactory (ConfigurableListableBeanFactory beanFactory ) throws BeansException {
459+
460+ }
419461}
420462
421463class OrderDecorator implements Ordered {
0 commit comments