From 1245c660ab8e28d6da1ed63a99df6b47f2d9d59e Mon Sep 17 00:00:00 2001 From: Cristian Manole <81580181+CManole@users.noreply.github.com> Date: Wed, 15 Dec 2021 20:16:31 +0200 Subject: [PATCH] fix fortify (#1651) * fix fortify * , --- ...vidValidationCertificateToProtobufMapping.java | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/dgc/dsc/DigitalCovidValidationCertificateToProtobufMapping.java b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/dgc/dsc/DigitalCovidValidationCertificateToProtobufMapping.java index 26a986a45b..a933b0a0a5 100644 --- a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/dgc/dsc/DigitalCovidValidationCertificateToProtobufMapping.java +++ b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/dgc/dsc/DigitalCovidValidationCertificateToProtobufMapping.java @@ -178,13 +178,11 @@ public Optional constructProtobufMapping() { private ServiceProviderDto validateFingerprint(String serviceProviderAllowlistEndpoint, String fingerPrintToCompare, final ObjectMapper objectMapper) { - try { - CloseableHttpClient httpClient = HttpClients.custom() - .setSSLHostnameVerifier((hostname, session) -> validateHostname( - session, - fingerPrintToCompare)) - .build(); - + try (CloseableHttpClient httpClient = HttpClients.custom() + .setSSLHostnameVerifier((hostname, session) -> validateHostname( + session, + fingerPrintToCompare)) + .build()) { HttpGet getMethod = new HttpGet(serviceProviderAllowlistEndpoint); final HttpEntity httpEntity = executeRequest(httpClient, getMethod); return buildServiceProviderDto(objectMapper, httpEntity); @@ -242,8 +240,7 @@ private boolean matches(final Certificate cert, final String fingerPrintToCompar private HttpEntity executeRequest(CloseableHttpClient httpClient, HttpGet getMethod) throws InvalidFingerprintException { - try { - final CloseableHttpResponse response = httpClient.execute(getMethod); + try (final CloseableHttpResponse response = httpClient.execute(getMethod)) { return response.getEntity(); } catch (Exception e) { LOGGER.warn("Request to obtain the service providers failed: ", e);