对于最新的稳定版本,请使用Spring Cloud Config 5.0.0spring-doc.cadn.net.cn

CredHub 后端

Spring Cloud 配置服务器支持 CredHub 作为配置属性的后端。 您可以通过向 Spring CredHub 添加依赖来启用此功能。spring-doc.cadn.net.cn

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

以下配置使用互助TLS访问CredHub:spring-doc.cadn.net.cn

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

属性应以 JSON 形式存储,例如:spring-doc.cadn.net.cn

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-app他们将拥有以下房产:spring-doc.cadn.net.cn

{
    toggle.button: "blue",
    toggle.link: "red",
    marketing.enabled: true,
    external.enabled: false
}
当没有指定标签时主人将作为默认值使用。你可以通过设置来更改spring.cloud.config.server.credhub.defaultLabel.
当没有指定配置文件时默认值将被使用。
附加值应用所有应用都会共享。

OAuth 2.0

你可以用 UAA 作为提供者使用 OAuth 2.0 进行身份验证。spring-doc.cadn.net.cn

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-doc.cadn.net.cn

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客户端ID应该有Credhub.read作为范围。

下表描述了 CredHub 的配置属性。spring-doc.cadn.net.cn

物业名称 言论

网址spring-doc.cadn.net.cn

CredHub服务器网址。spring-doc.cadn.net.cn

路径spring-doc.cadn.net.cn

所有凭证的基础路径。可选,默认为空。spring-doc.cadn.net.cn

默认标签spring-doc.cadn.net.cn

客户端应用程序未提供默认标签。可选,默认为主人.spring-doc.cadn.net.cn

OUs2spring-doc.cadn.net.cn

OAuth2配置以访问CredHub。自选。spring-doc.cadn.net.cn