Cloud FoundryにデプロイされるSpringBoot上のアプリケーションがあります。これには、セキュリティ関連のデータを受け取るために私のapplication.propertiesファイルで使用できるVCAP_SERVICESにいくつかの情報を添付するバインドされたサービスがあります。@ConfigurationPropertiesを使用してCF環境をネストしたJSONを読む
このサービス変数は、全体VCAP_SERVICE環境変数のuser-provided
サブJSONであり、次のようになります。私のapplication.propertiesで
"user-provided": [
{
"credentials": {
"auth-scopes": {
"group-1": "superadmin",
"group-2": "admin"
},
"base64ClientCredential": "SSBBTSBOT1QgVEhBVCBTSUxMWSA6LUQ=",
"client-id": "my-app",
"client-secret": "g1234567890",
"token-info-uri": "https://XYZ.predix.io/check_token",
"user-info-uri": "https://XYZ.predix.io/userinfo"
},
"label": "user-provided",
"name": "my-app-creds",
"syslog_drain_url": "",
"tags": [],
"volume_mounts": []
}
]
は私が
security.properties.client-id=${vcap.services.my-app-creds.credentials.client-id}
security.properties.client-secret=${vcap.services.my-app-creds.credentials.client-secret}
security.properties.token-info-uri=${vcap.services.my-app-creds.credentials.token-info-uri}
security.properties.user-info-uri=${vcap.services.my-app-creds.credentials.user-info-uri}
security.properties.auth-scopes=${vcap.services.my-app-creds.credentials.auth-scopes}
を持っている私も、作成したクラスSecurityProperties
これらのプロパティを読み込んでJAVAに格納する:
@Component
@PropertySource("classpath:application.properties")
@ConfigurationProperties(prefix = "security.properties")
public class SecurityProperties {
String clientId;
String clientSecret;
String tokenInfoUri;
String userInfoUri;
//Required getters and setters
}
そして、このクラスは、application.properties
から受け取った情報にこれらのフィールドを正常にバインドします。
私が地図を受信したいときに問題が発生します。
"auth-scopes": {
"group-1": "superadmin",
"group-2": "admin"
}
私はSecurityProperties
クラスフィールドに追加してみました:
HashMap<String, String> authScopes;
しかし、それは私も内部クラス
で試してみましたを失敗しました
AuthScopes authScopes;
public static class AuthScopes {
//various different implementations
//to read this but no success at all
}
私は他のアイディアを使い果たしました。私はちょうどこれを得る方法を理解することができません。私もauth-scopes
jsonからVCAPS
の文字列として読み込まれ、それから私はそれを解析します - 問題は受け入れます。問題は、SecurityProperties
フィールドにString authScopes
を追加しても、正確にはこの文字列にバインドされているということです:"${vcap.services.my-app-creds.credentials.auth-scopes}"
。役に立った
ご意見がありましたら、どうぞ。
この回答ありがとうございます。これは私が恐れていたものです。私は、vcapを逆にして権威を与えられたグループのリスト(私がすでにチェックし、それが働いていた)であるプロパティを作成すると思います。 – Zychoo