|
21 | 21 | import java.io.File; |
22 | 22 | import java.nio.file.Path; |
23 | 23 | import org.apache.yetus.audience.InterfaceAudience; |
| 24 | +import org.apache.zookeeper.common.ClientX509Util; |
24 | 25 | import org.apache.zookeeper.common.ConfigException; |
25 | 26 | import org.apache.zookeeper.common.ZKConfig; |
26 | 27 |
|
@@ -59,6 +60,7 @@ public class ZKClientConfig extends ZKConfig { |
59 | 60 | * Feature is disabled by default. |
60 | 61 | */ |
61 | 62 | public static final long ZOOKEEPER_REQUEST_TIMEOUT_DEFAULT = 0; |
| 63 | + private static final String ZOOKEEPER_PREFIX = "zookeeper."; |
62 | 64 | public static final String ZK_SASL_CLIENT_ALLOW_REVERSE_DNS = "zookeeper.sasl.client.allowReverseDnsLookup"; |
63 | 65 | public static final boolean ZK_SASL_CLIENT_ALLOW_REVERSE_DNS_DEFAULT = false; |
64 | 66 | /** |
@@ -107,6 +109,12 @@ public ZKClientConfig(Path configPath) throws ConfigException { |
107 | 109 | super(configPath); |
108 | 110 | } |
109 | 111 |
|
| 112 | + @Override |
| 113 | + public void addConfiguration(Path configPath) throws ConfigException { |
| 114 | + super.addConfiguration(configPath); |
| 115 | + applyServerSslConfiguration(); |
| 116 | + } |
| 117 | + |
110 | 118 | /** |
111 | 119 | * Initialize all the ZooKeeper client properties which are configurable as |
112 | 120 | * java system property |
@@ -139,6 +147,43 @@ protected void handleBackwardCompatibility() { |
139 | 147 | setProperty(DNS_SRV_REFRESH_INTERVAL_SECONDS, System.getProperty(DNS_SRV_REFRESH_INTERVAL_SECONDS)); |
140 | 148 | } |
141 | 149 |
|
| 150 | + private void applyServerSslConfiguration() { |
| 151 | + try (ClientX509Util clientX509Util = new ClientX509Util()) { |
| 152 | + copyServerSslProperty(clientX509Util.getSslProtocolProperty()); |
| 153 | + copyServerSslProperty(clientX509Util.getSslEnabledProtocolsProperty()); |
| 154 | + copyServerSslProperty(clientX509Util.getSslCipherSuitesProperty()); |
| 155 | + copyServerSslProperty(clientX509Util.getSslKeystoreLocationProperty()); |
| 156 | + copyServerSslProperty(clientX509Util.getSslKeystorePasswdProperty()); |
| 157 | + copyServerSslProperty(clientX509Util.getSslKeystorePasswdPathProperty()); |
| 158 | + copyServerSslProperty(clientX509Util.getSslKeystoreTypeProperty()); |
| 159 | + copyServerSslProperty(clientX509Util.getSslTruststoreLocationProperty()); |
| 160 | + copyServerSslProperty(clientX509Util.getSslTruststorePasswdProperty()); |
| 161 | + copyServerSslProperty(clientX509Util.getSslTruststorePasswdPathProperty()); |
| 162 | + copyServerSslProperty(clientX509Util.getSslTruststoreTypeProperty()); |
| 163 | + copyServerSslProperty(clientX509Util.getSslContextSupplierClassProperty()); |
| 164 | + copyServerSslProperty(clientX509Util.getSslHostnameVerificationEnabledProperty()); |
| 165 | + copyServerSslProperty(clientX509Util.getSslCrlEnabledProperty()); |
| 166 | + copyServerSslProperty(clientX509Util.getSslOcspEnabledProperty()); |
| 167 | + copyServerSslProperty(clientX509Util.getSslClientAuthProperty()); |
| 168 | + copyServerSslProperty(clientX509Util.getSslHandshakeDetectionTimeoutMillisProperty()); |
| 169 | + copyServerSslProperty(clientX509Util.getSslAuthProviderProperty()); |
| 170 | + } |
| 171 | + } |
| 172 | + |
| 173 | + private void copyServerSslProperty(String clientProperty) { |
| 174 | + if (clientProperty == null || getProperty(clientProperty) != null) { |
| 175 | + return; |
| 176 | + } |
| 177 | + if (!clientProperty.startsWith(ZOOKEEPER_PREFIX)) { |
| 178 | + return; |
| 179 | + } |
| 180 | + String serverProperty = clientProperty.substring(ZOOKEEPER_PREFIX.length()); |
| 181 | + String serverValue = getProperty(serverProperty); |
| 182 | + if (serverValue != null) { |
| 183 | + setProperty(clientProperty, serverValue); |
| 184 | + } |
| 185 | + } |
| 186 | + |
142 | 187 | /** |
143 | 188 | * Returns true if the SASL client is enabled. By default, the client is |
144 | 189 | * enabled but can be disabled by setting the system property |
|
0 commit comments