2121import java .io .File ;
2222import org .apache .yetus .audience .InterfaceAudience ;
2323import org .apache .zookeeper .ZooKeeper ;
24+ import org .apache .zookeeper .common .ClientX509Util ;
2425import org .apache .zookeeper .common .ZKConfig ;
2526import org .apache .zookeeper .server .quorum .QuorumPeerConfig .ConfigException ;
2627
@@ -64,6 +65,7 @@ public class ZKClientConfig extends ZKConfig {
6465 * Feature is disabled by default.
6566 */
6667 public static final long ZOOKEEPER_REQUEST_TIMEOUT_DEFAULT = 0 ;
68+ private static final String ZOOKEEPER_PREFIX = "zookeeper." ;
6769
6870 public ZKClientConfig () {
6971 super ();
@@ -78,6 +80,12 @@ public ZKClientConfig(String configPath) throws ConfigException {
7880 super (configPath );
7981 }
8082
83+ @ Override
84+ public void addConfiguration (File configFile ) throws ConfigException {
85+ super .addConfiguration (configFile );
86+ applyServerSslConfiguration ();
87+ }
88+
8189 /**
8290 * Initialize all the ZooKeeper client properties which are configurable as
8391 * java system property
@@ -108,6 +116,43 @@ protected void handleBackwardCompatibility() {
108116 setProperty (SECURE_CLIENT , System .getProperty (SECURE_CLIENT ));
109117 }
110118
119+ private void applyServerSslConfiguration () {
120+ try (ClientX509Util clientX509Util = new ClientX509Util ()) {
121+ copyServerSslProperty (clientX509Util .getSslProtocolProperty ());
122+ copyServerSslProperty (clientX509Util .getSslEnabledProtocolsProperty ());
123+ copyServerSslProperty (clientX509Util .getSslCipherSuitesProperty ());
124+ copyServerSslProperty (clientX509Util .getSslKeystoreLocationProperty ());
125+ copyServerSslProperty (clientX509Util .getSslKeystorePasswdProperty ());
126+ copyServerSslProperty (clientX509Util .getSslKeystorePasswdPathProperty ());
127+ copyServerSslProperty (clientX509Util .getSslKeystoreTypeProperty ());
128+ copyServerSslProperty (clientX509Util .getSslTruststoreLocationProperty ());
129+ copyServerSslProperty (clientX509Util .getSslTruststorePasswdProperty ());
130+ copyServerSslProperty (clientX509Util .getSslTruststorePasswdPathProperty ());
131+ copyServerSslProperty (clientX509Util .getSslTruststoreTypeProperty ());
132+ copyServerSslProperty (clientX509Util .getSslContextSupplierClassProperty ());
133+ copyServerSslProperty (clientX509Util .getSslHostnameVerificationEnabledProperty ());
134+ copyServerSslProperty (clientX509Util .getSslCrlEnabledProperty ());
135+ copyServerSslProperty (clientX509Util .getSslOcspEnabledProperty ());
136+ copyServerSslProperty (clientX509Util .getSslClientAuthProperty ());
137+ copyServerSslProperty (clientX509Util .getSslHandshakeDetectionTimeoutMillisProperty ());
138+ copyServerSslProperty (clientX509Util .getSslAuthProviderProperty ());
139+ }
140+ }
141+
142+ private void copyServerSslProperty (String clientProperty ) {
143+ if (clientProperty == null || getProperty (clientProperty ) != null ) {
144+ return ;
145+ }
146+ if (!clientProperty .startsWith (ZOOKEEPER_PREFIX )) {
147+ return ;
148+ }
149+ String serverProperty = clientProperty .substring (ZOOKEEPER_PREFIX .length ());
150+ String serverValue = getProperty (serverProperty );
151+ if (serverValue != null ) {
152+ setProperty (clientProperty , serverValue );
153+ }
154+ }
155+
111156 /**
112157 * Returns true if the SASL client is enabled. By default, the client is
113158 * enabled but can be disabled by setting the system property
0 commit comments