Class ConfigClientOAuth2Support

java.lang.Object
org.springframework.cloud.config.client.oauth2.ConfigClientOAuth2Support

public final class ConfigClientOAuth2Support extends Object
Wires the OAuth2 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

    Fields
    Modifier and Type
    Field
    Description
    static final boolean
    Whether Spring Security OAuth2 client classes are on the classpath.
    static final String
    Fully-qualified class name of the OAuth2 request interceptor used as the classpath probe.
  • Method Summary

    Modifier and Type
    Method
    Description
    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 and spring.cloud.config.oauth2.enabled=true.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • OAUTH2_INTERCEPTOR_CLASS

      public static final String 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_PRESENT
      Whether 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 and spring.cloud.config.oauth2.enabled=true. Otherwise this is a no-op.
      Parameters:
      bootstrapContext - the bootstrap context used to look up overridable collaborators
      binder - the binder used to read OAuth2 properties
      bindHandler - the bind handler (may be null) so encrypted or placeholder values resolve consistently with the rest of the config client
      factory - the factory to add the interceptor to