Merge "Change the copyright to 2018"
[so.git] / bpmn / MSOCommonBPMN / src / main / java / org / openecomp / mso / client / dmaap / DmaapClient.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.openecomp.mso.client.dmaap;
22
23 import java.io.FileNotFoundException;
24 import java.io.IOException;
25 import java.util.Base64;
26 import java.util.Map;
27 import java.util.Properties;
28
29 import org.openecomp.mso.bpmn.core.PropertyConfiguration;
30 import org.springframework.core.io.ClassPathResource;
31 import org.springframework.core.io.Resource;
32
33 import com.att.eelf.configuration.EELFLogger;
34 import com.att.eelf.configuration.EELFManager;
35
36 public abstract class DmaapClient {
37         
38         protected final EELFLogger auditLogger = EELFManager.getInstance().getAuditLogger();
39         protected final Map<String, String> msoProperties;
40         protected final Properties properties;
41         public DmaapClient(String filepath) throws FileNotFoundException, IOException {
42                 Resource resource = new ClassPathResource(filepath);
43                 DmaapProperties dmaapProperties = DmaapPropertiesLoader.getInstance().getImpl();
44                 if (dmaapProperties == null) {
45                         dmaapProperties = new DefaultDmaapPropertiesImpl();
46                 }
47                 this.msoProperties = dmaapProperties.getProperties();
48                 this.properties = new Properties();
49                 this.properties.load(resource.getInputStream());
50                 this.properties.put("password", this.deobfuscatePassword(this.getPassword()));
51                 this.properties.put("username", this.getUserName());
52                 this.properties.put("topic", this.getTopic());
53         }
54         protected String deobfuscatePassword(String password) {
55                 
56                 try {
57                         return new String(Base64.getDecoder().decode(password.getBytes()));
58                 } catch(IllegalArgumentException iae) {
59                         
60                         return password;
61                 }
62         }
63         
64         
65         public abstract String getUserName();
66         public abstract String getPassword();
67         public abstract String getTopic();
68 }