2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.so.client.dmaap;
23 import java.io.IOException;
24 import java.security.GeneralSecurityException;
25 import java.util.Base64;
27 import java.util.Optional;
28 import java.util.Properties;
30 import org.onap.so.client.defaultproperties.DefaultDmaapPropertiesImpl;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
33 import org.springframework.core.io.ClassPathResource;
34 import org.springframework.core.io.Resource;
35 import org.onap.so.utils.CryptoUtils;
37 public abstract class DmaapClient {
39 protected static Logger logger = LoggerFactory.getLogger(DmaapClient.class);
40 protected final Map<String, String> msoProperties;
41 protected final Properties properties;
43 public DmaapClient(String filepath) throws IOException {
44 Resource resource = new ClassPathResource(filepath);
45 DmaapProperties dmaapProperties = DmaapPropertiesLoader.getInstance().getNewImpl();
46 if (dmaapProperties == null) {
47 logger.error("No RestProperty implementation found on classpath, loading default");
48 dmaapProperties = new DefaultDmaapPropertiesImpl();
50 this.msoProperties = dmaapProperties.getProperties();
51 this.properties = new Properties();
52 this.properties.load(resource.getInputStream());
54 this.properties.put("auth", CryptoUtils.decrypt(this.getAuth(), this.getKey()).getBytes());
55 } catch (GeneralSecurityException e) {
56 logger.error(e.getMessage(), e);
58 this.properties.put("key", this.getKey());
59 this.properties.put("topic", this.getTopic());
60 Optional<String> host = this.getHost();
61 if (host.isPresent()) {
62 this.properties.put("host", host.get());
66 protected String deobfuscatePassword(String decrypted_key) {
69 return new String(Base64.getDecoder().decode(decrypted_key.getBytes()));
70 } catch (IllegalArgumentException iae) {
71 logger.error("llegal Arguments", iae);
76 public abstract String getKey();
78 public abstract String getAuth();
80 public abstract String getTopic();
82 public abstract Optional<String> getHost();