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 * =============================================================================
11 * Licensed under the Apache License, Version 2.0 (the "License");
12 * you may not use this file except in compliance with the License.
13 * You may obtain a copy of the License at
15 * http://www.apache.org/licenses/LICENSE-2.0
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
23 * ============LICENSE_END=========================================================
26 package org.onap.appc.encryptiontool.wrapper;
28 import java.util.ArrayList;
29 import javax.sql.rowset.CachedRowSet;
30 import org.apache.commons.lang.StringUtils;
31 import org.onap.ccsdk.sli.core.dblib.DBResourceManager;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
35 public class WrapperEncryptionTool {
37 private static final Logger log = LoggerFactory.getLogger(WrapperEncryptionTool.class);
38 private static final String USER_PARAM = "user";
39 private static final String PASS_PARAM = "password";
40 private static final String URL_PARAM = "url";
41 private static final String PORT_PARAM = "port";
43 private WrapperEncryptionTool() {
46 public static void main(String[] args) {
47 String vnfType = args[0];
48 String protocol = args[1];
49 String user = args[2];
50 String password = args[3];
51 String action = args[4];
52 String port = args[5];
54 log.info("vnfType = " + vnfType + " protocol = " + protocol + " " + USER_PARAM + "=" + user + " " + PASS_PARAM
55 + "=" + password + " action=" + action + " " + PORT_PARAM + "=" + port + " " + URL_PARAM + "=" + url);
57 if (StringUtils.isBlank(user)) {
58 log.info("ERROR-USER can not be null");
61 if (StringUtils.isBlank(password)) {
62 log.info("ERROR-PASSWORD can not be null");
65 if (StringUtils.isBlank(protocol) || StringUtils.isBlank(vnfType) || StringUtils.isBlank(action)) {
66 log.info("ERROR-PROTOCOL ,Action and VNF-TYPE both can not be null");
69 if (protocol.equalsIgnoreCase("ansible") && (StringUtils.isBlank(url))) {
70 log.info("URL cannot be null for Ansible");
73 EncryptionTool et = EncryptionTool.getInstance();
74 String enPass = et.encrypt(password);
75 log.info("enPass =" + enPass);
76 if (protocol.equalsIgnoreCase("ansible"))
77 updatePropertiesAnsible(user, vnfType, enPass, action, port, url, protocol);
79 updateProperties(user, vnfType, enPass, action, port, url, protocol);
82 public static void updatePropertiesAnsible(String user, String vnfType, String enPass, String action, String port,
83 String url, String protocol) {
84 DBResourceManager dbResourceManager = null;
85 ArrayList<String> getList = new ArrayList<>();
87 getList.add(protocol);
90 String whereClause = " VNF_TYPE = ? AND PROTOCOL = ? AND ACTION = ? AND URL = ? ";
91 String setClause = " USER_NAME = ?, PASSWORD = ?, PORT_NUMBER = ? ";
92 String insertClause = " USER_NAME,PASSWORD,PORT_NUMBER,URL,VNF_TYPE,PROTOCOL,ACTION";
93 String insertsetClause = " ?,?,?,?,?,?,?";
95 dbResourceManager = DbServiceUtil.initDbLibService();
96 CachedRowSet data = DbServiceUtil.getData(Constants.DEVICE_AUTHENTICATION, getList, Constants.SCHEMA_SDNCTL,
101 log.info(rowCount + "rowcount");
108 getList.add(vnfType);
109 getList.add(protocol);
112 DbServiceUtil.updateDB(Constants.DEVICE_AUTHENTICATION, getList, whereClause, setClause);
113 log.info("APPC-MESSAGE: Password Updated Successfully");
115 DbServiceUtil.insertDB(Constants.DEVICE_AUTHENTICATION, getList, insertClause, insertsetClause);
116 log.info("APPC-MESSAGE: password Inserted Successfully");
118 } catch (Exception e) {
119 log.debug("Caught Exception", e);
120 log.info("Caught exception", e);
121 log.info("APPC-MESSAGE:" + e.getMessage());
124 dbResourceManager.cleanUp();
128 public static void updateProperties(String user, String vnfType, String enPass, String action, String port,
129 String url, String protocol) {
130 DBResourceManager dbResourceManager = null;
131 ArrayList<String> getList = new ArrayList<>();
132 getList.add(vnfType);
133 getList.add(protocol);
135 String whereClause = " VNF_TYPE = ? AND PROTOCOL = ? AND ACTION = ? ";
136 String setClause = " USER_NAME = ?, PASSWORD = ?, PORT_NUMBER = ?,URL = ? ";
137 String insertClause = " USER_NAME,PASSWORD,PORT_NUMBER,URL,VNF_TYPE,PROTOCOL,ACTION";
138 String insertsetClause = " ?,?,?,?,?,?,?";
140 dbResourceManager = DbServiceUtil.initDbLibService();
141 CachedRowSet data = DbServiceUtil.getData(Constants.DEVICE_AUTHENTICATION, getList, Constants.SCHEMA_SDNCTL,
146 log.info(rowCount + "rowcount");
153 getList.add(vnfType);
154 getList.add(protocol);
157 DbServiceUtil.updateDB(Constants.DEVICE_AUTHENTICATION, getList, whereClause, setClause);
158 log.info("APPC-MESSAGE: Password Updated Successfully");
160 DbServiceUtil.insertDB(Constants.DEVICE_AUTHENTICATION, getList, insertClause, insertsetClause);
161 log.info("APPC-MESSAGE: password Inserted Successfully");
163 } catch (Exception e) {
164 log.debug("Caught Exception", e);
165 log.info("Caught exception", e);
166 log.info("APPC-MESSAGE:" + e.getMessage());
169 dbResourceManager.cleanUp();