2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.appc.encryptiontool.wrapper;
24 import java.io.FileOutputStream;
25 import java.io.OutputStream;
26 import java.util.ArrayList;
27 import java.util.Properties;
29 import javax.sql.rowset.CachedRowSet;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
33 import org.apache.commons.configuration.PropertiesConfiguration;
34 import org.onap.ccsdk.sli.core.dblib.DBResourceManager;
36 public class WrapperEncryptionTool {
38 private static final Logger log = LoggerFactory
39 .getLogger(WrapperEncryptionTool.class);
41 public static void main(String[] args)
44 String vnf_type=args[0];
45 String user = args[1];
46 String password = args[2];
47 String action = args[3];
48 String port = args[4];
51 if("".equals(vnf_type))
53 System.out.println("ERROR-VNF_TYPE can not be null");
58 System.out.println("ERROR-USER can not be null");
61 if("".equals(password))
63 System.out.println("ERROR-PASSWORD can not be null");
67 EncryptionTool encryptionTool = EncryptionTool.getInstance();
68 String enPass = encryptionTool.encrypt(password);
70 if(action != null && !action.isEmpty()){
71 updateProperties(user,vnf_type , enPass, action, port, url);
75 ArrayList<String> argList = new ArrayList<>();
76 argList.add(vnf_type);
78 String clause = " vnf_type = ? and user_name = ? ";
79 String setClause = " password = ? ";
80 String getselectData = " * ";
81 DBResourceManager dbResourceManager = null;
84 dbResourceManager = DbServiceUtil.initDbLibService();
85 CachedRowSet data = DbServiceUtil.getData(Constants.DEVICE_AUTHENTICATION,
86 argList, Constants.SCHEMA_SDNCTL, getselectData,clause );
92 log.info("APPC-MESSAGE: ERROR - No record Found for VNF_TYPE: " + vnf_type + ", User " + user );
97 argList.add(vnf_type);
99 DbServiceUtil.updateDB(Constants.DEVICE_AUTHENTICATION, argList,
100 Constants.SCHEMA_SDNCTL, clause, setClause);
101 log.info("APPC-MESSAGE: Password Updated Successfully");
107 log.info("APPC-MESSAGE:" + e.getMessage());
111 dbResourceManager.cleanUp();
116 private static void updateProperties(String user, String vnf_type, String password,
117 String action, String port, String url) {
119 log.info("Received Inputs User:" + user + " vnf_type:" + vnf_type + " action:" + action );
121 String property = vnf_type + "." + action + ".";
124 PropertiesConfiguration conf = new PropertiesConfiguration(Constants.APPC_CONFIG_DIR + "/appc_southbound.properties");
125 conf.setProperty(property + "user", user);
126 if(port != null && !port.isEmpty() )
127 conf.setProperty(property + "port", port);
128 if(password != null && !password.isEmpty() )
129 conf.setProperty(property + "password", password);
130 if(url != null && !url.isEmpty() )
131 conf.setProperty(property + "url", url);
136 catch (Exception e ) {
138 log.info("APPC-MESSAGE:" + e.getMessage());