From a8f3d035937d24db06f79954226ef071f2408669 Mon Sep 17 00:00:00 2001 From: Ryan Baxter Date: Thu, 13 Oct 2016 10:42:46 -0400 Subject: [PATCH] Fixes #501 (#523) --- .../main/asciidoc/spring-cloud-config.adoc | 48 ++++++++++++++++++- 1 file changed, 46 insertions(+), 2 deletions(-) diff --git a/docs/src/main/asciidoc/spring-cloud-config.adoc b/docs/src/main/asciidoc/spring-cloud-config.adoc index e956a30e..0425a6be 100644 --- a/docs/src/main/asciidoc/spring-cloud-config.adoc +++ b/docs/src/main/asciidoc/spring-cloud-config.adoc @@ -1162,10 +1162,54 @@ spring: ---- -If you use another form of security you might need to provide a -`RestTemplate` to the `ConfigServicePropertySourceLocator` (e.g. by +If you use another form of security you might need to <> to the `ConfigServicePropertySourceLocator` (e.g. by grabbing it in the bootstrap context and injecting one). +[[custom-rest-template]] +==== Providing A Custom RestTemplate + +In some cases you might need to customize the requests made to the config server from +the client. Typically this involves passing special `Authorization` headers to +authenticate requests to the server. To provide a custom `RestTemplate` follow the +steps below. + +1. Set `spring.cloud.config.enabled=false` to disable the existing config server +property source. + +2. Create a new configuration bean with an implementation of `PropertySourceLocator`. + +.CustomConfigServiceBootstrapConfiguration.java +[source,java] +---- +@Configuration +public class CustomConfigServiceBootstrapConfiguration { + @Bean + public ConfigClientProperties configClientProperties() { + ConfigClientProperties client = new ConfigClientProperties(this.environment); + client.setEnabled(false); + return client; + } + + @Bean + public ConfigServicePropertySourceLocator configServicePropertySourceLocator() { + ConfigClientProperties clientProperties = configClientProperties(); + ConfigServicePropertySourceLocator configServicePropertySourceLocator = new ConfigServicePropertySourceLocator(clientProperties); + configServicePropertySourceLocator.setRestTemplate(customRestTemplate(clientProperties)); + return configServicePropertySourceLocator; + } +} +---- + +3. In `resource/META_INF` create a file called +`spring.factories` and specify your custom configuration. + +.spring.factorties +[source,properties] +---- +org.springframework.cloud.bootstrap.BootstrapConfiguration = com.my.config.client.CustomConfigServiceBootstrapConfiguration +---- + ==== Vault When using Vault as a backend to your config server the client will need to