From 7a233c41f0d76c4d44d62689a15e9f9b7e098ce0 Mon Sep 17 00:00:00 2001 From: Kay-Uwe Janssen Date: Thu, 3 Jun 2021 10:59:45 +0200 Subject: [PATCH] Some infrastructure beans are not marked properly Added missing infrastructure role to methodSecurityMetadataSource bean and move the post processing of the defaultMethodExpressionHandler to the end of afterSingletonsInstantiated. Closes gh-9845 --- .../configuration/GlobalMethodSecurityConfiguration.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/config/src/main/java/org/springframework/security/config/annotation/method/configuration/GlobalMethodSecurityConfiguration.java b/config/src/main/java/org/springframework/security/config/annotation/method/configuration/GlobalMethodSecurityConfiguration.java index 89c713062d..27ce85758c 100644 --- a/config/src/main/java/org/springframework/security/config/annotation/method/configuration/GlobalMethodSecurityConfiguration.java +++ b/config/src/main/java/org/springframework/security/config/annotation/method/configuration/GlobalMethodSecurityConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -174,6 +174,8 @@ public class GlobalMethodSecurityConfiguration implements ImportAware, SmartInit if (grantedAuthorityDefaults != null) { this.defaultMethodExpressionHandler.setDefaultRolePrefix(grantedAuthorityDefaults.getRolePrefix()); } + + this.defaultMethodExpressionHandler = this.objectPostProcessor.postProcess(this.defaultMethodExpressionHandler); } private T getSingleBeanOrNull(Class type) { @@ -338,6 +340,7 @@ public class GlobalMethodSecurityConfiguration implements ImportAware, SmartInit * @return the {@link MethodSecurityMetadataSource} */ @Bean + @Role(BeanDefinition.ROLE_INFRASTRUCTURE) public MethodSecurityMetadataSource methodSecurityMetadataSource() { List sources = new ArrayList<>(); ExpressionBasedAnnotationAttributeFactory attributeFactory = new ExpressionBasedAnnotationAttributeFactory( @@ -397,7 +400,6 @@ public class GlobalMethodSecurityConfiguration implements ImportAware, SmartInit @Autowired(required = false) public void setObjectPostProcessor(ObjectPostProcessor objectPostProcessor) { this.objectPostProcessor = objectPostProcessor; - this.defaultMethodExpressionHandler = objectPostProcessor.postProcess(this.defaultMethodExpressionHandler); } @Autowired(required = false)