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