2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * =============================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * ============LICENSE_END=========================================================
24 package org.onap.appc.encryptiontool.wrapper;
26 import java.util.ArrayList;
27 import javax.sql.rowset.CachedRowSet;
28 import org.apache.commons.lang.StringUtils;
29 import org.onap.ccsdk.sli.core.dblib.DBResourceManager;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
33 public class WrapperEncryptionTool {
35 private static final Logger log = LoggerFactory.getLogger(WrapperEncryptionTool.class);
36 private static final String USER_PARAM = "user";
37 private static final String PASS_PARAM = "password";
38 private static final String URL_PARAM = "url";
39 private static final String PORT_PARAM = "port";
41 private WrapperEncryptionTool() {
44 public static void main(String[] args) {
45 String vnfType = args[0];
46 String protocol = args[1];
47 String user = args[2];
48 String password = args[3];
49 String action = args[4];
50 String port = args[5];
52 log.info("vnfType = " + vnfType + " protocol = " + protocol + " user=" + user + " password=" + password
53 + " action=" + action + " port=" + port + " url=" + url);
55 if (StringUtils.isBlank(user)) {
56 log.info("ERROR-USER can not be null");
59 if (StringUtils.isBlank(password)) {
60 log.info("ERROR-PASSWORD can not be null");
63 if (StringUtils.isBlank(protocol) || StringUtils.isBlank(vnfType) || StringUtils.isBlank(action)) {
64 log.info("ERROR-PROTOCOL ,Action and VNF-TYPE both can not be null");
67 if (protocol.equalsIgnoreCase("ansible") && (StringUtils.isBlank(url))) {
68 log.info("URL cannot be null for Ansible");
71 EncryptionTool et = EncryptionTool.getInstance();
72 String enPass = et.encrypt(password);
73 log.info("enPass =" + enPass);
74 if (protocol.equalsIgnoreCase("ansible"))
75 updatePropertiesAnsible(user, vnfType, enPass, action, port, url, protocol);
77 updateProperties(user, vnfType, enPass, action, port, url, protocol);
80 public static void updatePropertiesAnsible(String user, String vnfType, String enPass, String action, String port,
81 String url, String protocol) {
82 DBResourceManager dbResourceManager = null;
83 ArrayList<String> getList = new ArrayList<>();
85 getList.add(protocol);
88 String whereClause = " VNF_TYPE = ? AND PROTOCOL = ? AND ACTION = ? AND URL = ? ";
89 String setClause = " USER_NAME = ?, PASSWORD = ?, PORT_NUMBER = ? ";
90 String insertClause = " USER_NAME,PASSWORD,PORT_NUMBER,URL,VNF_TYPE,PROTOCOL,ACTION";
91 String insertsetClause = " ?,?,?,?,?,?,?";
93 dbResourceManager = DbServiceUtil.initDbLibService();
94 CachedRowSet data = DbServiceUtil.getData(Constants.DEVICE_AUTHENTICATION, getList, Constants.SCHEMA_SDNCTL,
99 log.info(rowCount + "rowcount");
106 getList.add(vnfType);
107 getList.add(protocol);
110 DbServiceUtil.updateDB(Constants.DEVICE_AUTHENTICATION, getList, whereClause, setClause);
111 log.info("APPC-MESSAGE: Password Updated Successfully");
113 DbServiceUtil.insertDB(Constants.DEVICE_AUTHENTICATION, getList, insertClause, insertsetClause);
114 log.info("APPC-MESSAGE: password Inserted Successfully");
116 } catch (Exception e) {
117 log.debug("Caught Exception", e);
118 log.info("Caught exception", e);
119 log.info("APPC-MESSAGE:" + e.getMessage());
122 dbResourceManager.cleanUp();
126 public static void updateProperties(String user, String vnfType, String enPass, String action, String port,
127 String url, String protocol) {
128 DBResourceManager dbResourceManager = null;
129 ArrayList<String> getList = new ArrayList<>();
130 getList.add(vnfType);
131 getList.add(protocol);
133 String whereClause = " VNF_TYPE = ? AND PROTOCOL = ? AND ACTION = ? ";
134 String setClause = " USER_NAME = ?, PASSWORD = ?, PORT_NUMBER = ?,URL = ? ";
135 String insertClause = " USER_NAME,PASSWORD,PORT_NUMBER,URL,VNF_TYPE,PROTOCOL,ACTION";
136 String insertsetClause = " ?,?,?,?,?,?,?";
138 dbResourceManager = DbServiceUtil.initDbLibService();
139 CachedRowSet data = DbServiceUtil.getData(Constants.DEVICE_AUTHENTICATION, getList, Constants.SCHEMA_SDNCTL,
144 log.info(rowCount + "rowcount");
151 getList.add(vnfType);
152 getList.add(protocol);
155 DbServiceUtil.updateDB(Constants.DEVICE_AUTHENTICATION, getList, whereClause, setClause);
156 log.info("APPC-MESSAGE: Password Updated Successfully");
158 DbServiceUtil.insertDB(Constants.DEVICE_AUTHENTICATION, getList, insertClause, insertsetClause);
159 log.info("APPC-MESSAGE: password Inserted Successfully");
161 } catch (Exception e) {
162 log.debug("Caught Exception", e);
163 log.info("Caught exception", e);
164 log.info("APPC-MESSAGE:" + e.getMessage());
167 dbResourceManager.cleanUp();