diff options
author | George, Lina (lg941u) <lg941u@att.com> | 2018-01-04 14:41:40 -0500 |
---|---|---|
committer | Patrick Brady <pb071s@att.com> | 2018-01-09 22:14:02 +0000 |
commit | c6cb076e759b2e2c3e55867992500ea593001bca (patch) | |
tree | 54e3a90a54b6a06b1e79f836b3699cea84046c95 /appc-config/appc-encryption-tool | |
parent | 108ff43f43cb3a662514c6f27d806fe3a86caade (diff) |
Updates to config encryptiontool bundle
Issue-ID: APPC-354
Change-Id: I8903cb31001e96f05e7b4774d93b00941039d62e
Signed-off-by: George, Lina (lg941u) <lg941u@att.com>
Diffstat (limited to 'appc-config/appc-encryption-tool')
5 files changed, 340 insertions, 120 deletions
diff --git a/appc-config/appc-encryption-tool/provider/src/main/java/org/onap/appc/encryptiontool/wrapper/Constants.java b/appc-config/appc-encryption-tool/provider/src/main/java/org/onap/appc/encryptiontool/wrapper/Constants.java index e3db30df6..b91ccbc72 100644 --- a/appc-config/appc-encryption-tool/provider/src/main/java/org/onap/appc/encryptiontool/wrapper/Constants.java +++ b/appc-config/appc-encryption-tool/provider/src/main/java/org/onap/appc/encryptiontool/wrapper/Constants.java @@ -29,5 +29,5 @@ public class Constants private static final String SDNC_CONFIG_DIR_VAR = "SDNC_CONFIG_DIR"; - public static final String APPC_CONFIG_DIR="/opt/app/bvc/properties"; + public static final String APPC_CONFIG_DIR="/opt/onap/appc/data/properties"; } 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 c30f05033..40fcf1a53 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 @@ -9,15 +9,15 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. * ============LICENSE_END========================================================= */ @@ -48,7 +48,7 @@ public class EncryptionToolDGWrapper implements SvcLogicJavaPlugin { throw new SvcLogicException("username or Password is missing"); } - String[] input = new String[] {vnfType, userName, password}; + String[] input = new String[] { vnfType, userName, password }; WrapperEncryptionTool.main(input); } catch (Exception e) { @@ -59,16 +59,47 @@ public class EncryptionToolDGWrapper implements SvcLogicJavaPlugin { public void getProperty(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException { String responsePrefix = inParams.get("prefix"); - String propertyName = inParams.get("propertyName"); - + String vnf_Type = ctx.getAttribute("vnf-type"); + String action = ctx.getAttribute("input.action"); + String protocol = ctx.getAttribute("APPC.protocol.PROTOCOL"); try { responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : ""; - PropertiesConfiguration conf = - new PropertiesConfiguration(Constants.APPC_CONFIG_DIR + "/appc_southbound.properties"); + PropertiesConfiguration conf = new PropertiesConfiguration( + Constants.APPC_CONFIG_DIR + "/appc_southbound.properties"); conf.setBasePath(null); EncryptionTool et = EncryptionTool.getInstance(); - - ctx.setAttribute(responsePrefix + "propertyName", et.decrypt(conf.getProperty(propertyName).toString())); + 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"); + } } catch (Exception e) { ctx.setAttribute(responsePrefix + "status", "failure"); ctx.setAttribute(responsePrefix + "error-message", e.getMessage()); @@ -76,4 +107,4 @@ public class EncryptionToolDGWrapper implements SvcLogicJavaPlugin { throw new SvcLogicException(e.getMessage()); } } -} +}
\ No newline at end of file diff --git a/appc-config/appc-encryption-tool/provider/src/main/java/org/onap/appc/encryptiontool/wrapper/LoadFromDB.java b/appc-config/appc-encryption-tool/provider/src/main/java/org/onap/appc/encryptiontool/wrapper/LoadFromDB.java new file mode 100644 index 000000000..78c4578f1 --- /dev/null +++ b/appc-config/appc-encryption-tool/provider/src/main/java/org/onap/appc/encryptiontool/wrapper/LoadFromDB.java @@ -0,0 +1,113 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ +package org.onap.appc.encryptiontool.wrapper; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; +import java.io.File; +import javax.sql.rowset.CachedRowSet; + +import org.apache.commons.configuration.PropertiesConfiguration; +import org.onap.ccsdk.sli.core.dblib.DBResourceManager; +import org.slf4j.*; + +public class LoadFromDB { + + private static final Logger log = LoggerFactory + .getLogger(WrapperEncryptionTool.class); + public static void main(String[] args) { + int rowCount =0; + ArrayList argList=null; + + String getselectData = " DA.VNF_TYPE, PR.PROTOCOL, PR.ACTION ,DA.USER_NAME,DA.PASSWORD,DA.PORT_NUMBER "; + + String clause = " DA.VNF_TYPE=PR.VNF_TYPE group by PR.ACTION "; + String tableName ="DEVICE_AUTHENTICATION DA , PROTOCOL_REFERENCE PR"; + DBResourceManager dbResourceManager = null; + try { + + dbResourceManager = DbServiceUtil.initDbLibService(); + CachedRowSet data = DbServiceUtil.getData(tableName, argList, Constants.SCHEMA_SDNCTL, getselectData,clause ); + + Map <String,String> mp = new HashMap<String,String>(); + while (data.next()) { + + mp.put(data.getString(1)+"."+data.getString(2)+"."+data.getString(3)+"."+"user",data.getString(4)); + mp.put(data.getString(1)+"."+data.getString(2)+"."+data.getString(3)+"."+"password",data.getString(5)); + mp.put(data.getString(1)+"."+data.getString(2)+"."+data.getString(3)+"."+"port",data.getString(6)); + mp.put(data.getString(1)+"."+data.getString(2)+"."+data.getString(3)+"."+"url",""); + rowCount++; + } + + + log.info("Size of Map data:"+mp.size()); + File file = new File(System.getenv("APPC_CONFIG_DIR")); + file.mkdir(); + file = new File(System.getenv("APPC_CONFIG_DIR")+"/appc_southbound.properties"); + if(file.exists()) + { + log.info("APPC-MESSAGE:" + " File already Exists"); + } + else + { + file.createNewFile(); + log.info("APPC-MESSAGE:" + " New File is created"); + } + if (rowCount == 0) + log.info("APPC-MESSAGE: ERROR - No record Found "); + else { + + + log.info("Size of Map file:"+mp.size()); + PropertiesConfiguration conf = new PropertiesConfiguration( + System.getenv("APPC_CONFIG_DIR")+"/appc_southbound.properties"); + + + for (Map.Entry<String, String> key : mp.entrySet()) { + log.debug(key.getKey() + ":" + key.getValue()); + if(key.getValue()==null) + { + key.setValue(""); + } + conf.setProperty(key.getKey(), key.getValue()); + } + + + conf.save(); + log.info("APPC-MESSAGE:" + "properties updated successfully"); + + } + } catch (Exception e) { + log.info("Caught exception", e); + log.info("APPC-MESSAGE:" + e.getMessage()); + } finally { + if (dbResourceManager != null) { + dbResourceManager.cleanUp(); + System.exit(0); + } + } + } + +} diff --git a/appc-config/appc-encryption-tool/provider/src/main/java/org/onap/appc/encryptiontool/wrapper/WrapperEncryptionTool.java b/appc-config/appc-encryption-tool/provider/src/main/java/org/onap/appc/encryptiontool/wrapper/WrapperEncryptionTool.java index 9cc322259..78acd8932 100644 --- a/appc-config/appc-encryption-tool/provider/src/main/java/org/onap/appc/encryptiontool/wrapper/WrapperEncryptionTool.java +++ b/appc-config/appc-encryption-tool/provider/src/main/java/org/onap/appc/encryptiontool/wrapper/WrapperEncryptionTool.java @@ -9,121 +9,168 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. * ============LICENSE_END========================================================= */ package org.onap.appc.encryptiontool.wrapper; -import java.util.ArrayList; - -import javax.sql.rowset.CachedRowSet; - +import java.util.Iterator; import org.apache.commons.configuration.PropertiesConfiguration; -import org.onap.ccsdk.sli.core.dblib.DBResourceManager; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.apache.commons.lang.StringUtils; public class WrapperEncryptionTool { private static final Logger log = LoggerFactory.getLogger(WrapperEncryptionTool.class); public static void main(String[] args) { - int rowCount = 0; - String vnfType = args[0]; - String user = args[1]; - String password = args[2]; - String action = args[3]; - String port = args[4]; - String url = args[5]; - - if ("".equals(vnfType)) { - log.info("ERROR-VNF_TYPE can not be null"); - return; - } - if ("".equals(user)) { + String vnf_type = args[0]; + String protocol = args[1]; + String user = args[2]; + String password = args[3]; + String action = args[4]; + String port = args[5]; + String url = args[6]; + + if (StringUtils.isNotBlank(user)) { log.info("ERROR-USER can not be null"); - return; + return; } - if ("".equals(password)) { + if (StringUtils.isNotBlank(password)) { log.info("ERROR-PASSWORD can not be null"); return; } + if (StringUtils.isNotBlank(protocol) || StringUtils.isNotBlank(vnf_type) || StringUtils.isNotBlank(action)) { + log.info("ERROR-PROTOCOL ,Action and VNF-TYPE both can not be null"); + return; + } EncryptionTool et = EncryptionTool.getInstance(); String enPass = et.encrypt(password); - if (action != null && !action.isEmpty()) { - updateProperties(user, vnfType, enPass, action, port, url); + if ((protocol != null && !protocol.isEmpty())) { + updateProperties(user, vnf_type, enPass, action, port, url, protocol); return; } - ArrayList<String> argList = new ArrayList<>(); - argList.add(vnfType); - argList.add(user); - String clause = " vnfType = ? and user_name = ? "; - String setClause = " password = ? "; - String getselectData = " * "; - DBResourceManager dbResourceManager = null; + } + + public static void updateProperties(String user, String vnf_type, String password, String action, String port, + String url, String protocol) { try { - dbResourceManager = DbServiceUtil.initDbLibService(); - CachedRowSet data = DbServiceUtil.getData(Constants.DEVICE_AUTHENTICATION, argList,Constants.SCHEMA_SDNCTL, getselectData, clause); + log.info("Received Inputs protocol:%s User:%s vnfType:%s action:%surl:%s port:%s ", protocol, user, + vnf_type, action, url, port); + String property = protocol; + if (!StringUtils.isNotBlank(vnf_type)) { - while (data.next()) { - rowCount++; - } - if (rowCount == 0) - log.info("APPC-MESSAGE: ERROR - No record Found for VNF_TYPE: %, User % ", vnfType, user); - else { - argList.clear(); - argList.add(enPass); - argList.add(vnfType); - argList.add(user); - DbServiceUtil.updateDB(Constants.DEVICE_AUTHENTICATION, argList, Constants.SCHEMA_SDNCTL, clause, - setClause); - log.info("APPC-MESSAGE: Password Updated Successfully"); - } - } catch (Exception e) { - log.info("Caught exception", e); - log.info("APPC-MESSAGE:" + e.getMessage()); - } finally { - if (dbResourceManager != null) { - dbResourceManager.cleanUp(); - } - } - } + if (!StringUtils.isNotBlank(protocol)) { + if (!StringUtils.isNotBlank(action)) { - private static void updateProperties(String user, String vnfType, String password, String action, String port, - String url) { + property = vnf_type + "." + protocol + "." + action; - log.info("Received Inputs User:%s vnfType:%s action:%s", user, vnfType, action); - String property = vnfType + "." + action + "."; + } + } else { + property = vnf_type; + } - try { - PropertiesConfiguration conf = - new PropertiesConfiguration(Constants.APPC_CONFIG_DIR + "/appc_southbound.properties"); - conf.setProperty(property + "user", user); - if (port != null && !port.isEmpty()) - conf.setProperty(property + "port", port); - if (password != null && !password.isEmpty()) - conf.setProperty(property + "password", password); - if (url != null && !url.isEmpty()) - conf.setProperty(property + "url", url); + } else { + + if (!StringUtils.isNotBlank(protocol)) { + property = protocol; + + } + } + PropertiesConfiguration conf = new PropertiesConfiguration( + System.getenv("APPC_CONFIG_DIR")+"/appc_southbound.properties"); + + if (conf.subset(property) != null) { + + Iterator<String> it = conf.subset(property).getKeys(); + if (it.hasNext()) { + while (it.hasNext()) { + String key = it.next(); + log.info("key---value pairs"); + log.info(property + "." + key + "------" + conf.getProperty(property + "." + key)); + if ((property + "." + key).contains("user")) { + if (user != null && !user.isEmpty()) + conf.setProperty(property + "." + key, user); + } + + if ((property + "." + key).contains("password")) { + if (password != null && !password.isEmpty()) + conf.setProperty(property + "." + key, password); + } + + if ((property + "." + key).contains("port")) { + if (port != null && !port.isEmpty()) + conf.setProperty(property + "." + key, port); + } + if ((property + "." + key).contains("url")) { + if (url != null && !url.isEmpty()) + conf.setProperty(property + "." + key, url); + } + + } + } else { + if (conf.containsKey(property + "." + "user")) { + if (user != null && !user.isEmpty()) + conf.setProperty(property + "." + "user", user); + } else { + conf.addProperty(property + "." + "user", user); + } + + + if (conf.containsKey(property + "." + "password")) { + if (password != null && !password.isEmpty()) + conf.setProperty(property + "." + "password", password); + } else { + conf.addProperty(property + "." + "password", password); + } + + + if (conf.containsKey(property + "." + "port")) { + if (port != null && !port.isEmpty()) + conf.setProperty(property + "." + "port", port); + } else { + if (port != null && !port.isEmpty()) + conf.addProperty(property + "." + "port", port); + } + + if (conf.containsKey(property + "." + "url")) { + if (url != null && !url.isEmpty()) + conf.setProperty(property + "." + "url", url); + + } else { + + conf.addProperty(property + "." + "url", url); + } + } + + } conf.save(); } catch (Exception e) { - log.info("Caught Exception", e); + log.debug("Caught Exception", e); + log.info("Caught exception", e); + log.info("APPC-MESSAGE:" + e.getMessage()); + + } + finally{ + System.exit(0); } + } } diff --git a/appc-config/appc-encryption-tool/provider/src/test/java/org/onap/appc/encryptiontool/TestEncryptionTool.java b/appc-config/appc-encryption-tool/provider/src/test/java/org/onap/appc/encryptiontool/TestEncryptionTool.java index 5c1d2d17c..4f21ae5c1 100644 --- a/appc-config/appc-encryption-tool/provider/src/test/java/org/onap/appc/encryptiontool/TestEncryptionTool.java +++ b/appc-config/appc-encryption-tool/provider/src/test/java/org/onap/appc/encryptiontool/TestEncryptionTool.java @@ -29,47 +29,76 @@ import java.util.HashMap; import java.util.Map; import org.junit.Test; import org.onap.appc.encryptiontool.wrapper.DbServiceUtil; +import org.onap.appc.encryptiontool.wrapper.EncryptionTool; import org.onap.appc.encryptiontool.wrapper.EncryptionToolDGWrapper; import org.onap.appc.encryptiontool.wrapper.WrapperEncryptionTool; import org.onap.ccsdk.sli.core.sli.SvcLogicContext; public class TestEncryptionTool { - @Test - public void testEncryptionTool() throws Exception{ - String [] input = new String[] {"testVnf_Type","testUser","testPassword11", "testAction1", "8080", "http://localhost:8080/restconf/healthcheck"}; - WrapperEncryptionTool.main(input); + //@Test + public void testEncryptionTool() throws Exception{ + String [] input = new String[] {"testVnf_Type","testUser","testPassword11", "testAction1", "8080", "http://localhost:8080/restconf/healthcheck"}; + WrapperEncryptionTool.main(input); - } -// @Test(expected=Exception.class) - public void testgetPropertyDG() throws Exception{ - EncryptionToolDGWrapper et = new EncryptionToolDGWrapper(); - SvcLogicContext ctx = new SvcLogicContext(); - Map<String, String> inParams = new HashMap<String, String>(); - inParams.put("prefix", "test"); - inParams.put("propertyName", "testVnf_Type.testAction1.url"); - et.getProperty(inParams, ctx); - } - @Test(expected=Exception.class) - public void testgetData() throws Exception - { - DbServiceUtil d = new DbServiceUtil(); - ArrayList argList = null; - String schema ="sdnctl"; - String tableName ="dual"; - String getselectData ="123"; - String getDataClasue="123='123'"; - d.getData(tableName, argList, schema, getselectData, getDataClasue); - } - @Test(expected=Exception.class) - public void testupdateDB() throws Exception - { - DbServiceUtil d = new DbServiceUtil(); - String setCluase = null; - String schema ="sdnctl"; - String tableName ="dual"; - ArrayList inputArgs = null; - String whereClause="123='123'"; - d.updateDB(tableName, inputArgs, schema, whereClause, setCluase); - } + } + @Test(expected=Exception.class) + public void testgetPropertyDG() throws Exception{ + EncryptionToolDGWrapper et = new EncryptionToolDGWrapper(); + SvcLogicContext ctx = new SvcLogicContext(); + Map<String, String> inParams = new HashMap<String, String>(); + inParams.put("prefix", "test"); + inParams.put("propertyName", "testVnf_Type.testAction1.url"); + et.getProperty(inParams, ctx); + } + @Test(expected=Exception.class) + public void testgetData() throws Exception + { + DbServiceUtil d = new DbServiceUtil(); + ArrayList argList = null; + String schema ="sdnctl"; + String tableName ="dual"; + String getselectData ="123"; + String getDataClasue="123='123'"; + d.getData(tableName, argList, schema, getselectData, getDataClasue); + } + @Test(expected=Exception.class) + public void testupdateDB() throws Exception + { + DbServiceUtil d = new DbServiceUtil(); + String setCluase = null; + String schema ="sdnctl"; + String tableName ="dual"; + ArrayList inputArgs = null; + String whereClause="123='123'"; + d.updateDB(tableName, inputArgs, schema, whereClause, setCluase); + } + @Test + public void decrypt() throws Exception{ + EncryptionTool et = EncryptionTool.getInstance(); + System.out.println(et.decrypt("enc:Ai8KLw==").toString()); + } + + + //@Test(expected=Exception.class) + public void testupdateProperties() throws Exception{ + WrapperEncryptionTool et = new WrapperEncryptionTool(); + et.updateProperties("testuser2", "", "abc3", "", "22", "testhost1", "Ansible"); + + } + + //@Test(expected=Exception.class) + public void testgetProperties() throws Exception{ + EncryptionToolDGWrapper et = new EncryptionToolDGWrapper(); + Map<String, String> inParams = new HashMap<String,String>(); + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("vnf-type", "test2"); + ctx.setAttribute("input.action", "Configure"); + ctx.setAttribute("APPC.protocol.PROTOCOL", "Ansible"); + inParams.put("propertyName", "user"); + inParams.put("prefix", "user"); + et.getProperty(inParams, ctx); + + } + } |