From 7b0e3cdef226ba4f07eb2d732be8e4ab6ae2eca3 Mon Sep 17 00:00:00 2001 From: Craig Perkins Date: Tue, 18 Oct 2022 09:22:32 -0400 Subject: [PATCH] Remove unused code, use variable for so timeout and set charset in WebhookSink Signed-off-by: Craig Perkins --- .../test/framework/cluster/TestRestClient.java | 9 --------- .../amazon/dlic/util/SettingsBasedSSLConfigurator.java | 5 ----- .../opensearch/security/auditlog/sink/WebhookSink.java | 7 ++++--- 3 files changed, 4 insertions(+), 17 deletions(-) diff --git a/src/integrationTest/java/org/opensearch/test/framework/cluster/TestRestClient.java b/src/integrationTest/java/org/opensearch/test/framework/cluster/TestRestClient.java index 7a79363030..c578ca2e77 100644 --- a/src/integrationTest/java/org/opensearch/test/framework/cluster/TestRestClient.java +++ b/src/integrationTest/java/org/opensearch/test/framework/cluster/TestRestClient.java @@ -380,15 +380,6 @@ public void setRequestConfig(RequestConfig requestConfig) { this.requestConfig = requestConfig; } - // TODO Can this be removed? -// public void setLocalAddress(InetAddress inetAddress) { -// if (requestConfig == null) { -// requestConfig = RequestConfig.custom().setLocalAddress(inetAddress).build(); -// } else { -// requestConfig = RequestConfig.copy(requestConfig).setLocalAddress(inetAddress).build(); -// } -// } - public boolean isSendHTTPClientCertificate() { return sendHTTPClientCertificate; } diff --git a/src/main/java/com/amazon/dlic/util/SettingsBasedSSLConfigurator.java b/src/main/java/com/amazon/dlic/util/SettingsBasedSSLConfigurator.java index 240888a576..03800feace 100644 --- a/src/main/java/com/amazon/dlic/util/SettingsBasedSSLConfigurator.java +++ b/src/main/java/com/amazon/dlic/util/SettingsBasedSSLConfigurator.java @@ -429,11 +429,6 @@ public HostnameVerifier getHostnameVerifier() { return hostnameVerifier; } - // TODO Can this be removed? -// public SSLIOSessionStrategy toSSLIOSessionStrategy() { -// return new SSLIOSessionStrategy(sslContext, supportedProtocols, supportedCipherSuites, hostnameVerifier); -// } - public SSLConnectionSocketFactory toSSLConnectionSocketFactory() { return new SSLConnectionSocketFactory(sslContext, supportedProtocols, supportedCipherSuites, hostnameVerifier); diff --git a/src/main/java/org/opensearch/security/auditlog/sink/WebhookSink.java b/src/main/java/org/opensearch/security/auditlog/sink/WebhookSink.java index d841ab5075..af4525fcba 100644 --- a/src/main/java/org/opensearch/security/auditlog/sink/WebhookSink.java +++ b/src/main/java/org/opensearch/security/auditlog/sink/WebhookSink.java @@ -14,6 +14,7 @@ import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; +import java.nio.charset.StandardCharsets; import java.nio.file.Path; import java.security.AccessController; import java.security.KeyStore; @@ -275,7 +276,7 @@ protected boolean doPost(String url, String payload) { HttpPost postRequest = new HttpPost(url); - StringEntity input = new StringEntity(payload, webhookFormat.contentType); + StringEntity input = new StringEntity(payload, webhookFormat.contentType.withCharset(StandardCharsets.UTF_8)); postRequest.setEntity(input); CloseableHttpResponse serverResponse = null; @@ -364,7 +365,7 @@ public boolean isTrusted(X509Certificate[] chain, String authType) { final HttpClientConnectionManager cm = PoolingHttpClientConnectionManagerBuilder.create() .setSSLSocketFactory(sslsf) - .setDefaultSocketConfig(SocketConfig.custom().setSoTimeout(60, TimeUnit.SECONDS).build()) + .setDefaultSocketConfig(SocketConfig.custom().setSoTimeout(timeout, TimeUnit.SECONDS).build()) .build(); hcb.setConnectionManager(cm); return hcb.build(); @@ -381,7 +382,7 @@ public boolean isTrusted(X509Certificate[] chain, String authType) { final HttpClientConnectionManager cm = PoolingHttpClientConnectionManagerBuilder.create() .setSSLSocketFactory(sslsf) - .setDefaultSocketConfig(SocketConfig.custom().setSoTimeout(60, TimeUnit.SECONDS).build()) + .setDefaultSocketConfig(SocketConfig.custom().setSoTimeout(timeout, TimeUnit.SECONDS).build()) .build(); hcb.setConnectionManager(cm);