From f5864c7291bf2578bfbb36ec654af0c097bf81cf Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Wed, 4 Oct 2017 01:21:59 -0600 Subject: [PATCH] Move away from `Settings#getAsMap()` (elastic/x-pack-elasticsearch#2661) Relates to elastic/elasticsearch#26845 Original commit: elastic/x-pack-elasticsearch@0323ea07a57d4f401857a7b55bb4663b3ecc5359 --- .../xpack/notification/email/Account.java | 5 +++-- .../elasticsearch/xpack/security/Security.java | 12 +++++------- .../security/audit/index/IndexAuditTrail.java | 10 +++++----- .../ldap/AbstractAdLdapRealmTestCase.java | 8 ++------ .../integration/ldap/MultipleAdRealmTests.java | 8 ++++---- .../license/TribeTransportTestCase.java | 15 ++++++++------- .../monitoring/exporter/ExportersTests.java | 16 ++++++++-------- .../pagerduty/PagerDutyAccountsTests.java | 4 ++-- .../notification/slack/SlackAccountsTests.java | 4 ++-- .../xpack/security/SecurityTribeIT.java | 8 ++++---- .../audit/index/IndexAuditTrailTests.java | 2 +- .../ldap/LdapUserSearchSessionFactoryTests.java | 7 ++++--- .../authc/pki/PkiAuthenticationTests.java | 10 ++-------- .../netty4/IPHostnameVerificationTests.java | 10 +--------- .../netty4/SslHostnameVerificationTests.java | 13 ++----------- .../actions/jira/ExecutableJiraActionTests.java | 15 ++++++++------- .../OpenLdapUserSearchSessionFactoryTests.java | 4 +--- 17 files changed, 62 insertions(+), 89 deletions(-) diff --git a/plugin/src/main/java/org/elasticsearch/xpack/notification/email/Account.java b/plugin/src/main/java/org/elasticsearch/xpack/notification/email/Account.java index 8370a2ee90b..33321e31639 100644 --- a/plugin/src/main/java/org/elasticsearch/xpack/notification/email/Account.java +++ b/plugin/src/main/java/org/elasticsearch/xpack/notification/email/Account.java @@ -7,6 +7,7 @@ package org.elasticsearch.xpack.notification.email; import org.apache.logging.log4j.Logger; import org.elasticsearch.SpecialPermission; +import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.SettingsException; import org.elasticsearch.common.unit.TimeValue; @@ -237,8 +238,8 @@ public class Account { replace(builder, "use_rset", "userset"); settings = builder.build(); Properties props = new Properties(); - for (Map.Entry entry : settings.getAsMap().entrySet()) { - props.setProperty(SMTP_SETTINGS_PREFIX + entry.getKey(), entry.getValue()); + for (String key : settings.keySet()) { + props.setProperty(SMTP_SETTINGS_PREFIX + key, settings.get(key)); } return props; } diff --git a/plugin/src/main/java/org/elasticsearch/xpack/security/Security.java b/plugin/src/main/java/org/elasticsearch/xpack/security/Security.java index f1f10949e88..736cd77c088 100644 --- a/plugin/src/main/java/org/elasticsearch/xpack/security/Security.java +++ b/plugin/src/main/java/org/elasticsearch/xpack/security/Security.java @@ -212,7 +212,7 @@ public class Security implements ActionPlugin, IngestPlugin, NetworkPlugin, Clus static final Setting> AUDIT_OUTPUTS_SETTING = Setting.listSetting(setting("audit.outputs"), - s -> s.getAsMap().containsKey(setting("audit.outputs")) ? + s -> s.keySet().contains(setting("audit.outputs")) ? Collections.emptyList() : Collections.singletonList(LoggingAuditTrail.NAME), Function.identity(), Property.NodeScope); @@ -680,7 +680,6 @@ public class Security implements ActionPlugin, IngestPlugin, NetworkPlugin, Clus return; } - final Map settingsMap = settings.getAsMap(); for (Map.Entry tribeSettings : tribesSettings.entrySet()) { String tribePrefix = "tribe." + tribeSettings.getKey() + "."; @@ -701,12 +700,11 @@ public class Security implements ActionPlugin, IngestPlugin, NetworkPlugin, Clus } // we passed all the checks now we need to copy in all of the x-pack security settings - for (Map.Entry entry : settingsMap.entrySet()) { - String key = entry.getKey(); - if (key.startsWith("xpack.security.")) { - settingsBuilder.put(tribePrefix + key, entry.getValue()); + settings.keySet().forEach(k -> { + if (k.startsWith("xpack.security.")) { + settingsBuilder.copy(tribePrefix + k, k, settings); } - } + }); } Map realmsSettings = settings.getGroups(setting("authc.realms"), true); diff --git a/plugin/src/main/java/org/elasticsearch/xpack/security/audit/index/IndexAuditTrail.java b/plugin/src/main/java/org/elasticsearch/xpack/security/audit/index/IndexAuditTrail.java index 70403c5e258..78a686fd4a7 100644 --- a/plugin/src/main/java/org/elasticsearch/xpack/security/audit/index/IndexAuditTrail.java +++ b/plugin/src/main/java/org/elasticsearch/xpack/security/audit/index/IndexAuditTrail.java @@ -837,14 +837,14 @@ public class IndexAuditTrail extends AbstractComponent implements AuditTrail, Cl // Filter out forbidden settings: Settings.Builder builder = Settings.builder(); - for (Map.Entry entry : newSettings.getAsMap().entrySet()) { - String name = "index." + entry.getKey(); + builder.put(newSettings.filter(k -> { + String name = "index." + k; if (FORBIDDEN_INDEX_SETTING.equals(name)) { logger.warn("overriding the default [{}} setting is forbidden. ignoring...", name); - continue; + return false; } - builder.put(name, entry.getValue()); - } + return true; + })); return builder.build(); } diff --git a/plugin/src/test/java/org/elasticsearch/integration/ldap/AbstractAdLdapRealmTestCase.java b/plugin/src/test/java/org/elasticsearch/integration/ldap/AbstractAdLdapRealmTestCase.java index bb65bd543a8..a2c4815647a 100644 --- a/plugin/src/test/java/org/elasticsearch/integration/ldap/AbstractAdLdapRealmTestCase.java +++ b/plugin/src/test/java/org/elasticsearch/integration/ldap/AbstractAdLdapRealmTestCase.java @@ -103,7 +103,7 @@ public abstract class AbstractAdLdapRealmTestCase extends SecurityIntegTestCase roleMappings = realmConfig.selectRoleMappings(ESTestCase::randomBoolean); useGlobalSSL = randomBoolean(); ESLoggerFactory.getLogger("test").info("running test with realm configuration [{}], with direct group to role mapping [{}]. " + - "Settings [{}]", realmConfig, realmConfig.mapGroupsAsRoles, realmConfig.settings.getAsMap()); + "Settings [{}]", realmConfig, realmConfig.mapGroupsAsRoles, realmConfig.settings); } @AfterClass @@ -119,11 +119,7 @@ public abstract class AbstractAdLdapRealmTestCase extends SecurityIntegTestCase if (useGlobalSSL) { // don't use filter since it returns a prefixed secure setting instead of mock! Settings settingsToAdd = super.nodeSettings(nodeOrdinal); - for (Map.Entry settingsEntry : settingsToAdd.getAsMap().entrySet()) { - if (settingsEntry.getKey().startsWith("xpack.ssl.") == false) { - builder.put(settingsEntry.getKey(), settingsEntry.getValue()); - } - } + builder.put(settingsToAdd.filter(k -> k.startsWith("xpack.ssl.") == false), false); MockSecureSettings mockSecureSettings = (MockSecureSettings) Settings.builder().put(settingsToAdd).getSecureSettings(); if (mockSecureSettings != null) { MockSecureSettings filteredSecureSettings = new MockSecureSettings(); diff --git a/plugin/src/test/java/org/elasticsearch/integration/ldap/MultipleAdRealmTests.java b/plugin/src/test/java/org/elasticsearch/integration/ldap/MultipleAdRealmTests.java index 5592530ee69..f08aa74c4b9 100644 --- a/plugin/src/test/java/org/elasticsearch/integration/ldap/MultipleAdRealmTests.java +++ b/plugin/src/test/java/org/elasticsearch/integration/ldap/MultipleAdRealmTests.java @@ -36,7 +36,7 @@ public class MultipleAdRealmTests extends AbstractAdLdapRealmTestCase { secondaryRealmConfig = randomFrom(configs); ESLoggerFactory.getLogger("test") .info("running test with secondary realm configuration [{}], with direct group to role mapping [{}]. Settings [{}]", - secondaryRealmConfig, secondaryRealmConfig.mapGroupsAsRoles, secondaryRealmConfig.settings.getAsMap()); + secondaryRealmConfig, secondaryRealmConfig.mapGroupsAsRoles, secondaryRealmConfig.settings); // It's easier to test 2 realms when using file based role mapping, and for the purposes of // this test, there's no need to test native mappings. @@ -51,9 +51,9 @@ public class MultipleAdRealmTests extends AbstractAdLdapRealmTestCase { Path store = getDataPath(TESTNODE_KEYSTORE); final List secondaryRoleMappings = secondaryRealmConfig.selectRoleMappings(() -> true); final Settings secondarySettings = super.buildRealmSettings(secondaryRealmConfig, secondaryRoleMappings, store); - secondarySettings.getAsMap().forEach((name, value) -> { - name = name.replace(XPACK_SECURITY_AUTHC_REALMS_EXTERNAL, XPACK_SECURITY_AUTHC_REALMS_EXTERNAL + "2"); - builder.put(name, value); + secondarySettings.keySet().forEach(name -> { + String newName = name.replace(XPACK_SECURITY_AUTHC_REALMS_EXTERNAL, XPACK_SECURITY_AUTHC_REALMS_EXTERNAL + "2"); + builder.copy(newName, name, secondarySettings); }); return builder.build(); diff --git a/plugin/src/test/java/org/elasticsearch/license/TribeTransportTestCase.java b/plugin/src/test/java/org/elasticsearch/license/TribeTransportTestCase.java index ecb290e07c6..97b32db979f 100644 --- a/plugin/src/test/java/org/elasticsearch/license/TribeTransportTestCase.java +++ b/plugin/src/test/java/org/elasticsearch/license/TribeTransportTestCase.java @@ -160,16 +160,17 @@ public abstract class TribeTransportTestCase extends ESIntegTestCase { assertAcked(cluster2.client().admin().indices().prepareCreate("test2").get()); ensureYellow(internalCluster()); ensureYellow(cluster2); - Map asMap = internalCluster().getDefaultSettings().getAsMap(); +// Map asMap = internalCluster().getDefaultSettings().getAsMap(); Settings.Builder tribe1Defaults = Settings.builder(); Settings.Builder tribe2Defaults = Settings.builder(); - for (Map.Entry entry : asMap.entrySet()) { - if (entry.getKey().startsWith("path.")) { - continue; + internalCluster().getDefaultSettings().keySet().forEach(k -> { + if (k.startsWith("path.") == false) { + tribe1Defaults.copy(k, internalCluster().getDefaultSettings()); + tribe2Defaults.copy(k, internalCluster().getDefaultSettings()); } - tribe1Defaults.put("tribe.t1." + entry.getKey(), entry.getValue()); - tribe2Defaults.put("tribe.t2." + entry.getKey(), entry.getValue()); - } + }); + tribe1Defaults.normalizePrefix("tribe.t1."); + tribe2Defaults.normalizePrefix("tribe.t2."); // give each tribe it's unicast hosts to connect to tribe1Defaults.putArray("tribe.t1." + UnicastZenPing.DISCOVERY_ZEN_PING_UNICAST_HOSTS_SETTING.getKey(), getUnicastHosts(internalCluster().client())); diff --git a/plugin/src/test/java/org/elasticsearch/xpack/monitoring/exporter/ExportersTests.java b/plugin/src/test/java/org/elasticsearch/xpack/monitoring/exporter/ExportersTests.java index 004c1ef6ff1..3e4940eebb3 100644 --- a/plugin/src/test/java/org/elasticsearch/xpack/monitoring/exporter/ExportersTests.java +++ b/plugin/src/test/java/org/elasticsearch/xpack/monitoring/exporter/ExportersTests.java @@ -193,10 +193,10 @@ public class ExportersTests extends ESTestCase { exporters.start(); assertThat(settingsHolder.get(), notNullValue()); - Map settings = settingsHolder.get().getAsMap(); + Settings settings = settingsHolder.get(); assertThat(settings.size(), is(2)); - assertThat(settings, hasEntry("_name0.type", "_type")); - assertThat(settings, hasEntry("_name1.type", "_type")); + assertEquals(settings.get("_name0.type"), "_type"); + assertEquals(settings.get("_name1.type"), "_type"); Settings update = Settings.builder() .put("xpack.monitoring.exporters._name0.foo", "bar") @@ -204,12 +204,12 @@ public class ExportersTests extends ESTestCase { .build(); clusterSettings.applySettings(update); assertThat(settingsHolder.get(), notNullValue()); - settings = settingsHolder.get().getAsMap(); + settings = settingsHolder.get(); assertThat(settings.size(), is(4)); - assertThat(settings, hasEntry("_name0.type", "_type")); - assertThat(settings, hasEntry("_name0.foo", "bar")); - assertThat(settings, hasEntry("_name1.type", "_type")); - assertThat(settings, hasEntry("_name1.foo", "bar")); + assertEquals(settings.get("_name0.type"), "_type"); + assertEquals(settings.get("_name0.foo"), "bar"); + assertEquals(settings.get("_name1.type"), "_type"); + assertEquals(settings.get("_name1.foo"), "bar"); } public void testExporterBlocksOnClusterState() { diff --git a/plugin/src/test/java/org/elasticsearch/xpack/notification/pagerduty/PagerDutyAccountsTests.java b/plugin/src/test/java/org/elasticsearch/xpack/notification/pagerduty/PagerDutyAccountsTests.java index d9d7347d07f..7df40d99f06 100644 --- a/plugin/src/test/java/org/elasticsearch/xpack/notification/pagerduty/PagerDutyAccountsTests.java +++ b/plugin/src/test/java/org/elasticsearch/xpack/notification/pagerduty/PagerDutyAccountsTests.java @@ -154,8 +154,8 @@ public class PagerDutyAccountsTests extends ESTestCase { private void addAccountSettings(String name, Settings.Builder builder) { builder.put("xpack.notification.pagerduty.account." + name + ".service_api_key", randomAlphaOfLength(50)); Settings defaults = SlackMessageDefaultsTests.randomSettings(); - for (Map.Entry setting : defaults.getAsMap().entrySet()) { - builder.put("xpack.notification.pagerduty.message_defaults." + setting.getKey(), setting.getValue()); + for (String setting : defaults.keySet()) { + builder.copy("xpack.notification.pagerduty.message_defaults." + setting, setting, defaults); } } } diff --git a/plugin/src/test/java/org/elasticsearch/xpack/notification/slack/SlackAccountsTests.java b/plugin/src/test/java/org/elasticsearch/xpack/notification/slack/SlackAccountsTests.java index 9a1b6c9ea82..c0f82010a12 100644 --- a/plugin/src/test/java/org/elasticsearch/xpack/notification/slack/SlackAccountsTests.java +++ b/plugin/src/test/java/org/elasticsearch/xpack/notification/slack/SlackAccountsTests.java @@ -138,8 +138,8 @@ public class SlackAccountsTests extends ESTestCase { private void addAccountSettings(String name, Settings.Builder builder) { builder.put("xpack.notification.slack.account." + name + ".url", "https://hooks.slack.com/services/" + randomAlphaOfLength(50)); Settings defaults = SlackMessageDefaultsTests.randomSettings(); - for (Map.Entry setting : defaults.getAsMap().entrySet()) { - builder.put("xpack.notification.slack.message_defaults." + setting.getKey(), setting.getValue()); + for (String setting : defaults.keySet()) { + builder.copy("xpack.notification.slack.message_defaults." + setting, setting, defaults); } } } diff --git a/plugin/src/test/java/org/elasticsearch/xpack/security/SecurityTribeIT.java b/plugin/src/test/java/org/elasticsearch/xpack/security/SecurityTribeIT.java index d8099b5d3d1..9025befad16 100644 --- a/plugin/src/test/java/org/elasticsearch/xpack/security/SecurityTribeIT.java +++ b/plugin/src/test/java/org/elasticsearch/xpack/security/SecurityTribeIT.java @@ -238,10 +238,10 @@ public class SecurityTribeIT extends NativeRealmIntegTestCase { } return true; }); - for (Map.Entry entry : tribeSettings.getAsMap().entrySet()) { - tribe1Defaults.put("tribe.t1." + entry.getKey(), entry.getValue()); - tribe2Defaults.put("tribe.t2." + entry.getKey(), entry.getValue()); - } + tribe1Defaults.put(tribeSettings, false); + tribe1Defaults.normalizePrefix("tribe.t1."); + tribe2Defaults.put(tribeSettings, false); + tribe2Defaults.normalizePrefix("tribe.t2."); // TODO: rethink how these settings are generated for tribes once we support more than just string settings... MockSecureSettings secureSettingsTemplate = (MockSecureSettings) Settings.builder().put(settingsTemplate).getSecureSettings(); diff --git a/plugin/src/test/java/org/elasticsearch/xpack/security/audit/index/IndexAuditTrailTests.java b/plugin/src/test/java/org/elasticsearch/xpack/security/audit/index/IndexAuditTrailTests.java index 9e02a902780..8667145ce57 100644 --- a/plugin/src/test/java/org/elasticsearch/xpack/security/audit/index/IndexAuditTrailTests.java +++ b/plugin/src/test/java/org/elasticsearch/xpack/security/audit/index/IndexAuditTrailTests.java @@ -290,7 +290,7 @@ public class IndexAuditTrailTests extends SecurityIntegTestCase { } Settings settings = builder.put(settings(rollover, includes, excludes)).build(); - logger.info("--> settings: [{}]", settings.getAsMap().toString()); + logger.info("--> settings: [{}]", settings); DiscoveryNode localNode = mock(DiscoveryNode.class); when(localNode.getHostAddress()).thenReturn(remoteAddress.getAddress()); when(localNode.getHostName()).thenReturn(remoteAddress.getAddress()); diff --git a/plugin/src/test/java/org/elasticsearch/xpack/security/authc/ldap/LdapUserSearchSessionFactoryTests.java b/plugin/src/test/java/org/elasticsearch/xpack/security/authc/ldap/LdapUserSearchSessionFactoryTests.java index 5400e6b7fdd..692eed28469 100644 --- a/plugin/src/test/java/org/elasticsearch/xpack/security/authc/ldap/LdapUserSearchSessionFactoryTests.java +++ b/plugin/src/test/java/org/elasticsearch/xpack/security/authc/ldap/LdapUserSearchSessionFactoryTests.java @@ -397,9 +397,10 @@ public class LdapUserSearchSessionFactoryTests extends LdapTestCase { .build(); Settings.Builder builder = Settings.builder() .put(globalSettings); - for (Map.Entry entry : settings.getAsMap().entrySet()) { - builder.put("xpack.security.authc.realms.ldap." + entry.getKey(), entry.getValue()); - } + settings.keySet().forEach(k -> { + builder.copy("xpack.security.authc.realms.ldap." + k, k, settings); + + }); Settings fullSettings = builder.build(); sslService = new SSLService(fullSettings, new Environment(fullSettings)); RealmConfig config = new RealmConfig("ad-as-ldap-test", settings, globalSettings, new Environment(globalSettings), new ThreadContext(globalSettings)); diff --git a/plugin/src/test/java/org/elasticsearch/xpack/security/authc/pki/PkiAuthenticationTests.java b/plugin/src/test/java/org/elasticsearch/xpack/security/authc/pki/PkiAuthenticationTests.java index 2f9ca0b2532..5186fba3b86 100644 --- a/plugin/src/test/java/org/elasticsearch/xpack/security/authc/pki/PkiAuthenticationTests.java +++ b/plugin/src/test/java/org/elasticsearch/xpack/security/authc/pki/PkiAuthenticationTests.java @@ -144,16 +144,10 @@ public class PkiAuthenticationTests extends SecurityIntegTestCase { private TransportClient createTransportClient(Settings additionalSettings) { Settings clientSettings = transportClientSettings(); if (additionalSettings.getByPrefix("xpack.ssl.").isEmpty() == false) { - Settings.Builder builder = Settings.builder(); - for (Entry entry : clientSettings.getAsMap().entrySet()) { - if (entry.getKey().startsWith("xpack.ssl.") == false) { - builder.put(entry.getKey(), entry.getValue()); - } - } - clientSettings = builder.build(); + clientSettings = clientSettings.filter(k -> k.startsWith("xpack.ssl.") == false); } - Settings.Builder builder = Settings.builder().put(clientSettings) + Settings.Builder builder = Settings.builder().put(clientSettings, false) .put(additionalSettings) .put("cluster.name", internalCluster().getClusterName()); builder.remove(Security.USER_SETTING.getKey()); diff --git a/plugin/src/test/java/org/elasticsearch/xpack/security/transport/netty4/IPHostnameVerificationTests.java b/plugin/src/test/java/org/elasticsearch/xpack/security/transport/netty4/IPHostnameVerificationTests.java index 8b859d12a91..e4af558798a 100644 --- a/plugin/src/test/java/org/elasticsearch/xpack/security/transport/netty4/IPHostnameVerificationTests.java +++ b/plugin/src/test/java/org/elasticsearch/xpack/security/transport/netty4/IPHostnameVerificationTests.java @@ -69,15 +69,7 @@ public class IPHostnameVerificationTests extends SecurityIntegTestCase { @Override protected Settings transportClientSettings() { Settings clientSettings = super.transportClientSettings(); - Settings.Builder builder = Settings.builder(); - for (Entry entry : clientSettings.getAsMap().entrySet()) { - if (entry.getKey().startsWith("xpack.ssl.") == false) { - builder.put(entry.getKey(), entry.getValue()); - } - } - clientSettings = builder.build(); - - return Settings.builder().put(clientSettings) + return Settings.builder().put(clientSettings.filter(k -> k.startsWith("xpack.ssl.") == false)) .put("xpack.ssl.verification_mode", "certificate") .put("xpack.ssl.keystore.path", keystore.toAbsolutePath()) .put("xpack.ssl.keystore.password", "testnode-ip-only") diff --git a/plugin/src/test/java/org/elasticsearch/xpack/security/transport/netty4/SslHostnameVerificationTests.java b/plugin/src/test/java/org/elasticsearch/xpack/security/transport/netty4/SslHostnameVerificationTests.java index 98abdf787a5..8ad668cd60d 100644 --- a/plugin/src/test/java/org/elasticsearch/xpack/security/transport/netty4/SslHostnameVerificationTests.java +++ b/plugin/src/test/java/org/elasticsearch/xpack/security/transport/netty4/SslHostnameVerificationTests.java @@ -35,11 +35,7 @@ public class SslHostnameVerificationTests extends SecurityIntegTestCase { protected Settings nodeSettings(int nodeOrdinal) { Settings settings = super.nodeSettings(nodeOrdinal); Settings.Builder settingsBuilder = Settings.builder(); - for (Entry entry : settings.getAsMap().entrySet()) { - if (entry.getKey().startsWith("xpack.ssl.") == false) { - settingsBuilder.put(entry.getKey(), entry.getValue()); - } - } + settingsBuilder.put(settings.filter(k -> k.startsWith("xpack.ssl.") == false), false); Path keystore; try { /* @@ -71,12 +67,7 @@ public class SslHostnameVerificationTests extends SecurityIntegTestCase { Settings settings = super.transportClientSettings(); // remove all ssl settings Settings.Builder builder = Settings.builder(); - for (Entry entry : settings.getAsMap().entrySet()) { - String key = entry.getKey(); - if (key.startsWith("xpack.ssl.") == false) { - builder.put(key, entry.getValue()); - } - } + builder.put(settings.filter( k -> k.startsWith("xpack.ssl.") == false), false); builder.put("xpack.ssl.verification_mode", "certificate") .put("xpack.ssl.keystore.path", keystore.toAbsolutePath()) // settings for client keystore diff --git a/plugin/src/test/java/org/elasticsearch/xpack/watcher/actions/jira/ExecutableJiraActionTests.java b/plugin/src/test/java/org/elasticsearch/xpack/watcher/actions/jira/ExecutableJiraActionTests.java index 2d8de064305..6ed2ac40a41 100644 --- a/plugin/src/test/java/org/elasticsearch/xpack/watcher/actions/jira/ExecutableJiraActionTests.java +++ b/plugin/src/test/java/org/elasticsearch/xpack/watcher/actions/jira/ExecutableJiraActionTests.java @@ -32,6 +32,8 @@ import java.util.Collections; import java.util.HashMap; import java.util.Locale; import java.util.Map; +import java.util.function.Function; +import java.util.stream.Collectors; import static java.util.Collections.emptyMap; import static java.util.Collections.singletonMap; @@ -223,11 +225,11 @@ public class ExecutableJiraActionTests extends ESTestCase { } public void testExecutionFieldsStringArrays() throws Exception { - Map defaults = Settings.builder() + Settings build = Settings.builder() .putArray("k0", "a", "b", "c") .put("k1", "v1") - .build() - .getAsMap(); + .build(); + Map defaults = build.keySet().stream().collect(Collectors.toMap(Function.identity(), k -> build.get(k))); Map fields = new HashMap<>(); fields.put("k2", "v2"); @@ -241,11 +243,10 @@ public class ExecutableJiraActionTests extends ESTestCase { } public void testExecutionFieldsStringArraysNotOverridden() throws Exception { - Map defaults = Settings.builder() + Settings build = Settings.builder() .putArray("k0", "a", "b", "c") - .build() - .getAsMap(); - + .build(); + Map defaults = build.keySet().stream().collect(Collectors.toMap(Function.identity(), k -> build.get(k))); Map fields = new HashMap<>(); fields.put("k1", "v1"); fields.put("k0", new String[]{"d", "e", "f"}); // should not be overridden byt the defaults diff --git a/qa/openldap-tests/src/test/java/org/elasticsearch/xpack/security/authc/ldap/OpenLdapUserSearchSessionFactoryTests.java b/qa/openldap-tests/src/test/java/org/elasticsearch/xpack/security/authc/ldap/OpenLdapUserSearchSessionFactoryTests.java index b5637db8553..07a2894dd18 100644 --- a/qa/openldap-tests/src/test/java/org/elasticsearch/xpack/security/authc/ldap/OpenLdapUserSearchSessionFactoryTests.java +++ b/qa/openldap-tests/src/test/java/org/elasticsearch/xpack/security/authc/ldap/OpenLdapUserSearchSessionFactoryTests.java @@ -69,9 +69,7 @@ public class OpenLdapUserSearchSessionFactoryTests extends ESTestCase { .build(), globalSettings, new Environment(globalSettings), new ThreadContext(globalSettings)); Settings.Builder builder = Settings.builder() .put(globalSettings); - for (Map.Entry entry : config.settings().getAsMap().entrySet()) { - builder.put("xpack.security.authc.realms.ldap." + entry.getKey(), entry.getValue()); - } + builder.put(Settings.builder().put(config.settings()).normalizePrefix("xpack.security.authc.realms.ldap.").build()); Settings settings = builder.build(); SSLService sslService = new SSLService(settings, new Environment(settings));