Properly close input streams when loading key stores

See gh-25884
pull/27078/head
Alex Belyaev 4 years ago committed by Stephane Nicoll
parent 2ac160a9b8
commit 1e3f5c342b

@ -16,6 +16,7 @@
package org.springframework.boot.autoconfigure.couchbase;
import java.io.InputStream;
import java.net.URL;
import java.security.KeyStore;
@ -107,7 +108,9 @@ public class CouchbaseAutoConfiguration {
private KeyStore loadKeyStore(String resource, String keyStorePassword) throws Exception {
KeyStore store = KeyStore.getInstance(KeyStore.getDefaultType());
URL url = ResourceUtils.getURL(resource);
store.load(url.openStream(), (keyStorePassword != null) ? keyStorePassword.toCharArray() : null);
try (InputStream inputStream = url.openStream()) {
store.load(inputStream, (keyStorePassword != null) ? keyStorePassword.toCharArray() : null);
}
return store;
}

@ -16,6 +16,7 @@
package org.springframework.boot.web.embedded.netty;
import java.io.InputStream;
import java.net.Socket;
import java.net.URL;
import java.security.InvalidAlgorithmParameterException;
@ -170,7 +171,9 @@ public class SslServerCustomizer implements NettyServerCustomizer {
KeyStore store = (provider != null) ? KeyStore.getInstance(type, provider) : KeyStore.getInstance(type);
try {
URL url = ResourceUtils.getURL(resource);
store.load(url.openStream(), (password != null) ? password.toCharArray() : null);
try (InputStream inputStream = url.openStream()) {
store.load(inputStream, (password != null) ? password.toCharArray() : null);
}
return store;
}
catch (Exception ex) {

@ -16,6 +16,7 @@
package org.springframework.boot.web.embedded.undertow;
import java.io.InputStream;
import java.net.InetAddress;
import java.net.Socket;
import java.net.URL;
@ -181,7 +182,9 @@ class SslBuilderCustomizer implements UndertowBuilderCustomizer {
KeyStore store = (provider != null) ? KeyStore.getInstance(type, provider) : KeyStore.getInstance(type);
try {
URL url = ResourceUtils.getURL(resource);
store.load(url.openStream(), (password != null) ? password.toCharArray() : null);
try (InputStream inputStream = url.openStream()) {
store.load(inputStream, (password != null) ? password.toCharArray() : null);
}
return store;
}
catch (Exception ex) {

Loading…
Cancel
Save