Skip to content

Commit

Permalink
Revert "disable certificate verification in HttpRequestBuilder.kt"
Browse files Browse the repository at this point in the history
This reverts commit 0b40761.
  • Loading branch information
BacicaFlorinTelus committed Oct 18, 2021
1 parent 0b40761 commit b732783
Showing 1 changed file with 0 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,7 @@ import java.io.InputStreamReader
import java.net.URI
import java.util.stream.Collectors
import org.apache.http.HttpHost
import org.apache.http.config.RegistryBuilder
import org.apache.http.conn.socket.ConnectionSocketFactory
import org.apache.http.conn.socket.PlainConnectionSocketFactory
import org.apache.http.conn.ssl.NoopHostnameVerifier
import org.apache.http.conn.ssl.SSLConnectionSocketFactory
import org.apache.http.impl.client.HttpClientBuilder
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager
import org.apache.http.ssl.SSLContexts
import org.apache.http.ssl.TrustStrategy
import org.springframework.http.HttpEntity
import org.springframework.http.HttpHeaders
import org.springframework.http.ResponseEntity
Expand All @@ -25,7 +17,6 @@ import org.springframework.http.client.HttpComponentsClientHttpRequestFactory
import org.springframework.stereotype.Component
import org.springframework.web.client.ResponseErrorHandler
import org.springframework.web.client.RestTemplate
import javax.net.ssl.SSLContext

@Component
class HttpRequestBuilder(private val objectMapper: ObjectMapper, private val requestFile: String) {
Expand Down Expand Up @@ -101,20 +92,9 @@ class HttpRequestBuilder(private val objectMapper: ObjectMapper, private val req
proxyPort: String?
):
HttpComponentsClientHttpRequestFactory {
val acceptingTrustStrategy = TrustStrategy { _, _ -> true }
val sslContext: SSLContext = SSLContexts.custom().loadTrustMaterial(null, acceptingTrustStrategy)
.build()
val csf = SSLConnectionSocketFactory(sslContext, NoopHostnameVerifier.INSTANCE)
val socketFactoryRegistry = RegistryBuilder.create<ConnectionSocketFactory>()
.register("https", csf)
.register("http", PlainConnectionSocketFactory.getSocketFactory())
.build()

val clientHttpRequestFactory = HttpComponentsClientHttpRequestFactory(
HttpClientBuilder.create()
.setProxy(proxyHost?.let { HttpHost(it, proxyPort!!.toInt(), "http") })
.setConnectionManager(PoolingHttpClientConnectionManager(socketFactoryRegistry))
.setSSLSocketFactory(csf)
.build()
)
clientHttpRequestFactory.setConnectTimeout(connectTimeout)
Expand Down

0 comments on commit b732783

Please sign in to comment.