Spring Cloud Config Server 支持将 CredHub 作为配置属性的后端。 您可以通过向 Spring CredHub 添加依赖项来启用此功能。Spring中文文档

pom.xml
<dependencies>
	<dependency>
		<groupId>org.springframework.credhub</groupId>
		<artifactId>spring-credhub-starter</artifactId>
	</dependency>
</dependencies>

以下配置使用双向 TLS 访问 CredHub:Spring中文文档

spring:
  profiles:
    active: credhub
  cloud:
    config:
      server:
        credhub:
          url: https://credhub:8844

这些属性应存储为 JSON,例如:Spring中文文档

credhub set --name "/demo-app/default/master/toggles" --type=json
value: {"toggle.button": "blue", "toggle.link": "red"}
credhub set --name "/demo-app/default/master/abs" --type=json
value: {"marketing.enabled": true, "external.enabled": false}

所有具有该名称的客户端应用程序都将具有以下可用的属性:spring.cloud.config.name=demo-appSpring中文文档

{
    toggle.button: "blue",
    toggle.link: "red",
    marketing.enabled: true,
    external.enabled: false
}
未指定配置文件时,将使用配置文件,未指定标签时将用作默认值。 注意:添加的值将由所有应用程序共享。defaultmasterapplication
未指定配置文件时,将使用配置文件,未指定标签时将用作默认值。 注意:添加的值将由所有应用程序共享。defaultmasterapplication

OAuth 2.0

您可以使用 UAA 作为提供程序对 OAuth 2.0 进行身份验证。Spring中文文档

pom.xml
<dependencies>
	<dependency>
		<groupId>org.springframework.security</groupId>
		<artifactId>spring-security-config</artifactId>
	</dependency>
	<dependency>
		<groupId>org.springframework.security</groupId>
		<artifactId>spring-security-oauth2-client</artifactId>
	</dependency>
</dependencies>

以下配置使用 OAuth 2.0 和 UAA 访问 CredHub:Spring中文文档

spring:
  profiles:
    active: credhub
  cloud:
    config:
      server:
        credhub:
          url: https://credhub:8844
          oauth2:
            registration-id: credhub-client
  security:
    oauth2:
      client:
        registration:
          credhub-client:
            provider: uaa
            client-id: credhub_config_server
            client-secret: asecret
            authorization-grant-type: client_credentials
        provider:
          uaa:
            token-uri: https://uaa:8443/oauth/token
使用的 UAA client-id 应具有作用域。credhub.read
使用的 UAA client-id 应具有作用域。credhub.read