From 38f720752af4d4aad8c4e467a288d9048659f688 Mon Sep 17 00:00:00 2001 From: Rob Daugherty Date: Wed, 14 Mar 2018 02:07:32 -0400 Subject: AT&T 1712 and 1802 release code This is code from AT&T's 1712 and 1802 releases. Change-Id: Ie1e85851e94bc66c4d9514a0226c221939531a04 Issue-ID: SO-425 Signed-off-by: Rob Daugherty --- .../mso/properties/MsoJavaProperties.java | 46 +++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) (limited to 'common/src/main/java/org/openecomp/mso/properties') 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 asMap() { + final Map result = new HashMap<>(); + msoProperties.forEach((key, value) -> result.put(key.toString(), value.toString())); + + return result; + } + } -- cgit 1.2.3-korg