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 if (StringUtils.isBlank(user)) {
53 log.info("ERROR-USER can not be null");
56 if (StringUtils.isBlank(password)) {
57 log.info("ERROR-PASSWORD can not be null");
60 if (StringUtils.isBlank(protocol) || StringUtils.isBlank(vnfType) || StringUtils.isBlank(action)) {
61 log.info("ERROR-PROTOCOL ,Action and VNF-TYPE both can not be null");
64 EncryptionTool et = EncryptionTool.getInstance();
65 String enPass = et.encrypt(password);
66 updateProperties(user, vnfType, enPass, action, port, url, protocol);
69 public static void updateProperties(String user, String vnfType, String enPass, String action, String port,
70 String url, String protocol) {
71 DBResourceManager dbResourceManager = null;
72 ArrayList<String> getList = new ArrayList<>();
74 getList.add(protocol);
76 String whereClause = " VNF_TYPE = ? AND PROTOCOL = ? AND ACTION = ? ";
77 String setClause = " USER_NAME = ?, PASSWORD = ?, PORT_NUMBER = ?,URL = ? ";
78 String insertClause = " USER_NAME,PASSWORD,PORT_NUMBER,URL,VNF_TYPE,PROTOCOL,ACTION";
79 String insertsetClause = " ?,?,?,?,?,?,?";
81 dbResourceManager = DbServiceUtil.initDbLibService();
82 CachedRowSet data = DbServiceUtil.getData(Constants.DEVICE_AUTHENTICATION, getList, Constants.SCHEMA_SDNCTL,
87 log.info(rowCount + "rowcount");
95 getList.add(protocol);
98 DbServiceUtil.updateDB(Constants.DEVICE_AUTHENTICATION, getList, whereClause, setClause);
99 log.info("APPC-MESSAGE: Password Updated Successfully");
101 DbServiceUtil.insertDB(Constants.DEVICE_AUTHENTICATION, getList, insertClause, insertsetClause);
102 log.info("APPC-MESSAGE: password Inserted Successfully");
104 } catch (Exception e) {
105 log.debug("Caught Exception", e);
106 log.info("Caught exception", e);
107 log.info("APPC-MESSAGE:" + e.getMessage());
108 dbResourceManager.cleanUp();
111 dbResourceManager.cleanUp();