Skip to content

Commit 53e030b

Browse files
[PRM-223] Removed self-signed certificate trusting (#307)
1 parent 8fa984c commit 53e030b

File tree

1 file changed

+4
-37
lines changed

1 file changed

+4
-37
lines changed

services/suspension-service/src/main/java/uk/nhs/prm/repo/suspension/service/config/HttpClientConfig.java

Lines changed: 4 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,9 @@
55
import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager;
66
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
77
import org.apache.hc.client5.http.impl.classic.HttpClients;
8-
import org.apache.hc.client5.http.socket.ConnectionSocketFactory;
9-
import org.apache.hc.client5.http.socket.PlainConnectionSocketFactory;
10-
import org.apache.hc.client5.http.ssl.SSLConnectionSocketFactory;
11-
import org.apache.hc.client5.http.ssl.TrustSelfSignedStrategy;
8+
import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManagerBuilder;
129
import org.apache.hc.core5.http.HeaderElement;
13-
import org.apache.hc.core5.http.config.Registry;
14-
import org.apache.hc.core5.http.config.RegistryBuilder;
1510
import org.apache.hc.core5.http.message.BasicHeaderElementIterator;
16-
import org.apache.hc.core5.ssl.SSLContextBuilder;
1711
import org.apache.hc.core5.util.TimeValue;
1812
import org.apache.hc.core5.util.Timeout;
1913
import org.apache.hc.core5.http.HttpHeaders;
@@ -23,10 +17,6 @@
2317
import org.springframework.context.annotation.Configuration;
2418
import org.springframework.scheduling.annotation.Scheduled;
2519

26-
import java.security.KeyManagementException;
27-
import java.security.KeyStoreException;
28-
import java.security.NoSuchAlgorithmException;
29-
3020
@Configuration
3121
public class HttpClientConfig {
3222

@@ -43,35 +33,12 @@ public class HttpClientConfig {
4333
= Integer.getInteger("DEFAULT_KEEP_ALIVE_TIME_MILLIS", DEFAULT_KEEP_ALIVE_TIME_MILLIS);
4434
//@formatter:on
4535

36+
4637
@Bean
4738
public PoolingHttpClientConnectionManager poolingConnectionManager() {
48-
SSLContextBuilder builder = new SSLContextBuilder();
49-
try {
50-
builder.loadTrustMaterial(null, new TrustSelfSignedStrategy());
51-
}
52-
catch (NoSuchAlgorithmException | KeyStoreException e) {
53-
LOGGER.error("Pooling Connection Manager Initialisation failure because of "
54-
+ e.getMessage(), e);
55-
}
56-
57-
SSLConnectionSocketFactory sslsf = null;
58-
try {
59-
sslsf = new SSLConnectionSocketFactory(builder.build());
60-
}
61-
catch (KeyManagementException | NoSuchAlgorithmException e) {
62-
LOGGER.error("Pooling Connection Manager Initialisation failure because of "
63-
+ e.getMessage(), e);
64-
}
65-
66-
Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder
67-
.<ConnectionSocketFactory> create().register("https", sslsf)
68-
.register("http", new PlainConnectionSocketFactory())
39+
return PoolingHttpClientConnectionManagerBuilder.create()
40+
.setMaxConnTotal(MAX_TOTAL_CONNECTIONS)
6941
.build();
70-
71-
PoolingHttpClientConnectionManager poolingConnectionManager =
72-
new PoolingHttpClientConnectionManager(socketFactoryRegistry);
73-
poolingConnectionManager.setMaxTotal(MAX_TOTAL_CONNECTIONS);
74-
return poolingConnectionManager;
7542
}
7643

7744
@Bean

0 commit comments

Comments
 (0)