Skip to content

Commit b14b4a7

Browse files
authored
Remove obsolete constructor from SSLService (#50347)
This removes the old `SSLService(Settings, Environment)` constructor and converts all uses cases to the `SSLService(Environment)` constructor that was added in #49667
1 parent 0c0f455 commit b14b4a7

File tree

42 files changed

+216
-206
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+216
-206
lines changed

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ssl/SSLService.java

+16-15
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ public class SSLService {
100100
private static final Setting<Boolean> DIAGNOSE_TRUST_EXCEPTIONS_SETTING = Setting.boolSetting(
101101
"xpack.security.ssl.diagnose.trust", true, Setting.Property.NodeScope);
102102

103+
private final Environment env;
103104
private final Settings settings;
104105
private final boolean diagnoseTrustExceptions;
105106

@@ -120,33 +121,33 @@ public class SSLService {
120121
*/
121122
private final Map<SSLConfiguration, SSLContextHolder> sslContexts;
122123
private final SetOnce<SSLConfiguration> transportSSLConfiguration = new SetOnce<>();
123-
private final Environment env;
124124

125125
/**
126-
* Create a new SSLService using the {@code Settings} from {@link Environment#settings()}.
127-
* @see #SSLService(Settings, Environment)
126+
* Create a new SSLService that parses the settings for the ssl contexts that need to be created, creates them, and then caches them
127+
* for use later
128128
*/
129129
public SSLService(Environment environment) {
130-
this(environment.settings(), environment);
130+
this.env = environment;
131+
this.settings = env.settings();
132+
this.diagnoseTrustExceptions = DIAGNOSE_TRUST_EXCEPTIONS_SETTING.get(environment.settings());
133+
this.sslConfigurations = new HashMap<>();
134+
this.sslContexts = loadSSLConfigurations();
131135
}
132136

133-
/**
134-
* Create a new SSLService that parses the settings for the ssl contexts that need to be created, creates them, and then caches them
135-
* for use later
136-
*/
137+
@Deprecated
137138
public SSLService(Settings settings, Environment environment) {
138-
this.settings = settings;
139139
this.env = environment;
140+
this.settings = env.settings();
140141
this.diagnoseTrustExceptions = DIAGNOSE_TRUST_EXCEPTIONS_SETTING.get(settings);
141142
this.sslConfigurations = new HashMap<>();
142143
this.sslContexts = loadSSLConfigurations();
143144
}
144145

145-
private SSLService(Settings settings, Environment environment, Map<String, SSLConfiguration> sslConfigurations,
146+
private SSLService(Environment environment, Map<String, SSLConfiguration> sslConfigurations,
146147
Map<SSLConfiguration, SSLContextHolder> sslContexts) {
147-
this.settings = settings;
148148
this.env = environment;
149-
this.diagnoseTrustExceptions = DIAGNOSE_TRUST_EXCEPTIONS_SETTING.get(settings);
149+
this.settings = env.settings();
150+
this.diagnoseTrustExceptions = DIAGNOSE_TRUST_EXCEPTIONS_SETTING.get(environment.settings());
150151
this.sslConfigurations = sslConfigurations;
151152
this.sslContexts = sslContexts;
152153
}
@@ -157,7 +158,7 @@ private SSLService(Settings settings, Environment environment, Map<String, SSLCo
157158
* have been created during initialization
158159
*/
159160
public SSLService createDynamicSSLService() {
160-
return new SSLService(settings, env, sslConfigurations, sslContexts) {
161+
return new SSLService(env, sslConfigurations, sslContexts) {
161162

162163
@Override
163164
Map<SSLConfiguration, SSLContextHolder> loadSSLConfigurations() {
@@ -489,9 +490,9 @@ X509ExtendedTrustManager wrapWithDiagnostics(X509ExtendedTrustManager trustManag
489490
* Parses the settings to load all SSLConfiguration objects that will be used.
490491
*/
491492
Map<SSLConfiguration, SSLContextHolder> loadSSLConfigurations() {
492-
Map<SSLConfiguration, SSLContextHolder> sslContextHolders = new HashMap<>();
493+
final Map<SSLConfiguration, SSLContextHolder> sslContextHolders = new HashMap<>();
493494

494-
Map<String, Settings> sslSettingsMap = new HashMap<>();
495+
final Map<String, Settings> sslSettingsMap = new HashMap<>();
495496
sslSettingsMap.put(XPackSettings.HTTP_SSL_PREFIX, getHttpTransportSSLSettings(settings));
496497
sslSettingsMap.put("xpack.http.ssl", settings.getByPrefix("xpack.http.ssl."));
497498
sslSettingsMap.putAll(getRealmsSSLSettings(settings));

x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/security/transport/ProfileConfigurationsTests.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public void testGetSecureTransportProfileConfigurations() {
3030
.put("transport.profiles.cert.xpack.security.ssl.verification_mode", VerificationMode.CERTIFICATE.name())
3131
.build();
3232
final Environment env = TestEnvironment.newEnvironment(settings);
33-
SSLService sslService = new SSLService(settings, env);
33+
SSLService sslService = new SSLService(env);
3434
final SSLConfiguration defaultConfig = sslService.getSSLConfiguration("xpack.security.transport.ssl");
3535
final Map<String, SSLConfiguration> profileConfigurations = ProfileConfigurations.get(settings, sslService, defaultConfig);
3636
assertThat(profileConfigurations.size(), Matchers.equalTo(3));
@@ -48,7 +48,7 @@ public void testGetInsecureTransportProfileConfigurations() {
4848
.put("transport.profiles.none.xpack.security.ssl.verification_mode", VerificationMode.NONE.name())
4949
.build();
5050
final Environment env = TestEnvironment.newEnvironment(settings);
51-
SSLService sslService = new SSLService(settings, env);
51+
SSLService sslService = new SSLService(env);
5252
final SSLConfiguration defaultConfig = sslService.getSSLConfiguration("xpack.security.transport.ssl");
5353
final Map<String, SSLConfiguration> profileConfigurations = ProfileConfigurations.get(settings, sslService, defaultConfig);
5454
assertThat(profileConfigurations.size(), Matchers.equalTo(2));

x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ssl/SSLConfigurationReloaderTests.java

+12-11
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ public void testReloadingKeyStore() throws Exception {
147147
throw new RuntimeException("Exception starting or connecting to the mock server", e);
148148
}
149149
};
150-
validateSSLConfigurationIsReloaded(settings, env, keyMaterialPreChecks, modifier, keyMaterialPostChecks);
150+
validateSSLConfigurationIsReloaded(env, keyMaterialPreChecks, modifier, keyMaterialPostChecks);
151151
}
152152
}
153153
/**
@@ -174,7 +174,7 @@ public void testPEMKeyConfigReloading() throws Exception {
174174
.putList("xpack.security.transport.ssl.certificate_authorities", certPath.toString())
175175
.setSecureSettings(secureSettings)
176176
.build();
177-
final Environment env = newEnvironment();
177+
final Environment env = TestEnvironment.newEnvironment(settings);
178178
// Load HTTPClient once. Client uses a keystore containing testnode key/cert as a truststore
179179
try (CloseableHttpClient client = getSSLClient(Collections.singletonList(certPath))) {
180180
final Consumer<SSLContext> keyMaterialPreChecks = (context) -> {
@@ -207,7 +207,7 @@ public void testPEMKeyConfigReloading() throws Exception {
207207
throw new RuntimeException("Exception starting or connecting to the mock server", e);
208208
}
209209
};
210-
validateSSLConfigurationIsReloaded(settings, env, keyMaterialPreChecks, modifier, keyMaterialPostChecks);
210+
validateSSLConfigurationIsReloaded(env, keyMaterialPreChecks, modifier, keyMaterialPostChecks);
211211
}
212212
}
213213

@@ -259,7 +259,7 @@ public void testReloadingTrustStore() throws Exception {
259259
throw new RuntimeException("Error closing CloseableHttpClient", e);
260260
}
261261
};
262-
validateSSLConfigurationIsReloaded(settings, env, trustMaterialPreChecks, modifier, trustMaterialPostChecks);
262+
validateSSLConfigurationIsReloaded(env, trustMaterialPreChecks, modifier, trustMaterialPostChecks);
263263
}
264264
}
265265

@@ -309,7 +309,7 @@ public void testReloadingPEMTrustConfig() throws Exception {
309309
throw new RuntimeException("Error closing CloseableHttpClient", e);
310310
}
311311
};
312-
validateSSLConfigurationIsReloaded(settings, env, trustMaterialPreChecks, modifier, trustMaterialPostChecks);
312+
validateSSLConfigurationIsReloaded(env, trustMaterialPreChecks, modifier, trustMaterialPostChecks);
313313
}
314314
}
315315

@@ -331,7 +331,7 @@ public void testReloadingKeyStoreException() throws Exception {
331331
.put("path.home", createTempDir())
332332
.build();
333333
Environment env = TestEnvironment.newEnvironment(settings);
334-
final SSLService sslService = new SSLService(settings, env);
334+
final SSLService sslService = new SSLService(env);
335335
final SSLConfiguration config = sslService.getSSLConfiguration("xpack.security.transport.ssl.");
336336
final AtomicReference<Exception> exceptionRef = new AtomicReference<>();
337337
final CountDownLatch latch = new CountDownLatch(1);
@@ -353,6 +353,7 @@ void reloadSSLContext(SSLConfiguration configuration) {
353353

354354
// truncate the keystore
355355
try (OutputStream ignore = Files.newOutputStream(keystorePath, StandardOpenOption.TRUNCATE_EXISTING)) {
356+
// do nothing
356357
}
357358

358359
latch.await();
@@ -384,7 +385,7 @@ public void testReloadingPEMKeyConfigException() throws Exception {
384385
.setSecureSettings(secureSettings)
385386
.build();
386387
Environment env = TestEnvironment.newEnvironment(settings);
387-
final SSLService sslService = new SSLService(settings, env);
388+
final SSLService sslService = new SSLService(env);
388389
final SSLConfiguration config = sslService.getSSLConfiguration("xpack.security.transport.ssl.");
389390
final AtomicReference<Exception> exceptionRef = new AtomicReference<>();
390391
final CountDownLatch latch = new CountDownLatch(1);
@@ -430,7 +431,7 @@ public void testTrustStoreReloadException() throws Exception {
430431
.put("path.home", createTempDir())
431432
.build();
432433
Environment env = TestEnvironment.newEnvironment(settings);
433-
final SSLService sslService = new SSLService(settings, env);
434+
final SSLService sslService = new SSLService(env);
434435
final SSLConfiguration config = sslService.getSSLConfiguration("xpack.security.transport.ssl.");
435436
final AtomicReference<Exception> exceptionRef = new AtomicReference<>();
436437
final CountDownLatch latch = new CountDownLatch(1);
@@ -474,7 +475,7 @@ public void testPEMTrustReloadException() throws Exception {
474475
.put("path.home", createTempDir())
475476
.build();
476477
Environment env = TestEnvironment.newEnvironment(settings);
477-
final SSLService sslService = new SSLService(settings, env);
478+
final SSLService sslService = new SSLService(env);
478479
final SSLConfiguration config = sslService.sslConfiguration(settings.getByPrefix("xpack.security.transport.ssl."));
479480
final AtomicReference<Exception> exceptionRef = new AtomicReference<>();
480481
final CountDownLatch latch = new CountDownLatch(1);
@@ -524,10 +525,10 @@ private Settings.Builder baseKeystoreSettings(Path tempDir, MockSecureSettings s
524525
.setSecureSettings(secureSettings);
525526
}
526527

527-
private void validateSSLConfigurationIsReloaded(Settings settings, Environment env, Consumer<SSLContext> preChecks,
528+
private void validateSSLConfigurationIsReloaded(Environment env, Consumer<SSLContext> preChecks,
528529
Runnable modificationFunction, Consumer<SSLContext> postChecks) throws Exception {
529530
final CountDownLatch reloadLatch = new CountDownLatch(1);
530-
final SSLService sslService = new SSLService(settings, env);
531+
final SSLService sslService = new SSLService(env);
531532
final SSLConfiguration config = sslService.getSSLConfiguration("xpack.security.transport.ssl");
532533
new SSLConfigurationReloader(env, sslService, resourceWatcherService) {
533534
@Override

0 commit comments

Comments
 (0)