diff --git a/config/src/main/java/org/springframework/security/config/annotation/web/configuration/OAuth2ClientConfiguration.java b/config/src/main/java/org/springframework/security/config/annotation/web/configuration/OAuth2ClientConfiguration.java index 668963f9d52..ef7826412c0 100644 --- a/config/src/main/java/org/springframework/security/config/annotation/web/configuration/OAuth2ClientConfiguration.java +++ b/config/src/main/java/org/springframework/security/config/annotation/web/configuration/OAuth2ClientConfiguration.java @@ -106,7 +106,7 @@ public String[] selectImports(AnnotationMetadata importingClassMetadata) { @Configuration(proxyBeanMethods = false) static class OAuth2AuthorizedClientManagerConfiguration { - @Bean + @Bean(name = OAuth2AuthorizedClientManagerRegistrar.BEAN_NAME) OAuth2AuthorizedClientManagerRegistrar authorizedClientManagerRegistrar() { return new OAuth2AuthorizedClientManagerRegistrar(); } @@ -173,6 +173,10 @@ private OAuth2AuthorizedClientManager getAuthorizedClientManager() { static final class OAuth2AuthorizedClientManagerRegistrar implements BeanDefinitionRegistryPostProcessor, BeanFactoryAware { + static final String BEAN_NAME = "authorizedClientManagerRegistrar"; + + static final String FACTORY_METHOD_NAME = "getAuthorizedClientManager"; + // @formatter:off private static final Set> KNOWN_AUTHORIZED_CLIENT_PROVIDERS = Set.of( AuthorizationCodeOAuth2AuthorizedClientProvider.class, @@ -196,7 +200,8 @@ public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) t } BeanDefinition beanDefinition = BeanDefinitionBuilder - .genericBeanDefinition(OAuth2AuthorizedClientManager.class, this::getAuthorizedClientManager) + .rootBeanDefinition(OAuth2AuthorizedClientManager.class) + .setFactoryMethodOnBean(FACTORY_METHOD_NAME, BEAN_NAME) .getBeanDefinition(); registry.registerBeanDefinition(this.beanNameGenerator.generateBeanName(beanDefinition, registry), @@ -220,7 +225,7 @@ OAuth2AuthorizedClientManager getAuthorizedClientManagerIfAvailable() { return getAuthorizedClientManager(); } - private OAuth2AuthorizedClientManager getAuthorizedClientManager() { + OAuth2AuthorizedClientManager getAuthorizedClientManager() { ClientRegistrationRepository clientRegistrationRepository = BeanFactoryUtils .beanOfTypeIncludingAncestors(this.beanFactory, ClientRegistrationRepository.class, true, true); diff --git a/config/src/main/java/org/springframework/security/config/http/AuthenticationConfigBuilder.java b/config/src/main/java/org/springframework/security/config/http/AuthenticationConfigBuilder.java index 6a80bafce57..3172d407601 100644 --- a/config/src/main/java/org/springframework/security/config/http/AuthenticationConfigBuilder.java +++ b/config/src/main/java/org/springframework/security/config/http/AuthenticationConfigBuilder.java @@ -422,7 +422,9 @@ private void registerOAuth2ClientPostProcessors() { .registerWithGeneratedName(new RootBeanDefinition(OAuth2ClientWebMvcSecurityPostProcessor.class)); } this.pc.getReaderContext() - .registerWithGeneratedName(new RootBeanDefinition(OAuth2AuthorizedClientManagerRegistrar.class)); + .getRegistry() + .registerBeanDefinition(OAuth2AuthorizedClientManagerRegistrar.BEAN_NAME, + new RootBeanDefinition(OAuth2AuthorizedClientManagerRegistrar.class)); } private void createSaml2LoginFilter(BeanReference authenticationManager, diff --git a/config/src/main/java/org/springframework/security/config/http/OAuth2AuthorizedClientManagerRegistrar.java b/config/src/main/java/org/springframework/security/config/http/OAuth2AuthorizedClientManagerRegistrar.java index 8693333c3ce..0020017bb5c 100644 --- a/config/src/main/java/org/springframework/security/config/http/OAuth2AuthorizedClientManagerRegistrar.java +++ b/config/src/main/java/org/springframework/security/config/http/OAuth2AuthorizedClientManagerRegistrar.java @@ -66,6 +66,10 @@ */ final class OAuth2AuthorizedClientManagerRegistrar implements BeanDefinitionRegistryPostProcessor, BeanFactoryAware { + static final String BEAN_NAME = "authorizedClientManagerRegistrar"; + + static final String FACTORY_METHOD_NAME = "getAuthorizedClientManager"; + // @formatter:off private static final Set> KNOWN_AUTHORIZED_CLIENT_PROVIDERS = Set.of( AuthorizationCodeOAuth2AuthorizedClientProvider.class, @@ -88,8 +92,8 @@ public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) t return; } - BeanDefinition beanDefinition = BeanDefinitionBuilder - .genericBeanDefinition(OAuth2AuthorizedClientManager.class, this::getAuthorizedClientManager) + BeanDefinition beanDefinition = BeanDefinitionBuilder.rootBeanDefinition(OAuth2AuthorizedClientManager.class) + .setFactoryMethodOnBean(FACTORY_METHOD_NAME, BEAN_NAME) .getBeanDefinition(); registry.registerBeanDefinition(this.beanNameGenerator.generateBeanName(beanDefinition, registry),