2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * ================================================================================
9 * Modifications Copyright (C) 2019 Ericsson
10 * Modifications Copyright (C) 2019 IBM
11 * =============================================================================
12 * Licensed under the Apache License, Version 2.0 (the "License");
13 * you may not use this file except in compliance with the License.
14 * You may obtain a copy of the License at
16 * http://www.apache.org/licenses/LICENSE-2.0
18 * Unless required by applicable law or agreed to in writing, software
19 * distributed under the License is distributed on an "AS IS" BASIS,
20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 * See the License for the specific language governing permissions and
22 * limitations under the License.
24 * ============LICENSE_END=========================================================
27 package org.onap.appc.encryptiontool.wrapper;
29 import java.util.ArrayList;
30 import javax.sql.rowset.CachedRowSet;
31 import org.apache.commons.lang.StringUtils;
32 import org.onap.ccsdk.sli.core.dblib.DBResourceManager;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
36 public class WrapperEncryptionTool {
38 private static final Logger log = LoggerFactory.getLogger(WrapperEncryptionTool.class);
39 private static final String USER_PARAM = "user";
40 private static final String PASS_PARAM = "password";
41 private static final String URL_PARAM = "url";
42 private static final String PORT_PARAM = "port";
44 private WrapperEncryptionTool() {
47 public static void main(String[] args) {
48 String vnfType = args[0];
49 String protocol = args[1];
50 String user = args[2];
51 String password = args[3];
52 String action = args[4];
53 String port = args[5];
55 log.info("vnfType = " + vnfType + " protocol = " + protocol + " " + USER_PARAM + "=" + user + " " + PASS_PARAM
56 + "=" + password + " action=" + action + " " + PORT_PARAM + "=" + port + " " + URL_PARAM + "=" + url);
58 if (StringUtils.isBlank(user)) {
59 log.info("ERROR-USER can not be null");
62 if (StringUtils.isBlank(password)) {
63 log.info("ERROR-PASSWORD can not be null");
66 if (StringUtils.isBlank(protocol) || StringUtils.isBlank(vnfType) || StringUtils.isBlank(action)) {
67 log.info("ERROR-PROTOCOL ,Action and VNF-TYPE both can not be null");
70 if (protocol.equalsIgnoreCase("ansible") && (StringUtils.isBlank(url))) {
71 log.info("URL cannot be null for Ansible");
74 EncryptionTool et = EncryptionTool.getInstance();
75 String enPass = et.encrypt(password);
76 log.info("enPass =" + enPass);
77 if (protocol.equalsIgnoreCase("ansible"))
78 updatePropertiesAnsible(user, vnfType, enPass, action, port, url, protocol);
80 updateProperties(user, vnfType, enPass, action, port, url, protocol);
83 public static void updatePropertiesAnsible(String user, String vnfType, String enPass, String action, String port,
84 String url, String protocol) {
85 DBResourceManager dbResourceManager = null;
86 ArrayList<String> getList = new ArrayList<>();
88 getList.add(protocol);
91 String whereClause = " VNF_TYPE = ? AND PROTOCOL = ? AND ACTION = ? AND URL = ? ";
92 String setClause = " USER_NAME = ?, PASSWORD = ?, PORT_NUMBER = ? ";
93 String insertClause = " USER_NAME,PASSWORD,PORT_NUMBER,URL,VNF_TYPE,PROTOCOL,ACTION";
94 String insertsetClause = " ?,?,?,?,?,?,?";
96 dbResourceManager = DbServiceUtil.initDbLibService();
97 CachedRowSet data = DbServiceUtil.getData(Constants.DEVICE_AUTHENTICATION, getList, Constants.SCHEMA_SDNCTL,
102 log.info(rowCount + "rowcount");
109 getList.add(vnfType);
110 getList.add(protocol);
113 DbServiceUtil.updateDB(Constants.DEVICE_AUTHENTICATION, getList, whereClause, setClause);
114 log.info("APPC-MESSAGE: Password Updated Successfully");
116 DbServiceUtil.insertDB(Constants.DEVICE_AUTHENTICATION, getList, insertClause, insertsetClause);
117 log.info("APPC-MESSAGE: password Inserted Successfully");
119 } catch (Exception e) {
120 log.debug("Caught Exception", e);
121 log.info("Caught exception", e);
122 log.info("APPC-MESSAGE:" + e.getMessage());
125 if(dbResourceManager!=null)
126 dbResourceManager.cleanUp();
130 public static void updateProperties(String user, String vnfType, String enPass, String action, String port,
131 String url, String protocol) {
132 DBResourceManager dbResourceManager = null;
133 ArrayList<String> getList = new ArrayList<>();
134 getList.add(vnfType);
135 getList.add(protocol);
137 String whereClause = " VNF_TYPE = ? AND PROTOCOL = ? AND ACTION = ? ";
138 String setClause = " USER_NAME = ?, PASSWORD = ?, PORT_NUMBER = ?,URL = ? ";
139 String insertClause = " USER_NAME,PASSWORD,PORT_NUMBER,URL,VNF_TYPE,PROTOCOL,ACTION";
140 String insertsetClause = " ?,?,?,?,?,?,?";
142 dbResourceManager = DbServiceUtil.initDbLibService();
143 CachedRowSet data = DbServiceUtil.getData(Constants.DEVICE_AUTHENTICATION, getList, Constants.SCHEMA_SDNCTL,
148 log.info(rowCount + "rowcount");
155 getList.add(vnfType);
156 getList.add(protocol);
159 DbServiceUtil.updateDB(Constants.DEVICE_AUTHENTICATION, getList, whereClause, setClause);
160 log.info("APPC-MESSAGE: Password Updated Successfully");
162 DbServiceUtil.insertDB(Constants.DEVICE_AUTHENTICATION, getList, insertClause, insertsetClause);
163 log.info("APPC-MESSAGE: password Inserted Successfully");
165 } catch (Exception e) {
166 log.debug("Caught Exception", e);
167 log.info("Caught exception", e);
168 log.info("APPC-MESSAGE:" + e.getMessage());
171 if(dbResourceManager!=null)
172 dbResourceManager.cleanUp();