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)