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.openecomp.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 propertyName = inParams.get("propertyName");
65 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
66 PropertiesConfiguration conf =
67 new PropertiesConfiguration(Constants.APPC_CONFIG_DIR + "/appc_southbound.properties");
68 conf.setBasePath(null);
69 EncryptionTool et = EncryptionTool.getInstance();
71 ctx.setAttribute(responsePrefix + "propertyName", et.decrypt(conf.getProperty(propertyName).toString()));
72 } catch (Exception e) {
73 ctx.setAttribute(responsePrefix + "status", "failure");
74 ctx.setAttribute(responsePrefix + "error-message", e.getMessage());
75 log.info("Caught exception", e);
76 throw new SvcLogicException(e.getMessage());