|
4 | 4 | package com.azure.security.keyvault.jca; |
5 | 5 |
|
6 | 6 | import java.security.KeyStore; |
| 7 | +import java.time.Duration; |
7 | 8 | import java.util.Collections; |
8 | 9 | import java.util.HashSet; |
9 | 10 | import java.util.Objects; |
@@ -60,9 +61,9 @@ public final class KeyVaultLoadStoreParameter implements KeyStore.LoadStoreParam |
60 | 61 | private boolean disableChallengeResourceVerification = false; |
61 | 62 |
|
62 | 63 | /** |
63 | | - * Stores the certificate refresh interval in milliseconds. |
| 64 | + * Stores the certificate refresh interval. |
64 | 65 | */ |
65 | | - private long certificatesRefreshIntervalInMs; |
| 66 | + private Duration certificatesRefreshInterval = Duration.ZERO; |
66 | 67 |
|
67 | 68 | /** |
68 | 69 | * Stores a flag indicating whether AIA certificate downloads are disabled. |
@@ -108,13 +109,17 @@ public static KeyVaultLoadStoreParameter fromSystemProperties() { |
108 | 109 | parameter.disableChallengeResourceVerification(); |
109 | 110 | } |
110 | 111 |
|
| 112 | + KeyVaultKeyStore.warnIfRemovedCertificatesRefreshIntervalIsConfigured(); |
111 | 113 | String refreshInterval |
112 | | - = System.getProperty(KeyVaultJcaPropertyNames.KEYVAULT_JCA_CERTIFICATES_REFRESH_INTERVAL_IN_MS); |
113 | | - if (refreshInterval == null) { |
114 | | - refreshInterval = System.getProperty(KeyVaultJcaPropertyNames.KEYVAULT_JCA_CERTIFICATES_REFRESH_INTERVAL); |
115 | | - } |
| 114 | + = System.getProperty(KeyVaultJcaPropertyNames.KEYVAULT_JCA_CERTIFICATES_REFRESH_INTERVAL); |
116 | 115 | if (refreshInterval != null) { |
117 | | - parameter.setCertificatesRefreshIntervalInMs(Long.parseLong(refreshInterval)); |
| 116 | + Duration interval; |
| 117 | + try { |
| 118 | + interval = Duration.ofMillis(Long.parseLong(refreshInterval)); |
| 119 | + } catch (NumberFormatException exception) { |
| 120 | + interval = Duration.parse(refreshInterval); |
| 121 | + } |
| 122 | + parameter.setCertificatesRefreshInterval(interval); |
118 | 123 | } |
119 | 124 |
|
120 | 125 | if (Boolean.parseBoolean(System.getProperty(KeyVaultJcaPropertyNames.KEYVAULT_JCA_DISABLE_AIA_DOWNLOAD))) { |
@@ -300,22 +305,24 @@ public void disableChallengeResourceVerification() { |
300 | 305 | } |
301 | 306 |
|
302 | 307 | /** |
303 | | - * Gets the certificate refresh interval in milliseconds. |
| 308 | + * Gets the certificate refresh interval. |
304 | 309 | * |
305 | | - * @return The certificate refresh interval in milliseconds. |
| 310 | + * @return The certificate refresh interval. Defaults to {@link Duration#ZERO}, which disables periodic refresh. |
306 | 311 | */ |
307 | | - public long getCertificatesRefreshIntervalInMs() { |
308 | | - return certificatesRefreshIntervalInMs; |
| 312 | + public Duration getCertificatesRefreshInterval() { |
| 313 | + return certificatesRefreshInterval; |
309 | 314 | } |
310 | 315 |
|
311 | 316 | /** |
312 | | - * Sets the certificate refresh interval in milliseconds. |
| 317 | + * Sets the certificate refresh interval. Zero or negative intervals disable periodic refresh. |
313 | 318 | * |
314 | | - * @param certificatesRefreshIntervalInMs The certificate refresh interval in milliseconds. |
| 319 | + * @param certificatesRefreshInterval The certificate refresh interval, for example {@code Duration.parse("PT30S")}. |
315 | 320 | * @return The KeyVaultLoadStoreParameter. |
| 321 | + * @throws NullPointerException if {@code certificatesRefreshInterval} is {@code null}. |
316 | 322 | */ |
317 | | - public KeyVaultLoadStoreParameter setCertificatesRefreshIntervalInMs(long certificatesRefreshIntervalInMs) { |
318 | | - this.certificatesRefreshIntervalInMs = certificatesRefreshIntervalInMs; |
| 323 | + public KeyVaultLoadStoreParameter setCertificatesRefreshInterval(Duration certificatesRefreshInterval) { |
| 324 | + this.certificatesRefreshInterval |
| 325 | + = Objects.requireNonNull(certificatesRefreshInterval, "'certificatesRefreshInterval' cannot be null."); |
319 | 326 | return this; |
320 | 327 | } |
321 | 328 |
|
|
0 commit comments