[VID-3] Setting docker image tag
[vid.git] / vid / src / main / java / org / openecomp / aai / util / HttpsAuthClient.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * VID
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.aai.util;
22
23 import java.io.FileInputStream;
24 import java.security.KeyManagementException;
25 import java.security.KeyStore;
26
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;
34
35 import org.openecomp.vid.encryption.EncryptedPropValue;
36
37 import org.openecomp.portalsdk.core.util.SystemProperties;
38
39 /**
40  * The Class HttpsAuthClient.
41  */
42 public class HttpsAuthClient{
43         
44         /**
45          * Gets the client.
46          *
47          * @param certFilePath the cert file path
48          * @return the client
49          * @throws KeyManagementException the key management exception
50          */
51         public static Client getClient(String certFilePath) throws KeyManagementException {
52                                 
53                 //config.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE);
54                 //config.getClasses().add(org.openecomp.aai.util.CustomJacksonJaxBJsonProvider.class);
55                 
56                 try {
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);
63
64                         
65                         
66                         
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) {
71                                 return true;
72                             }
73                         });
74                 
75 //                      final SSLContext ctx = SSLContext.getInstance("TLS");
76 //                      KeyManagerFactory kmf = null;
77 //                      try {
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();
82 //                              ks.load(fin, pwd);
83 //                              kmf.init(ks, pwd);
84 //                      } catch (Exception e) {
85 //                              System.out.println("Error setting up kmf: exiting");
86 //                              e.printStackTrace();
87 //                              System.exit(1);
88 //                      }
89 //
90 //                      ctx.init(kmf.getKeyManagers(), null, null);
91
92                         return ClientBuilder.newBuilder()
93                                         .hostnameVerifier(new HostnameVerifier() {
94                                                 @Override
95                                                 public boolean verify( String s, SSLSession sslSession ) {
96                                                         return true;
97                                                 }
98                                         }).build()
99                                         .register(org.openecomp.aai.util.CustomJacksonJaxBJsonProvider.class);
100                         
101                 } catch (Exception e) {
102                         System.out.println("Error setting up config: exiting");
103                         e.printStackTrace();
104                         System.exit(1);
105                         return null;
106                 }
107         }
108
109
110         
111 }