2525import java .io .InputStreamReader ;
2626import java .io .Reader ;
2727import java .nio .charset .StandardCharsets ;
28- import java .util .List ;
2928import java .util .Properties ;
3029
31- import com .netflix .config .ConcurrentCompositeConfiguration ;
32- import com .netflix .config .DynamicPropertyFactory ;
30+ import org .springframework .core .env .Environment ;
3331
3432/**
3533 * SSL配置选项。
@@ -263,20 +261,10 @@ private static String listToString(Object[] lists) {
263261 return sb .toString ();
264262 }
265263
266- public static String getStringProperty (ConcurrentCompositeConfiguration configSource , String defaultValue ,
267- String ... keys ) {
264+ public static String getStringProperty (Environment environment , String defaultValue , String ... keys ) {
268265 String property = null ;
269266 for (String key : keys ) {
270- if (configSource != null ) {
271- Object v = configSource .getProperty (key );
272- if (v instanceof List ) {
273- property = listToString (((List <?>) v ).toArray ());
274- } else {
275- property = (String ) configSource .getProperty (key );
276- }
277- } else {
278- property = DynamicPropertyFactory .getInstance ().getStringProperty (key , null ).get ();
279- }
267+ property = environment .getProperty (key );
280268 if (property != null ) {
281269 break ;
282270 }
@@ -289,17 +277,10 @@ public static String getStringProperty(ConcurrentCompositeConfiguration configSo
289277 }
290278 }
291279
292- private static boolean getBooleanProperty (ConcurrentCompositeConfiguration configSource , boolean defaultValue ,
293- String ... keys ) {
280+ private static boolean getBooleanProperty (Environment environment , boolean defaultValue , String ... keys ) {
294281 String property = null ;
295282 for (String key : keys ) {
296- if (configSource != null ) {
297- if (configSource .getProperty (key ) != null ) {
298- return configSource .getBoolean (key );
299- }
300- } else {
301- property = DynamicPropertyFactory .getInstance ().getStringProperty (key , null ).get ();
302- }
283+ property = environment .getProperty (key );
303284 if (property != null ) {
304285 break ;
305286 }
@@ -312,83 +293,79 @@ private static boolean getBooleanProperty(ConcurrentCompositeConfiguration confi
312293 }
313294 }
314295
315- public static SSLOption buildFromYaml (String tag , ConcurrentCompositeConfiguration configSource ) {
296+ public static SSLOption buildFromYaml (String tag , Environment environment ) {
316297 SSLOption option = new SSLOption ();
317- option .engine = getStringProperty (configSource ,
298+ option .engine = getStringProperty (environment ,
318299 DEFAULT_OPTION .getEngine (),
319300 "ssl." + tag + ".engine" ,
320301 "ssl.engine" );
321302 option .protocols =
322- getStringProperty (configSource ,
303+ getStringProperty (environment ,
323304 DEFAULT_OPTION .getProtocols (),
324305 "ssl." + tag + ".protocols" ,
325306 "ssl.protocols" );
326307 option .ciphers =
327- getStringProperty (configSource , DEFAULT_OPTION .getCiphers (), "ssl." + tag + ".ciphers" , "ssl.ciphers" );
308+ getStringProperty (environment , DEFAULT_OPTION .getCiphers (), "ssl." + tag + ".ciphers" , "ssl.ciphers" );
328309 option .authPeer =
329- getBooleanProperty (configSource , DEFAULT_OPTION .isAuthPeer (), "ssl." + tag + ".authPeer" , "ssl.authPeer" );
310+ getBooleanProperty (environment , DEFAULT_OPTION .isAuthPeer (), "ssl." + tag + ".authPeer" , "ssl.authPeer" );
330311 option .checkCNHost =
331- getBooleanProperty (configSource ,
312+ getBooleanProperty (environment ,
332313 DEFAULT_OPTION .isCheckCNHost (),
333314 "ssl." + tag + ".checkCN.host" ,
334315 "ssl.checkCN.host" );
335316 option .checkCNWhite =
336- getBooleanProperty (configSource ,
317+ getBooleanProperty (environment ,
337318 DEFAULT_OPTION .isCheckCNWhite (),
338319 "ssl." + tag + ".checkCN.white" ,
339320 "ssl.checkCN.white" );
340- option .checkCNWhiteFile = getStringProperty (configSource ,
321+ option .checkCNWhiteFile = getStringProperty (environment ,
341322 DEFAULT_OPTION .getCiphers (),
342323 "ssl." + tag + ".checkCN.white.file" ,
343324 "ssl.checkCN.white.file" );
344- option .allowRenegociate = getBooleanProperty (configSource ,
325+ option .allowRenegociate = getBooleanProperty (environment ,
345326 DEFAULT_OPTION .isAllowRenegociate (),
346327 "ssl." + tag + ".allowRenegociate" ,
347328 "ssl.allowRenegociate" );
348329 option .storePath =
349- getStringProperty (configSource ,
330+ getStringProperty (environment ,
350331 DEFAULT_OPTION .getStorePath (),
351332 "ssl." + tag + ".storePath" ,
352333 "ssl.storePath" );
353334 option .clientAuth =
354- getStringProperty (configSource ,
335+ getStringProperty (environment ,
355336 DEFAULT_OPTION .getClientAuth (),
356337 "ssl." + tag + ".storePath" ,
357338 "ssl.clientAuth" );
358339 option .trustStore =
359- getStringProperty (configSource ,
340+ getStringProperty (environment ,
360341 DEFAULT_OPTION .getTrustStore (),
361342 "ssl." + tag + ".trustStore" ,
362343 "ssl.trustStore" );
363- option .trustStoreType = getStringProperty (configSource ,
344+ option .trustStoreType = getStringProperty (environment ,
364345 DEFAULT_OPTION .getTrustStoreType (),
365346 "ssl." + tag + ".trustStoreType" ,
366347 "ssl.trustStoreType" );
367- option .trustStoreValue = getStringProperty (configSource ,
348+ option .trustStoreValue = getStringProperty (environment ,
368349 DEFAULT_OPTION .getTrustStoreValue (),
369350 "ssl." + tag + ".trustStoreValue" ,
370351 "ssl.trustStoreValue" );
371352 option .keyStore =
372- getStringProperty (configSource , DEFAULT_OPTION .getKeyStore (), "ssl." + tag + ".keyStore" , "ssl.keyStore" );
353+ getStringProperty (environment , DEFAULT_OPTION .getKeyStore (), "ssl." + tag + ".keyStore" , "ssl.keyStore" );
373354 option .keyStoreType =
374- getStringProperty (configSource ,
355+ getStringProperty (environment ,
375356 DEFAULT_OPTION .getKeyStoreType (),
376357 "ssl." + tag + ".keyStoreType" ,
377358 "ssl.keyStoreType" );
378- option .keyStoreValue = getStringProperty (configSource ,
359+ option .keyStoreValue = getStringProperty (environment ,
379360 DEFAULT_OPTION .getKeyStoreValue (),
380361 "ssl." + tag + ".keyStoreValue" ,
381362 "ssl.keyStoreValue" );
382- option .crl = getStringProperty (configSource , DEFAULT_OPTION .getCrl (), "ssl." + tag + ".crl" , "ssl.crl" );
363+ option .crl = getStringProperty (environment , DEFAULT_OPTION .getCrl (), "ssl." + tag + ".crl" , "ssl.crl" );
383364 option .sslCustomClass =
384- getStringProperty (configSource , null , "ssl." + tag + ".sslCustomClass" , "ssl.sslCustomClass" );
365+ getStringProperty (environment , null , "ssl." + tag + ".sslCustomClass" , "ssl.sslCustomClass" );
385366 return option ;
386367 }
387368
388- public static SSLOption buildFromYaml (String tag ) {
389- return buildFromYaml (tag , null );
390- }
391-
392369 private void fromProperty (Properties props ) {
393370 this .protocols = propString (props , "ssl.protocols" );
394371 this .ciphers = propString (props , "ssl.ciphers" );
0 commit comments