Skip to content

Commit a9a23ca

Browse files
garyrussellartembilan
authored andcommitted
GH-1237: RCFB Close key/trust store input streams
Resolves #1237 **cherry-pick to 2.2.x, 2.1.x, 1.7.x** (cherry picked from commit 165b838)
1 parent 3be802f commit a9a23ca

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

spring-rabbit/src/main/java/org/springframework/amqp/rabbit/connection/RabbitConnectionFactoryBean.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.springframework.amqp.rabbit.connection;
1818

1919
import java.io.IOException;
20+
import java.io.InputStream;
2021
import java.net.URI;
2122
import java.net.URISyntaxException;
2223
import java.security.KeyManagementException;
@@ -756,7 +757,9 @@ protected KeyManager[] configureKeyManagers() throws KeyStoreException, IOExcept
756757
Resource resource = this.keyStoreResource != null ? this.keyStoreResource
757758
: this.resolver.getResource(keyStoreName);
758759
KeyStore ks = KeyStore.getInstance(storeType);
759-
ks.load(resource.getInputStream(), keyPassphrase);
760+
try (InputStream inputStream = resource.getInputStream()) {
761+
ks.load(inputStream, keyPassphrase);
762+
}
760763
KeyManagerFactory kmf = KeyManagerFactory.getInstance(this.keyStoreAlgorithm);
761764
kmf.init(ks, keyPassphrase);
762765
keyManagers = kmf.getKeyManagers();
@@ -779,7 +782,9 @@ protected TrustManager[] configureTrustManagers()
779782
Resource resource = this.trustStoreResource != null ? this.trustStoreResource
780783
: this.resolver.getResource(trustStoreName);
781784
KeyStore tks = KeyStore.getInstance(storeType);
782-
tks.load(resource.getInputStream(), trustPassphrase);
785+
try (InputStream inputStream = resource.getInputStream()) {
786+
tks.load(inputStream, trustPassphrase);
787+
}
783788
TrustManagerFactory tmf = TrustManagerFactory.getInstance(this.trustStoreAlgorithm);
784789
tmf.init(tks);
785790
trustManagers = tmf.getTrustManagers();

0 commit comments

Comments
 (0)