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.dmaap.dbcapi.util;
23 import com.att.eelf.configuration.EELFLogger;
24 import com.att.eelf.configuration.EELFManager;
26 import java.security.KeyStore;
28 import javax.net.ssl.SSLContext;
29 import javax.net.ssl.SSLSocketFactory;
30 import javax.net.ssl.TrustManager;
31 import javax.net.ssl.TrustManagerFactory;
32 import org.onap.dmaap.dbcapi.server.CertificateManager;
33 import org.onap.dmaap.dbcapi.server.JettyServer;
35 public class DmaapConfig extends Properties {
37 private static final EELFLogger logger = EELFManager.getInstance().getLogger(DmaapConfig.class);
38 private static final long serialVersionUID = 1L;
39 private static final String CONFIG_FILE_NAME = System.getProperty("ConfigFile", "/opt/app/config/conf/dmaapbc.properties");
40 private static final Properties config = new DmaapConfig();
42 public static Properties getConfig() {
45 public static String getConfigFileName() {
46 return(CONFIG_FILE_NAME);
48 private DmaapConfig() {
49 try (InputStream is = new FileInputStream(CONFIG_FILE_NAME)){
51 } catch (Exception e) {
52 logger.error("Unable to load configuration file " + CONFIG_FILE_NAME);
57 public static SSLSocketFactory getSSLSocketFactory() {
58 SSLSocketFactory factory = null;
60 CertificateManager cm = JettyServer.getCertificateManager();
61 String truststore = cm.getTrustStoreFile();
62 KeyStore ts = KeyStore.getInstance(cm.getTrustStoreType());
63 try (InputStream in = new FileInputStream(truststore)) {
64 ts.load(in, cm.getTrustStorePassword().toCharArray());
66 TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
68 TrustManager[] tm = tmf.getTrustManagers();
69 SSLContext sslContext = SSLContext.getInstance("TLS");
70 sslContext.init(null, tm, null);
71 factory = sslContext.getSocketFactory();
72 } catch (Exception e) {
73 logger.error("Exception thrown trying to get SSLSocketFactory: ", e);