SpringCloud CredHub后端

2023-06-17 12:58 更新

Spring Cloud Config服務(wù)器支持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

屬性應(yīng)存儲為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?的所有客戶端應(yīng)用程序?qū)⒕哂幸韵聦傩裕?/p>

{
    toggle.button: "blue",
    toggle.link: "red",
    marketing.enabled: true,
    external.enabled: false
}

如果未指定配置文件,將使用default,而未指定標簽時,將使用master作為默認值。注意:添加到 application的值將由所有應(yīng)用程序共享。

OAuth 2.0

您可以使用UAA作為提供程序通過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的范圍應(yīng)為?credhub.read?。

以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號