summaryrefslogtreecommitdiffstats
path: root/appc-config/appc-encryption-tool/provider/src/main
diff options
context:
space:
mode:
authorGeorge, Lina (lg941u) <lg941u@att.com>2018-09-18 14:30:52 -0400
committerTakamune Cho <tc012c@att.com>2018-09-19 14:06:32 +0000
commitba28cb6a1255a7372c00b2dee85be1f15e86c8fd (patch)
tree360ad4db4031044a7ed68646f16511313036adf4 /appc-config/appc-encryption-tool/provider/src/main
parent2133020f219c8ec31c748d0a3ff9c063aa15dde9 (diff)
Changes to encryptionToolDGWrapper
Issue-ID: APPC-1199 Change-Id: Ifa93fd75d08081e0fdc8fc4f941934df0cc4706a Signed-off-by: George, Lina (lg941u) <lg941u@att.com>
Diffstat (limited to 'appc-config/appc-encryption-tool/provider/src/main')
-rw-r--r--appc-config/appc-encryption-tool/provider/src/main/java/org/onap/appc/encryptiontool/wrapper/EncryptionToolDGWrapper.java109
1 files changed, 68 insertions, 41 deletions
diff --git a/appc-config/appc-encryption-tool/provider/src/main/java/org/onap/appc/encryptiontool/wrapper/EncryptionToolDGWrapper.java b/appc-config/appc-encryption-tool/provider/src/main/java/org/onap/appc/encryptiontool/wrapper/EncryptionToolDGWrapper.java
index 49bc15f97..fa7075eff 100644
--- a/appc-config/appc-encryption-tool/provider/src/main/java/org/onap/appc/encryptiontool/wrapper/EncryptionToolDGWrapper.java
+++ b/appc-config/appc-encryption-tool/provider/src/main/java/org/onap/appc/encryptiontool/wrapper/EncryptionToolDGWrapper.java
@@ -30,80 +30,107 @@ import org.apache.commons.lang.StringUtils;
import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
import org.onap.ccsdk.sli.core.sli.SvcLogicException;
import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin;
+import org.onap.ccsdk.sli.core.sli.SvcLogicResource;
+import org.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus;
import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
+import org.onap.ccsdk.sli.adaptors.resource.sql.SqlResource;
public class EncryptionToolDGWrapper implements SvcLogicJavaPlugin {
-
private static final EELFLogger log = EELFManager.getInstance().getLogger(EncryptionToolDGWrapper.class);
+ private SvcLogicResource serviceLogic;
+ private static EncryptionToolDGWrapper dgGeneralDBService = null;
+
+ public static EncryptionToolDGWrapper initialise() {
+ if (dgGeneralDBService == null) {
+ dgGeneralDBService = new EncryptionToolDGWrapper();
+ }
+ return dgGeneralDBService;
+ }
+
+ public EncryptionToolDGWrapper() {
+ if (serviceLogic == null) {
+ serviceLogic = new SqlResource();
+ }
+ }
+
+ protected EncryptionToolDGWrapper(SqlResource svcLogic) {
+ if (serviceLogic == null) {
+ serviceLogic = svcLogic;
+ }
+ }
public void runEncryption(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
String userName = inParams.get("userName");
String password = inParams.get("password");
String vnfType = inParams.get("vnf_type");
-
try {
if (StringUtils.isBlank(userName) || StringUtils.isBlank(password) || StringUtils.isBlank(vnfType)) {
throw new SvcLogicException("username or Password is missing");
}
-
String[] input = new String[] { vnfType, userName, password };
WrapperEncryptionTool.main(input);
-
} catch (Exception e) {
throw new SvcLogicException(e.getMessage());
}
-
}
public void getProperty(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
+ String fn = "getproperty.deviceauthentication";
String responsePrefix = inParams.get("prefix");
String vnf_Type = ctx.getAttribute("vnf-type");
String action = ctx.getAttribute("input.action");
String protocol = ctx.getAttribute("APPC.protocol.PROTOCOL");
+ String user = "";
+ String password = "";
+ String port = "0";
+ String url = "";
+ QueryStatus status = null;
+
+ responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
try {
- responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
- PropertiesConfiguration conf = new PropertiesConfiguration(
- Constants.APPC_CONFIG_DIR + "/appc_southbound.properties");
- conf.setBasePath(null);
- EncryptionTool et = EncryptionTool.getInstance();
- log.info("responsePrefix:"+responsePrefix);
- log.debug("key:"+vnf_Type+"."+protocol+"."+action);
- if(StringUtils.isNotBlank(vnf_Type) && StringUtils.isNotBlank(protocol) && StringUtils.isNotBlank(action))
- {
- String user = (String)conf.getProperty(vnf_Type + "." + protocol + "." + action + "." + "user");
- String password = (String)conf.getProperty(vnf_Type + "." + protocol + "." + action + "." + "password");
- String port = (String)conf.getProperty(vnf_Type + "." + protocol + "." + action + "." + "port");
- String url = (String)conf.getProperty(vnf_Type + "." + protocol + "." + action + "." + "url");
- if (StringUtils.isBlank(user) || StringUtils.isBlank(password)) {
- throw new SvcLogicException("Error-while fetching user or password");
- }
- if ( (user.startsWith("[") && user.endsWith("]")) || (password.startsWith("[") && password.endsWith("]"))|| (port.startsWith("[") && port.endsWith("]"))||(url.startsWith("[") && url.endsWith("]")) )
- {
- throw new SvcLogicException("Duplicate entries found for key "+vnf_Type + "." + protocol + "." + action +"in properties File");
- }
- if (StringUtils.isNotBlank(user))
- ctx.setAttribute(responsePrefix + "user", user);
- if (StringUtils.isNotBlank(password))
- ctx.setAttribute(responsePrefix + "password", et.decrypt(password));
- if (StringUtils.isNotBlank(url))
- ctx.setAttribute(responsePrefix + "url", url);
- if (StringUtils.isNotBlank(port))
- ctx.setAttribute(responsePrefix + "port", port);
- log.debug(ctx.getAttribute(responsePrefix + "user"));
- log.debug(ctx.getAttribute(responsePrefix + "password"));
- log.debug(ctx.getAttribute(responsePrefix + "url"));
- log.debug(ctx.getAttribute(responsePrefix + "port"));
- }
- else
- {
- throw new SvcLogicException("Error-as any of properties such as vnf-type,protocol,action are missing in ctx");
+ if (serviceLogic != null && ctx != null) {
+ String key = "SELECT USER_NAME ,PASSWORD,PORT_NUMBER,URL FROM DEVICE_AUTHENTICATION WHERE VNF_TYPE = '"
+ + vnf_Type + "' AND PROTOCOL = '" + protocol + "' AND ACTION = '" + action + "'";
+ log.info("Getting authentication details :" + key);
+ status = serviceLogic.query("SQL", false, null, key, null, null, ctx);
+ if (status == QueryStatus.FAILURE) {
+ log.info(fn + ":: Error retrieving credentials");
+ throw new SvcLogicException("Error retrieving credentials");
+ }
+ if (status == QueryStatus.NOT_FOUND) {
+ log.info(fn + ":: NOT_FOUND! No data found in device_authentication table for " + vnf_Type + " "
+ + protocol + "" + action + "");
+ throw new SvcLogicException(fn + ":: NOT_FOUND! No data found in device_authentication table for "
+ + vnf_Type + " " + protocol + "" + action + "");
}
+
+ user = ctx.getAttribute("USER-NAME");
+ password = ctx.getAttribute("PASSWORD");
+ port = ctx.getAttribute("PORT-NUMBER");
+ url = ctx.getAttribute("URL");
+ log.info("data retrieved " + "user" + user + "pwd" + password + "port" + port + "url" + url);
+
+ if (StringUtils.isNotBlank(user))
+ ctx.setAttribute(responsePrefix + "user", user);
+ if (StringUtils.isNotBlank(password))
+ ctx.setAttribute(responsePrefix + "password", password);
+ if (StringUtils.isNotBlank(url))
+ ctx.setAttribute(responsePrefix + "url", url);
+ if (StringUtils.isNotBlank(port))
+ ctx.setAttribute(responsePrefix + "port", port);
+ log.debug("user" + ctx.getAttribute(responsePrefix + "user"));
+ log.debug("password" + ctx.getAttribute(responsePrefix + "password"));
+ log.debug("url" + ctx.getAttribute(responsePrefix + "url"));
+ log.debug("port" + ctx.getAttribute(responsePrefix + "port"));
+
+ }
} catch (Exception e) {
ctx.setAttribute(responsePrefix + "status", "failure");
ctx.setAttribute(responsePrefix + "error-message", e.getMessage());
log.info("Caught exception", e);
throw new SvcLogicException(e.getMessage());
+
}
}
}