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.openecomp.aai.util;
23 import java.io.FileInputStream;
24 import java.security.KeyManagementException;
25 import java.security.KeyStore;
27 import javax.net.ssl.HostnameVerifier;
28 import javax.net.ssl.HttpsURLConnection;
29 import javax.net.ssl.KeyManagerFactory;
30 import javax.net.ssl.SSLContext;
31 import javax.net.ssl.SSLSession;
32 import javax.ws.rs.client.Client;
33 import javax.ws.rs.client.ClientBuilder;
35 import org.openecomp.vid.encryption.EncryptedPropValue;
37 import org.openecomp.portalsdk.core.util.SystemProperties;
40 * The Class HttpsAuthClient.
42 public class HttpsAuthClient{
47 * @param certFilePath the cert file path
49 * @throws KeyManagementException the key management exception
51 public static Client getClient(String certFilePath) throws KeyManagementException {
53 //config.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE);
54 //config.getClasses().add(org.openecomp.aai.util.CustomJacksonJaxBJsonProvider.class);
57 String truststore_path = certFilePath + AAIProperties.FILESEPARTOR + SystemProperties.getProperty(AAIProperties.AAI_TRUSTSTORE_FILENAME);
58 String truststore_password = SystemProperties.getProperty(AAIProperties.AAI_TRUSTSTORE_PASSWD_X);
59 String decrypted_truststore_password = EncryptedPropValue.decryptTriple(truststore_password);
60 // String keystore_path = certFilePath + AAIProperties.FILESEPARTOR + SystemProperties.getProperty(AAIProperties.AAI_KEYSTORE_FILENAME);
61 // String keystore_password = SystemProperties.getProperty(AAIProperties.AAI_KEYSTORE_PASSWD_X);
62 // String decrypted_keystore_password = EncryptedPropValue.decryptTriple(keystore_password);
67 System.setProperty("javax.net.ssl.trustStore", truststore_path);
68 System.setProperty("javax.net.ssl.trustStorePassword", decrypted_truststore_password);
69 HttpsURLConnection.setDefaultHostnameVerifier( new HostnameVerifier(){
70 public boolean verify(String string,SSLSession ssls) {
75 // final SSLContext ctx = SSLContext.getInstance("TLS");
76 // KeyManagerFactory kmf = null;
78 // kmf = KeyManagerFactory.getInstance("SunX509");
79 // FileInputStream fin = new FileInputStream(keystore_path);
80 // KeyStore ks = KeyStore.getInstance("PKCS12");
81 // char[] pwd = decrypted_keystore_password.toCharArray();
84 // } catch (Exception e) {
85 // System.out.println("Error setting up kmf: exiting");
86 // e.printStackTrace();
90 // ctx.init(kmf.getKeyManagers(), null, null);
92 return ClientBuilder.newBuilder()
93 .hostnameVerifier(new HostnameVerifier() {
95 public boolean verify( String s, SSLSession sslSession ) {
99 .register(org.openecomp.aai.util.CustomJacksonJaxBJsonProvider.class);
101 } catch (Exception e) {
102 System.out.println("Error setting up config: exiting");