|
@@ -5,6 +5,7 @@
|
|
|
|
|
|
package cn.com.qmth.framework.config.center.client.core;
|
|
|
|
|
|
+import cn.com.qmth.framework.config.center.client.utils.AESUtils;
|
|
|
import com.fasterxml.jackson.databind.JavaType;
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import okhttp3.*;
|
|
@@ -21,13 +22,13 @@ public class RemotePropertyLoader {
|
|
|
|
|
|
private static final String CONTENT_TYPE = "application/json; charset=UTF-8";
|
|
|
|
|
|
- public static Map<String, Object> call(String address, String namespace, String appCode, String profile) {
|
|
|
+ public static Map<String, Object> call(String address, String namespace, String appCode, String profile, String secretKey) {
|
|
|
if (StringUtils.isEmpty(address)) {
|
|
|
- throw new IllegalArgumentException(ConfigConstants.SYS_CONFIG_CENTER_ADDRESS + " is not exist");
|
|
|
+ throw new IllegalArgumentException(ConfigConstants.CONFIG_CENTER_ADDRESS + " is not exist");
|
|
|
}
|
|
|
|
|
|
if (StringUtils.isEmpty(namespace)) {
|
|
|
- throw new IllegalArgumentException(ConfigConstants.SYS_CONFIG_CENTER_NAMESPACE + " is not exist");
|
|
|
+ throw new IllegalArgumentException(ConfigConstants.CONFIG_CENTER_NAMESPACE + " is not exist");
|
|
|
}
|
|
|
|
|
|
if (StringUtils.isEmpty(appCode)) {
|
|
@@ -52,7 +53,9 @@ public class RemotePropertyLoader {
|
|
|
if (response.isSuccessful()) {
|
|
|
ObjectMapper jsonMapper = new ObjectMapper();
|
|
|
JavaType javaType = jsonMapper.getTypeFactory().constructMapType(HashMap.class, String.class, Object.class);
|
|
|
- return jsonMapper.readValue(resp, javaType);
|
|
|
+ Map<String, Object> properties = jsonMapper.readValue(resp, javaType);
|
|
|
+
|
|
|
+ return decryptProperties(properties, secretKey);
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
throw new RuntimeException(configCenterUrl + " call err! " + e.getMessage(), e);
|
|
@@ -74,4 +77,21 @@ public class RemotePropertyLoader {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private static Map<String, Object> decryptProperties(Map<String, Object> properties, String secretKey) {
|
|
|
+ Map<String, Object> finalProperties = new HashMap<>();
|
|
|
+
|
|
|
+ for (Map.Entry<String, Object> entry : properties.entrySet()) {
|
|
|
+ if (entry.getKey().startsWith(ConfigConstants.SECRET_PROPERTY_PREFIX)) {
|
|
|
+ finalProperties.put(
|
|
|
+ entry.getKey().substring(ConfigConstants.SECRET_PROPERTY_PREFIX.length()),
|
|
|
+ AESUtils.decrypt(secretKey, String.valueOf(entry.getValue()))
|
|
|
+ );
|
|
|
+ } else {
|
|
|
+ finalProperties.put(entry.getKey(), entry.getValue());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return finalProperties;
|
|
|
+ }
|
|
|
+
|
|
|
}
|