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.onap.appc.encryptiontool.wrapper;
27 import java.util.Iterator;
28 import org.apache.commons.configuration.PropertiesConfiguration;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
31 import org.apache.commons.lang.StringUtils;
33 public class WrapperEncryptionTool {
35 private static final Logger log = LoggerFactory.getLogger(WrapperEncryptionTool.class);
37 public static void main(String[] args) {
38 String vnf_type = args[0];
39 String protocol = args[1];
40 String user = args[2];
41 String password = args[3];
42 String action = args[4];
43 String port = args[5];
46 if (StringUtils.isNotBlank(user)) {
47 log.info("ERROR-USER can not be null");
50 if (StringUtils.isNotBlank(password)) {
51 log.info("ERROR-PASSWORD can not be null");
54 if (StringUtils.isNotBlank(protocol) || StringUtils.isNotBlank(vnf_type) || StringUtils.isNotBlank(action)) {
55 log.info("ERROR-PROTOCOL ,Action and VNF-TYPE both can not be null");
59 EncryptionTool et = EncryptionTool.getInstance();
60 String enPass = et.encrypt(password);
62 if ((protocol != null && !protocol.isEmpty())) {
63 updateProperties(user, vnf_type, enPass, action, port, url, protocol);
69 public static void updateProperties(String user, String vnf_type, String password, String action, String port,
70 String url, String protocol) {
72 log.info("Received Inputs protocol:%s User:%s vnfType:%s action:%surl:%s port:%s ", protocol, user,
73 vnf_type, action, url, port);
74 String property = protocol;
75 if (!StringUtils.isNotBlank(vnf_type)) {
77 if (!StringUtils.isNotBlank(protocol)) {
78 if (!StringUtils.isNotBlank(action)) {
80 property = vnf_type + "." + protocol + "." + action;
90 if (!StringUtils.isNotBlank(protocol)) {
96 PropertiesConfiguration conf = new PropertiesConfiguration(
97 System.getenv("APPC_CONFIG_DIR")+"/appc_southbound.properties");
99 if (conf.subset(property) != null) {
101 Iterator<String> it = conf.subset(property).getKeys();
103 while (it.hasNext()) {
104 String key = it.next();
105 log.info("key---value pairs");
106 log.info(property + "." + key + "------" + conf.getProperty(property + "." + key));
107 if ((property + "." + key).contains("user")) {
108 if (user != null && !user.isEmpty())
109 conf.setProperty(property + "." + key, user);
112 if ((property + "." + key).contains("password")) {
113 if (password != null && !password.isEmpty())
114 conf.setProperty(property + "." + key, password);
117 if ((property + "." + key).contains("port")) {
118 if (port != null && !port.isEmpty())
119 conf.setProperty(property + "." + key, port);
121 if ((property + "." + key).contains("url")) {
122 if (url != null && !url.isEmpty())
123 conf.setProperty(property + "." + key, url);
128 if (conf.containsKey(property + "." + "user")) {
129 if (user != null && !user.isEmpty())
130 conf.setProperty(property + "." + "user", user);
132 conf.addProperty(property + "." + "user", user);
136 if (conf.containsKey(property + "." + "password")) {
137 if (password != null && !password.isEmpty())
138 conf.setProperty(property + "." + "password", password);
140 conf.addProperty(property + "." + "password", password);
144 if (conf.containsKey(property + "." + "port")) {
145 if (port != null && !port.isEmpty())
146 conf.setProperty(property + "." + "port", port);
148 if (port != null && !port.isEmpty())
149 conf.addProperty(property + "." + "port", port);
152 if (conf.containsKey(property + "." + "url")) {
153 if (url != null && !url.isEmpty())
154 conf.setProperty(property + "." + "url", url);
158 conf.addProperty(property + "." + "url", url);
165 } catch (Exception e) {
166 log.debug("Caught Exception", e);
167 log.info("Caught exception", e);
168 log.info("APPC-MESSAGE:" + e.getMessage());