diff options
author | Claudio D. Gasparini <claudio.gasparini@intl.att.com> | 2021-03-23 18:39:35 +0100 |
---|---|---|
committer | Claudio David Gasparini <claudio.gasparini@intl.att.com> | 2021-03-24 06:57:28 +0000 |
commit | 2bed5569d0caeacbcca471e1ce0a23ba4a3f9a80 (patch) | |
tree | e81e64d81a38d79b18a436036ec5a8c16f710f05 | |
parent | 1f5c3b30a6bcee56dcdf848e578f2f72cddd3cd7 (diff) |
Fix Certificate Exception when using BasicAuthRestClientService
by using TrustAllStrategy
Issue-ID: CCSDK-3234
Signed-off-by: Claudio D. Gasparini <claudio.gasparini@intl.att.com>
Change-Id: I7ee63739b4f1d7a4ddbc618ba660704aa058752a
(cherry picked from commit f13c7c4cb1fd32d5f0d36a909285cab2c4337cf9)
-rw-r--r-- | ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/BasicAuthRestClientService.kt | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/BasicAuthRestClientService.kt b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/BasicAuthRestClientService.kt index be9b849f6..5ab848893 100644 --- a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/BasicAuthRestClientService.kt +++ b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/BasicAuthRestClientService.kt @@ -16,8 +16,15 @@ package org.onap.ccsdk.cds.blueprintsprocessor.rest.service +import org.apache.http.conn.ssl.NoopHostnameVerifier +import org.apache.http.conn.ssl.SSLConnectionSocketFactory +import org.apache.http.conn.ssl.TrustAllStrategy +import org.apache.http.impl.client.CloseableHttpClient +import org.apache.http.impl.client.HttpClients import org.apache.http.message.BasicHeader +import org.apache.http.ssl.SSLContextBuilder import org.onap.ccsdk.cds.blueprintsprocessor.rest.BasicAuthRestClientProperties +import org.onap.ccsdk.cds.blueprintsprocessor.rest.utils.WebClientUtils import org.springframework.http.HttpHeaders import org.springframework.http.MediaType import java.net.URI @@ -48,6 +55,17 @@ class BasicAuthRestClientService( return uri.resolve(uri).toString() } + override fun httpClient(): CloseableHttpClient { + val sslContext = SSLContextBuilder.create() + + sslContext.loadTrustMaterial(TrustAllStrategy.INSTANCE) + val csf = SSLConnectionSocketFactory(sslContext.build(), NoopHostnameVerifier()) + return HttpClients.custom() + .addInterceptorFirst(WebClientUtils.logRequest()) + .addInterceptorLast(WebClientUtils.logResponse()) + .setSSLSocketFactory(csf).build() + } + override fun convertToBasicHeaders(headers: Map<String, String>): Array<BasicHeader> { val customHeaders: MutableMap<String, String> = headers.toMutableMap() |