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;
29 import org.apache.commons.configuration.PropertiesConfiguration;
30 import org.apache.commons.lang.StringUtils;
31 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
32 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
33 import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin;
34 import com.att.eelf.configuration.EELFLogger;
35 import com.att.eelf.configuration.EELFManager;
37 public class EncryptionToolDGWrapper implements SvcLogicJavaPlugin {
39 private static final EELFLogger log = EELFManager.getInstance().getLogger(EncryptionToolDGWrapper.class);
41 public void runEncryption(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
42 String userName = inParams.get("userName");
43 String password = inParams.get("password");
44 String vnfType = inParams.get("vnf_type");
47 if (StringUtils.isBlank(userName) || StringUtils.isBlank(password) || StringUtils.isBlank(vnfType)) {
48 throw new SvcLogicException("username or Password is missing");
51 String[] input = new String[] { vnfType, userName, password };
52 WrapperEncryptionTool.main(input);
54 } catch (Exception e) {
55 throw new SvcLogicException(e.getMessage());
60 public void getProperty(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
61 String responsePrefix = inParams.get("prefix");
62 String vnf_Type = ctx.getAttribute("vnf-type");
63 String action = ctx.getAttribute("input.action");
64 String protocol = ctx.getAttribute("APPC.protocol.PROTOCOL");
66 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
67 PropertiesConfiguration conf = new PropertiesConfiguration(
68 Constants.APPC_CONFIG_DIR + "/appc_southbound.properties");
69 conf.setBasePath(null);
70 EncryptionTool et = EncryptionTool.getInstance();
71 log.info("responsePrefix:"+responsePrefix);
72 log.debug("key:"+vnf_Type+"."+protocol+"."+action);
73 if(StringUtils.isNotBlank(vnf_Type) && StringUtils.isNotBlank(protocol) && StringUtils.isNotBlank(action))
75 String user = (String)conf.getProperty(vnf_Type + "." + protocol + "." + action + "." + "user");
76 String password = (String)conf.getProperty(vnf_Type + "." + protocol + "." + action + "." + "password");
77 String port = (String)conf.getProperty(vnf_Type + "." + protocol + "." + action + "." + "port");
78 String url = (String)conf.getProperty(vnf_Type + "." + protocol + "." + action + "." + "url");
79 if (StringUtils.isBlank(user) || StringUtils.isBlank(password)) {
80 throw new SvcLogicException("Error-while fetching user or password");
82 if ( (user.startsWith("[") && user.endsWith("]")) || (password.startsWith("[") && password.endsWith("]"))|| (port.startsWith("[") && port.endsWith("]"))||(url.startsWith("[") && url.endsWith("]")) )
84 throw new SvcLogicException("Duplicate entries found for key "+vnf_Type + "." + protocol + "." + action +"in properties File");
86 if (StringUtils.isNotBlank(user))
87 ctx.setAttribute(responsePrefix + "user", user);
88 if (StringUtils.isNotBlank(password))
89 ctx.setAttribute(responsePrefix + "password", et.decrypt(password));
90 if (StringUtils.isNotBlank(url))
91 ctx.setAttribute(responsePrefix + "url", url);
92 if (StringUtils.isNotBlank(port))
93 ctx.setAttribute(responsePrefix + "port", port);
94 log.debug(ctx.getAttribute(responsePrefix + "user"));
95 log.debug(ctx.getAttribute(responsePrefix + "password"));
96 log.debug(ctx.getAttribute(responsePrefix + "url"));
97 log.debug(ctx.getAttribute(responsePrefix + "port"));
101 throw new SvcLogicException("Error-as any of properties such as vnf-type,protocol,action are missing in ctx");
103 } catch (Exception e) {
104 ctx.setAttribute(responsePrefix + "status", "failure");
105 ctx.setAttribute(responsePrefix + "error-message", e.getMessage());
106 log.info("Caught exception", e);
107 throw new SvcLogicException(e.getMessage());