2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 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 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 * ============LICENSE_END=========================================================
25 package org.openecomp.appc.encryptiontool.wrapper;
27 import java.util.ArrayList;
29 import javax.sql.rowset.CachedRowSet;
31 import org.apache.commons.configuration.PropertiesConfiguration;
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);
40 public static void main(String[] args) {
42 String vnfType = args[0];
43 String user = args[1];
44 String password = args[2];
45 String action = args[3];
46 String port = args[4];
49 if ("".equals(vnfType)) {
50 log.info("ERROR-VNF_TYPE can not be null");
53 if ("".equals(user)) {
54 log.info("ERROR-USER can not be null");
57 if ("".equals(password)) {
58 log.info("ERROR-PASSWORD can not be null");
62 EncryptionTool et = EncryptionTool.getInstance();
63 String enPass = et.encrypt(password);
65 if (action != null && !action.isEmpty()) {
66 updateProperties(user, vnfType, enPass, action, port, url);
70 ArrayList<String> argList = new ArrayList<>();
73 String clause = " vnfType = ? and user_name = ? ";
74 String setClause = " password = ? ";
75 String getselectData = " * ";
76 DBResourceManager dbResourceManager = null;
77 try (CachedRowSet data = DbServiceUtil.getData(Constants.DEVICE_AUTHENTICATION, argList,
78 Constants.SCHEMA_SDNCTL, getselectData, clause);) {
79 dbResourceManager = DbServiceUtil.initDbLibService();
85 log.info("APPC-MESSAGE: ERROR - No record Found for VNF_TYPE: %, User % ", vnfType, user);
91 DbServiceUtil.updateDB(Constants.DEVICE_AUTHENTICATION, argList, Constants.SCHEMA_SDNCTL, clause,
93 log.info("APPC-MESSAGE: Password Updated Successfully");
95 } catch (Exception e) {
96 log.info("Caught exception", e);
97 log.info("APPC-MESSAGE:" + e.getMessage());
99 if (dbResourceManager != null) {
100 dbResourceManager.cleanUp();
105 private static void updateProperties(String user, String vnfType, String password, String action, String port,
108 log.info("Received Inputs User:%s vnfType:%s action:%s", user, vnfType, action);
109 String property = vnfType + "." + action + ".";
113 PropertiesConfiguration conf =
114 new PropertiesConfiguration(Constants.APPC_CONFIG_DIR + "/appc_southbound.properties");
115 conf.setProperty(property + "user", user);
116 if (port != null && !port.isEmpty())
117 conf.setProperty(property + "port", port);
118 if (password != null && !password.isEmpty())
119 conf.setProperty(property + "password", password);
120 if (url != null && !url.isEmpty())
121 conf.setProperty(property + "url", url);
125 } catch (Exception e) {
126 log.info("Caught Exception", e);