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 org.onap.ccsdk.sli.core.sli.SvcLogicResource;
34 import org.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus;
35 import com.att.eelf.configuration.EELFLogger;
36 import com.att.eelf.configuration.EELFManager;
37 import org.onap.ccsdk.sli.adaptors.resource.sql.SqlResource;
39 public class EncryptionToolDGWrapper implements SvcLogicJavaPlugin {
40 private static final EELFLogger log = EELFManager.getInstance().getLogger(EncryptionToolDGWrapper.class);
41 private SvcLogicResource serviceLogic;
42 private static EncryptionToolDGWrapper dgGeneralDBService = null;
44 public static EncryptionToolDGWrapper initialise() {
45 if (dgGeneralDBService == null) {
46 dgGeneralDBService = new EncryptionToolDGWrapper();
48 return dgGeneralDBService;
51 public EncryptionToolDGWrapper() {
52 if (serviceLogic == null) {
53 serviceLogic = new SqlResource();
57 protected EncryptionToolDGWrapper(SqlResource svcLogic) {
58 if (serviceLogic == null) {
59 serviceLogic = svcLogic;
63 public void runEncryption(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
64 String userName = inParams.get("userName");
65 String password = inParams.get("password");
66 String vnfType = inParams.get("vnf_type");
68 if (StringUtils.isBlank(userName) || StringUtils.isBlank(password) || StringUtils.isBlank(vnfType)) {
69 throw new SvcLogicException("username or Password is missing");
71 String[] input = new String[] { vnfType, userName, password };
72 WrapperEncryptionTool.main(input);
73 } catch (Exception e) {
74 throw new SvcLogicException(e.getMessage());
78 public void getProperty(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
79 String fn = "getproperty.deviceauthentication";
80 String responsePrefix = inParams.get("prefix");
81 String vnf_Type = ctx.getAttribute("vnf-type");
82 String action = ctx.getAttribute("input.action");
83 String protocol = ctx.getAttribute("APPC.protocol.PROTOCOL");
88 QueryStatus status = null;
90 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
92 if (serviceLogic != null && ctx != null) {
93 String key = "SELECT USER_NAME ,PASSWORD,PORT_NUMBER,URL FROM DEVICE_AUTHENTICATION WHERE VNF_TYPE = '"
94 + vnf_Type + "' AND PROTOCOL = '" + protocol + "' AND ACTION = '" + action + "'";
95 log.info("Getting authentication details :" + key);
96 status = serviceLogic.query("SQL", false, null, key, null, null, ctx);
97 if (status == QueryStatus.FAILURE) {
98 log.info(fn + ":: Error retrieving credentials");
99 throw new SvcLogicException("Error retrieving credentials");
101 if (status == QueryStatus.NOT_FOUND) {
102 log.info(fn + ":: NOT_FOUND! No data found in device_authentication table for " + vnf_Type + " "
103 + protocol + "" + action + "");
104 throw new SvcLogicException(fn + ":: NOT_FOUND! No data found in device_authentication table for "
105 + vnf_Type + " " + protocol + "" + action + "");
108 user = ctx.getAttribute("USER-NAME");
109 password = ctx.getAttribute("PASSWORD");
110 port = ctx.getAttribute("PORT-NUMBER");
111 url = ctx.getAttribute("URL");
112 log.info("data retrieved " + "user" + user + "pwd" + password + "port" + port + "url" + url);
114 if (StringUtils.isNotBlank(user))
115 ctx.setAttribute(responsePrefix + "user", user);
116 if (StringUtils.isNotBlank(password))
117 ctx.setAttribute(responsePrefix + "password", password);
118 if (StringUtils.isNotBlank(url))
119 ctx.setAttribute(responsePrefix + "url", url);
120 if (StringUtils.isNotBlank(port))
121 ctx.setAttribute(responsePrefix + "port", port);
122 log.debug("user" + ctx.getAttribute(responsePrefix + "user"));
123 log.debug("password" + ctx.getAttribute(responsePrefix + "password"));
124 log.debug("url" + ctx.getAttribute(responsePrefix + "url"));
125 log.debug("port" + ctx.getAttribute(responsePrefix + "port"));
128 } catch (Exception e) {
129 ctx.setAttribute(responsePrefix + "status", "failure");
130 ctx.setAttribute(responsePrefix + "error-message", e.getMessage());
131 log.info("Caught exception", e);
132 throw new SvcLogicException(e.getMessage());