aboutsummaryrefslogtreecommitdiffstats
path: root/vid-app-common/src/main/java/org/onap/vid/aai/util/HttpsComponentsClient.java
diff options
context:
space:
mode:
authorSonsino, Ofir (os0695) <os0695@intl.att.com>2018-07-10 14:20:54 +0300
committerSonsino, Ofir (os0695) <os0695@intl.att.com>2018-07-10 14:20:54 +0300
commitc72d565bb58226b20625b2bce5f0019046bee649 (patch)
tree8658e49595705b02e47ddc14afa20d6bb7123547 /vid-app-common/src/main/java/org/onap/vid/aai/util/HttpsComponentsClient.java
parentef8a6b47847012fd59ea20da21d8d3d7c4a301ed (diff)
Merge 1806 code of vid-common
Change-Id: I75d52abed4a24dfe3827d79edc4a2938726aa87a Issue-ID: VID-208 Signed-off-by: Sonsino, Ofir (os0695) <os0695@intl.att.com>
Diffstat (limited to 'vid-app-common/src/main/java/org/onap/vid/aai/util/HttpsComponentsClient.java')
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/aai/util/HttpsComponentsClient.java54
1 files changed, 36 insertions, 18 deletions
diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/util/HttpsComponentsClient.java b/vid-app-common/src/main/java/org/onap/vid/aai/util/HttpsComponentsClient.java
index 100222198..d1f1cfc86 100644
--- a/vid-app-common/src/main/java/org/onap/vid/aai/util/HttpsComponentsClient.java
+++ b/vid-app-common/src/main/java/org/onap/vid/aai/util/HttpsComponentsClient.java
@@ -20,25 +20,29 @@
package org.onap.vid.aai.util;
-import java.io.FileInputStream;
-import java.security.KeyManagementException;
-import java.security.KeyStore;
-
-import javax.net.ssl.SSLContext;
-
+import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.conn.ssl.SSLContextBuilder;
import org.apache.http.impl.client.CloseableHttpClient;
-import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.impl.client.HttpClients;
import org.eclipse.jetty.util.security.Password;
+import org.onap.vid.exceptions.GenericUncheckedException;
+import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
import org.onap.portalsdk.core.util.SystemProperties;
+import javax.net.ssl.SSLContext;
+import java.io.FileInputStream;
+import java.security.GeneralSecurityException;
+import java.security.KeyManagementException;
+import java.security.KeyStore;
+
/**
* The Class HttpsComponentsClient.
*/
public class HttpsComponentsClient{
-
+
+ static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(HttpsComponentsClient.class);
+
/**
* Gets the client.
*
@@ -46,10 +50,10 @@ public class HttpsComponentsClient{
* @return the client
* @throws KeyManagementException the key management exception
*/
- public static CloseableHttpClient getClient(String certFilePath) throws Exception {
+ public static CloseableHttpClient getClient(String certFilePath) {
CloseableHttpClient httpclient = null;
try {
-
+
String truststore_path = certFilePath + AAIProperties.FILESEPARTOR + SystemProperties.getProperty(AAIProperties.AAI_TRUSTSTORE_FILENAME);
String truststore_password = SystemProperties.getProperty(AAIProperties.AAI_TRUSTSTORE_PASSWD_X);
String decrypted_truststore_password = Password.deobfuscate(truststore_password);
@@ -60,17 +64,31 @@ public class HttpsComponentsClient{
SSLContextBuilder sslContextB = new SSLContextBuilder();
KeyStore ks = KeyStore.getInstance("PKCS12");
- FileInputStream fin = new FileInputStream(keystore_path);
char[] pwd = decrypted_keystore_password.toCharArray();
- ks.load(fin, pwd);
-
+
+ try(FileInputStream fin = new FileInputStream(keystore_path)) {
+ ks.load(fin, pwd);
+ }
+ catch (Exception e) {
+ logger.debug(EELFLoggerDelegate.debugLogger, "Error setting up keystore");
+ logger.error(EELFLoggerDelegate.errorLogger, "Error loading keystore materials: (keystore path: {}, obfuascated keystore password: {})", keystore_path, keystore_password);
+ throw new GenericUncheckedException(e);
+ }
+
sslContextB.loadKeyMaterial(ks, pwd);
KeyStore ts = KeyStore.getInstance("JKS");
- FileInputStream fin1 = new FileInputStream(truststore_path);
char[] pwd1 = decrypted_truststore_password.toCharArray();
- ts.load(fin1, pwd1);
-
+
+ try(FileInputStream fin1 = new FileInputStream(truststore_path)) {
+ ts.load(fin1, pwd1);
+ }
+ catch (Exception e) {
+ logger.debug(EELFLoggerDelegate.debugLogger, "Error setting up truststore");
+ logger.error(EELFLoggerDelegate.errorLogger, "Error loading truststore materials: (truststore path: {}, obfuascated truststore password: {})", truststore_path, truststore_password);
+ throw new GenericUncheckedException(e);
+ }
+
sslContextB.loadTrustMaterial(ts);
sslContextB.loadKeyMaterial(ks, pwd);
sslContextB.useTLS();
@@ -88,8 +106,8 @@ public class HttpsComponentsClient{
.build();
- } catch (Exception e) {
- throw e;
+ } catch (GeneralSecurityException e) {
+ throw new GenericUncheckedException(e);
}
return httpclient;
}