2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ===================================================================
8 * Unless otherwise specified, all software contained herein is licensed
9 * under the Apache License, Version 2.0 (the "License");
10 * you may not use this software except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * Unless otherwise specified, all documentation contained herein is licensed
22 * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
23 * you may not use this documentation except in compliance with the License.
24 * You may obtain a copy of the License at
26 * https://creativecommons.org/licenses/by/4.0/
28 * Unless required by applicable law or agreed to in writing, documentation
29 * distributed under the License is distributed on an "AS IS" BASIS,
30 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 * See the License for the specific language governing permissions and
32 * limitations under the License.
34 * ============LICENSE_END============================================
36 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
39 package org.onap.portalapp.portal.scheduler.client;
42 import java.text.DateFormat;
43 import java.text.SimpleDateFormat;
44 import java.util.Date;
46 import javax.net.ssl.HostnameVerifier;
47 import javax.net.ssl.HttpsURLConnection;
48 import javax.net.ssl.SSLContext;
49 import javax.net.ssl.SSLSession;
50 import javax.ws.rs.client.Client;
51 import javax.ws.rs.client.ClientBuilder;
53 import org.eclipse.jetty.util.security.Password;
54 import org.glassfish.jersey.client.ClientConfig;
55 import org.glassfish.jersey.client.ClientProperties;
56 import org.onap.portalapp.portal.scheduler.SchedulerProperties;
57 import org.onap.portalapp.portal.scheduler.util.CustomJacksonJaxBJsonProvider;
58 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
59 import org.onap.portalsdk.core.util.SystemProperties;
62 * General SSL client using the VID tomcat keystore. It doesn't use client certificates.
65 public class HttpsBasicClient{
68 static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(HttpsBasicClient.class);
70 /** The Constant dateFormat. */
71 final static DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS");
74 * Retrieve an SSL client.
76 * @return Client The SSL client
77 * @throws Exception the exception
79 public static Client getClient() throws Exception {
80 String methodName = "getClient";
81 ClientConfig config = new ClientConfig();
82 //config.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE);
83 //config.getClasses().add(org.openecomp.aai.util.CustomJacksonJaxBJsonProvider.class);
85 SSLContext ctx = null;
89 config.property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true);
91 String truststore_path = SchedulerProperties.getProperty(SchedulerProperties.VID_TRUSTSTORE_FILENAME);
92 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + " " + methodName + " truststore_path=" + truststore_path);
93 String truststore_password = SchedulerProperties.getProperty(SchedulerProperties.VID_TRUSTSTORE_PASSWD_X);
96 String decrypted_truststore_password = Password.deobfuscate(truststore_password);
97 //logger.debug(dateFormat.format(new Date()) + " " + methodName + " decrypted_truststore_password=" + decrypted_truststore_password);
99 File tr = new File (truststore_path);
100 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + " " + methodName + " absolute truststore path=" + tr.getAbsolutePath());
102 //String keystore_path = certFilePath + AAIProperties.FILESEPARTOR + SystemProperties.getProperty(AAIProperties.AAI_KEYSTORE_FILENAME);
103 //String keystore_password = SystemProperties.getProperty(AAIProperties.AAI_KEYSTORE_PASSWD_X);
104 //String decrypted_keystore_password = EncryptedPropValue.decryptTriple(keystore_password);
106 System.setProperty("javax.net.ssl.trustStore", truststore_path);
107 System.setProperty("javax.net.ssl.trustStorePassword", decrypted_truststore_password);
108 HttpsURLConnection.setDefaultHostnameVerifier( new HostnameVerifier(){
109 public boolean verify(String string,SSLSession ssls) {
114 //May need to make the algorithm a parameter. MSO requires TLSv1.1 or TLSv1.2
115 ctx = SSLContext.getInstance("TLSv1.2");
118 KeyManagerFactory kmf = null;
120 kmf = KeyManagerFactory.getInstance("SunX509");
121 FileInputStream fin = new FileInputStream(keystore_path);
122 KeyStore ks = KeyStore.getInstance("PKCS12");
123 char[] pwd = decrypted_keystore_password.toCharArray();
126 } catch (Exception e) {
127 System.out.println("Error setting up kmf: exiting");
132 ctx.init(kmf.getKeyManagers(), null, null);
134 ctx.init(null, null, null);
135 //config.getProperties().put(HTTPSProperties.PROPERTY_HTTPS_PROPERTIES,
136 // new HTTPSProperties( , ctx));
138 return ClientBuilder.newBuilder()
140 .hostnameVerifier(new HostnameVerifier() {
142 public boolean verify( String s, SSLSession sslSession ) {
145 }).withConfig(config)
147 .register(CustomJacksonJaxBJsonProvider.class);
149 } catch (Exception e) {
150 logger.debug(EELFLoggerDelegate.debugLogger, "Error setting up config: exiting");
151 //System.out.println("Error setting up config: exiting");
156 //Client client = ClientBuilder.newClient(config);
157 // uncomment this line to get more logging for the request/response
158 // client.addFilter(new LoggingFilter(System.out));