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.vid.client;
23 import org.eclipse.jetty.util.security.Password;
24 import org.glassfish.jersey.client.ClientConfig;
25 import org.glassfish.jersey.client.ClientProperties;
26 import org.onap.vid.properties.VidProperties;
27 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
28 import org.onap.portalsdk.core.util.SystemProperties;
30 import javax.net.ssl.HostnameVerifier;
31 import javax.net.ssl.HttpsURLConnection;
32 import javax.net.ssl.SSLContext;
33 import javax.net.ssl.SSLSession;
34 import javax.ws.rs.client.Client;
35 import javax.ws.rs.client.ClientBuilder;
37 import java.text.DateFormat;
38 import java.text.SimpleDateFormat;
39 import java.util.Date;
42 * General SSL client using the VID tomcat keystore. It doesn't use client certificates.
45 public class HttpsBasicClient{
48 static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(HttpsBasicClient.class);
50 /** The Constant dateFormat. */
51 final static DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS");
54 * Retrieve an SSL client.
56 * @return Client The SSL client
57 * @throws Exception the exception
59 public static Client getClient() {
60 String methodName = "getClient";
61 ClientConfig config = new ClientConfig();
63 SSLContext ctx = null;
67 config.property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true);
69 String truststore_path = SystemProperties.getProperty(VidProperties.VID_TRUSTSTORE_FILENAME);
70 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + " " + methodName + " truststore_path=" + truststore_path);
71 String truststore_password = SystemProperties.getProperty(VidProperties.VID_TRUSTSTORE_PASSWD_X);
74 String decrypted_truststore_password = Password.deobfuscate(truststore_password);
75 //logger.debug(dateFormat.format(new Date()) + " " + methodName + " decrypted_truststore_password=" + decrypted_truststore_password);
77 File tr = new File (truststore_path);
78 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + " " + methodName + " absolute truststore path=" + tr.getAbsolutePath());
80 System.setProperty("javax.net.ssl.trustStore", truststore_path);
81 System.setProperty("javax.net.ssl.trustStorePassword", decrypted_truststore_password);
82 HttpsURLConnection.setDefaultHostnameVerifier( new HostnameVerifier(){
83 public boolean verify(String string,SSLSession ssls) {
88 //May need to make the algorithm a parameter. MSO requires TLSv1.1 or TLSv1.2
89 ctx = SSLContext.getInstance("TLSv1.2");
91 ctx.init(null, null, null);
92 //config.getProperties().put(HTTPSProperties.PROPERTY_HTTPS_PROPERTIES,
93 // new HTTPSProperties( , ctx));
95 return ClientBuilder.newBuilder()
97 .hostnameVerifier(new HostnameVerifier() {
99 public boolean verify( String s, SSLSession sslSession ) {
102 }).withConfig(config)
104 .register(org.onap.vid.aai.util.CustomJacksonJaxBJsonProvider.class);
106 } catch (Exception e) {
107 logger.debug(EELFLoggerDelegate.debugLogger, "Error setting up config: exiting", e);