36
36
import java .security .cert .X509Certificate ;
37
37
import java .time .Duration ;
38
38
import java .util .Arrays ;
39
+ import java .util .Optional ;
39
40
import java .util .concurrent .Executors ;
40
41
import java .util .concurrent .ScheduledExecutorService ;
41
42
import java .util .concurrent .TimeUnit ;
@@ -68,12 +69,12 @@ public class ReloadingKeyManagerFactory extends KeyManagerFactory implements Aut
68
69
*
69
70
* @param keystorePath the keystore file to reload
70
71
* @param keystorePassword the keystore password
71
- * @param reloadInterval the duration between reload attempts. Set to {@link
72
- * java.time.Duration#ZERO} to disable scheduled reloading.
72
+ * @param reloadInterval the duration between reload attempts. Set to {@link Optional#empty()} to
73
+ * disable scheduled reloading.
73
74
* @return
74
75
*/
75
- public static ReloadingKeyManagerFactory create (
76
- Path keystorePath , String keystorePassword , Duration reloadInterval )
76
+ static ReloadingKeyManagerFactory create (
77
+ Path keystorePath , String keystorePassword , Optional < Duration > reloadInterval )
77
78
throws UnrecoverableKeyException , KeyStoreException , NoSuchAlgorithmException ,
78
79
CertificateException , IOException {
79
80
KeyManagerFactory kmf = KeyManagerFactory .getInstance (KeyManagerFactory .getDefaultAlgorithm ());
@@ -103,14 +104,24 @@ private ReloadingKeyManagerFactory(Spi spi, Provider provider, String algorithm)
103
104
this .spi = spi ;
104
105
}
105
106
106
- private void start (Path keystorePath , String keystorePassword , Duration reloadInterval ) {
107
+ private void start (
108
+ Path keystorePath , String keystorePassword , Optional <Duration > reloadInterval ) {
107
109
this .keystorePath = keystorePath ;
108
110
this .keystorePassword = keystorePassword ;
109
111
110
112
// Ensure that reload is called once synchronously, to make sure the file exists etc.
111
113
reload ();
112
114
113
- if (!reloadInterval .isZero ()) {
115
+ if (!reloadInterval .isPresent () || reloadInterval .get ().isZero ()) {
116
+ final String msg =
117
+ "KeyStore reloading is disabled. If your Cassandra cluster requires client certificates, "
118
+ + "client application restarts are infrequent, and client certificates have short lifetimes, then your client "
119
+ + "may fail to re-establish connections to Cassandra hosts. To enable KeyStore reloading, see "
120
+ + "`advanced.ssl-engine-factory.keystore-reload-interval` in reference.conf." ;
121
+ logger .info (msg );
122
+ } else {
123
+ logger .info ("KeyStore reloading is enabled with interval {}" , reloadInterval .get ());
124
+
114
125
this .executor =
115
126
Executors .newScheduledThreadPool (
116
127
1 ,
@@ -122,8 +133,8 @@ private void start(Path keystorePath, String keystorePassword, Duration reloadIn
122
133
});
123
134
this .executor .scheduleWithFixedDelay (
124
135
this ::reload ,
125
- reloadInterval .toMillis (),
126
- reloadInterval .toMillis (),
136
+ reloadInterval .get (). toMillis (),
137
+ reloadInterval .get (). toMillis (),
127
138
TimeUnit .MILLISECONDS );
128
139
}
129
140
}
@@ -135,7 +146,7 @@ void reload() {
135
146
} catch (Exception e ) {
136
147
String msg =
137
148
"Failed to reload KeyStore. If this continues to happen, your client may use stale identity"
138
- + "certificates and fail to re-establish connections to Cassandra hosts." ;
149
+ + " certificates and fail to re-establish connections to Cassandra hosts." ;
139
150
logger .warn (msg , e );
140
151
}
141
152
}
0 commit comments