24
24
import org .w3c .dom .Element ;
25
25
26
26
import org .springframework .beans .BeanMetadataElement ;
27
+ import org .springframework .beans .BeansException ;
27
28
import org .springframework .beans .factory .config .BeanDefinition ;
28
29
import org .springframework .beans .factory .config .BeanReference ;
30
+ import org .springframework .beans .factory .config .ConfigurableListableBeanFactory ;
29
31
import org .springframework .beans .factory .config .ListFactoryBean ;
30
32
import org .springframework .beans .factory .config .MethodInvokingFactoryBean ;
31
33
import org .springframework .beans .factory .config .RuntimeBeanReference ;
32
34
import org .springframework .beans .factory .parsing .BeanComponentDefinition ;
33
35
import org .springframework .beans .factory .parsing .CompositeComponentDefinition ;
36
+ import org .springframework .beans .factory .support .AbstractBeanDefinition ;
34
37
import org .springframework .beans .factory .support .BeanDefinitionBuilder ;
38
+ import org .springframework .beans .factory .support .BeanDefinitionRegistry ;
39
+ import org .springframework .beans .factory .support .BeanDefinitionRegistryPostProcessor ;
35
40
import org .springframework .beans .factory .support .ManagedList ;
36
41
import org .springframework .beans .factory .support .RootBeanDefinition ;
37
42
import org .springframework .beans .factory .xml .BeanDefinitionParser ;
@@ -393,7 +398,8 @@ else if (StringUtils.hasText(before)) {
393
398
}
394
399
395
400
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 )) {
397
403
return ;
398
404
}
399
405
// Not already registered, so register the list of filter chains and the
@@ -412,10 +418,46 @@ static void registerFilterChainProxyIfNecessary(ParserContext pc, Object source)
412
418
BeanDefinition fcpBean = fcpBldr .getBeanDefinition ();
413
419
pc .registerBeanComponent (new BeanComponentDefinition (fcpBean ,
414
420
BeanIds .FILTER_CHAIN_PROXY ));
415
- pc . getRegistry () .registerAlias (BeanIds .FILTER_CHAIN_PROXY ,
421
+ registry .registerAlias (BeanIds .FILTER_CHAIN_PROXY ,
416
422
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 ;
417
447
}
418
448
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
+ }
419
461
}
420
462
421
463
class OrderDecorator implements Ordered {
0 commit comments