Skip to content

Commit

Permalink
log information about SSLFactory renewal (apache#12357)
Browse files Browse the repository at this point in the history
* log infomation about SSLFactory renewal

* update log

* fix typo
  • Loading branch information
zhtaoxiang authored and suyashpatel98 committed Feb 28, 2024
1 parent 05a7d04 commit 968cc9b
Showing 1 changed file with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,8 @@ static void reloadSslFactoryWhenFileStoreChanges(SSLFactory baseSslFactory,
String trustStoreType, String trustStorePath, String trustStorePassword,
String sslContextProtocol, SecureRandom secureRandom)
throws IOException, URISyntaxException, InterruptedException {
LOGGER.info("Enable auto renewal of SSLFactory {} when key store {} or trust store {} changes",
baseSslFactory, keyStorePath, trustStorePath);
WatchService watchService = FileSystems.getDefault().newWatchService();
Map<WatchKey, Set<Path>> watchKeyPathMap = new HashMap<>();
registerFile(watchService, watchKeyPathMap, keyStorePath);
Expand All @@ -442,10 +444,15 @@ static void reloadSslFactoryWhenFileStoreChanges(SSLFactory baseSslFactory,
for (WatchEvent<?> event : key.pollEvents()) {
Path changedFile = (Path) event.context();
if (watchKeyPathMap.get(key).contains(changedFile)) {
LOGGER.info("Detected change in file: {}, try to renew SSLFactory {} "
+ "(built from key store {} and truststore {})",
changedFile, baseSslFactory, keyStorePath, trustStorePath);
SSLFactory updatedSslFactory = createSSLFactory(
keyStoreType, keyStorePath, keyStorePassword, trustStoreType, trustStorePath, trustStorePassword,
sslContextProtocol, secureRandom, false);
SSLFactoryUtils.reload(baseSslFactory, updatedSslFactory);
LOGGER.info("Successfully renewed SSLFactory {} (built from key store {} and truststore {}) "
+ "on file {} changes", baseSslFactory, keyStorePath, trustStorePath, changedFile);
}
}
key.reset();
Expand Down Expand Up @@ -514,6 +521,9 @@ static SSLFactory createSSLFactory(
if (trustStoreStream != null) {
trustStoreStream.close();
}
LOGGER.info("Successfully created SSLFactory {} with key store {} and trust store {}. "
+ "Key and trust material swappable: {}",
sslFactory, keyStorePath, trustStorePath, keyAndTrustMaterialSwappable);
return sslFactory;
} catch (Exception e) {
throw new IllegalStateException(e);
Expand Down

0 comments on commit 968cc9b

Please sign in to comment.