CredHub Backend
Spring Cloud Config Server 支持 CredHub作为配置属性的后端。您可以通过添加对 Spring CredHub的依赖项来启用此功能。
pom.xml
<dependencies>
<dependency>
<groupId>org.springframework.credhub</groupId>
<artifactId>spring-credhub-starter</artifactId>
</dependency>
</dependencies>
以下配置使用相互 TLS 访问 CredHub:
spring:
profiles:
active: credhub
cloud:
config:
server:
credhub:
url: https://credhub:8844
属性应该存储为 JSON,例如:
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
的客户端应用程序都将可以访问以下属性:
{ toggle.button: "blue", toggle.link: "red", marketing.enabled: true, external.enabled: false }
如果没有指定配置文件,将使用 |
OAuth 2.0
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:
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 应具有 |