Class ConfigClientOAuth2Support
ClientHttpRequestInterceptor into a
ConfigClientRequestTemplateFactory for the Spring Cloud Config Data flow, when
Spring Security OAuth2 client classes are on the classpath and
spring.cloud.config.oauth2.enabled=true.
Every collaborator that gets built (ClientRegistrationRepository,
OAuth2AuthorizedClientManager, OAuth2ClientHttpRequestInterceptor.ClientRegistrationIdResolver, and the
interceptor itself) is looked up in the bootstrap context first via
BootstrapContext.getOrElseSupply(java.lang.Class<T>, java.util.function.Supplier<T>), so users can plug in custom
implementations by registering them in the bootstrap registry before this support class
runs. spring.cloud.config.oauth2.client-registration-id is only required when
no OAuth2ClientHttpRequestInterceptor.ClientRegistrationIdResolver has been registered.
All Spring Security references are isolated in the nested
ConfigClientOAuth2Support.OAuth2InterceptorRegistrar, which is only loaded after the
OAUTH2_CLIENT_IS_PRESENT guard passes, so config clients without Spring
Security OAuth2 on the classpath never trigger class loading of those types.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final booleanWhether Spring Security OAuth2 client classes are on the classpath.static final StringFully-qualified class name of the OAuth2 request interceptor used as the classpath probe. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidregisterInterceptor(org.springframework.boot.bootstrap.ConfigurableBootstrapContext bootstrapContext, org.springframework.boot.context.properties.bind.Binder binder, org.springframework.boot.context.properties.bind.BindHandler bindHandler, ConfigClientRequestTemplateFactory factory) Adds an OAuth2 interceptor to the given factory if Spring Security OAuth2 client is available andspring.cloud.config.oauth2.enabled=true.
-
Field Details
-
OAUTH2_INTERCEPTOR_CLASS
Fully-qualified class name of the OAuth2 request interceptor used as the classpath probe.- See Also:
-
OAUTH2_CLIENT_IS_PRESENT
public static final boolean OAUTH2_CLIENT_IS_PRESENTWhether Spring Security OAuth2 client classes are on the classpath.
-
-
Method Details
-
registerInterceptor
public static void registerInterceptor(org.springframework.boot.bootstrap.ConfigurableBootstrapContext bootstrapContext, org.springframework.boot.context.properties.bind.Binder binder, org.springframework.boot.context.properties.bind.BindHandler bindHandler, ConfigClientRequestTemplateFactory factory) Adds an OAuth2 interceptor to the given factory if Spring Security OAuth2 client is available andspring.cloud.config.oauth2.enabled=true. Otherwise this is a no-op.- Parameters:
bootstrapContext- the bootstrap context used to look up overridable collaboratorsbinder- the binder used to read OAuth2 propertiesbindHandler- the bind handler (may benull) so encrypted or placeholder values resolve consistently with the rest of the config clientfactory- the factory to add the interceptor to
-