c30f050336e6c0964e91b05336559eb6493b8ba0
[appc.git] / appc-config / appc-encryption-tool / provider / src / main / java / org / openecomp / appc / encryptiontool / wrapper / EncryptionToolDGWrapper.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
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
12  * 
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  * 
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.
20  * 
21  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22  * ============LICENSE_END=========================================================
23  */
24
25 package org.onap.appc.encryptiontool.wrapper;
26
27 import java.util.Map;
28
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;
36
37 public class EncryptionToolDGWrapper implements SvcLogicJavaPlugin {
38
39     private static final EELFLogger log = EELFManager.getInstance().getLogger(EncryptionToolDGWrapper.class);
40
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");
45
46         try {
47             if (StringUtils.isBlank(userName) || StringUtils.isBlank(password) || StringUtils.isBlank(vnfType)) {
48                 throw new SvcLogicException("username or Password is missing");
49             }
50
51             String[] input = new String[] {vnfType, userName, password};
52             WrapperEncryptionTool.main(input);
53
54         } catch (Exception e) {
55             throw new SvcLogicException(e.getMessage());
56         }
57
58     }
59
60     public void getProperty(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
61         String responsePrefix = inParams.get("prefix");
62         String propertyName = inParams.get("propertyName");
63
64         try {
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();
70
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());
77         }
78     }
79 }