aboutsummaryrefslogtreecommitdiffstats
path: root/common/src/main/java/org/openecomp/mso/properties/MsoJavaProperties.java
diff options
context:
space:
mode:
authorSeshu Kumar M <seshu.kumar.m@huawei.com>2018-03-14 09:22:15 +0000
committerGerrit Code Review <gerrit@onap.org>2018-03-14 09:22:15 +0000
commit09f3630ea990197e9d7b669aa2d6a63ec397bf3e (patch)
tree6625d3e9ac31600d86bf54a50e75dba61cc2c82a /common/src/main/java/org/openecomp/mso/properties/MsoJavaProperties.java
parenta56de0e221751debd038aca5b6d20d8f9325d294 (diff)
parent38f720752af4d4aad8c4e467a288d9048659f688 (diff)
Merge "AT&T 1712 and 1802 release code"
Diffstat (limited to 'common/src/main/java/org/openecomp/mso/properties/MsoJavaProperties.java')
-rw-r--r--common/src/main/java/org/openecomp/mso/properties/MsoJavaProperties.java46
1 files changed, 45 insertions, 1 deletions
diff --git a/common/src/main/java/org/openecomp/mso/properties/MsoJavaProperties.java b/common/src/main/java/org/openecomp/mso/properties/MsoJavaProperties.java
index f0ca191978..c13b9e0b53 100644
--- a/common/src/main/java/org/openecomp/mso/properties/MsoJavaProperties.java
+++ b/common/src/main/java/org/openecomp/mso/properties/MsoJavaProperties.java
@@ -24,7 +24,11 @@ package org.openecomp.mso.properties;
import java.io.FileReader;
import java.io.IOException;
import java.security.GeneralSecurityException;
+import java.util.HashMap;
+import java.util.Map;
import java.util.Properties;
+
+import org.apache.commons.codec.binary.Base64;
import org.openecomp.mso.utils.CryptoUtils;
public class MsoJavaProperties extends AbstractMsoProperties {
@@ -86,11 +90,43 @@ public class MsoJavaProperties extends AbstractMsoProperties {
}
+ /**
+ * @param encryptedAuth: encrypted credentials from properties
+ * @param msoKey: key to use to decrypt from properties
+ * @return base 64 encoded basic auth credentials
+ */
+ public synchronized String getBasicAuth(String encryptedAuth, String msoKey){
+ String encodedString = null;
+ if ((encryptedAuth == null || encryptedAuth.isEmpty()) || (msoKey == null || msoKey.isEmpty()))
+ return null;
+ try {
+ String auth = decrypt(encryptedAuth, msoKey);
+ byte[] encoded = Base64.encodeBase64(auth.getBytes());
+ encodedString = new String(encoded);
+ encodedString = "Basic " + encodedString;
+
+ } catch (Exception ex) {
+ LOGGER.debug("Exception while getBasicAuth " + encryptedAuth, ex);
+ }
+ return encodedString;
+ }
+
public synchronized int size() {
return this.msoProperties.size();
}
-
+ public synchronized String decrypt(String toDecrypt, String msokey){
+ String result = null;
+ try {
+ result = CryptoUtils.decrypt(toDecrypt, msokey);
+
+ }
+ catch (Exception e) {
+ LOGGER.debug("Failed to decrypt credentials: " + toDecrypt, e);
+ }
+ return result;
+ }
+
@Override
protected synchronized void reloadPropertiesFile() throws IOException {
this.loadPropertiesFile(this.propertiesFileName);
@@ -181,4 +217,12 @@ public class MsoJavaProperties extends AbstractMsoProperties {
return response.toString();
}
+
+ public Map<String, String> asMap() {
+ final Map<String, String> result = new HashMap<>();
+ msoProperties.forEach((key, value) -> result.put(key.toString(), value.toString()));
+
+ return result;
+ }
+
}