diff --git a/plugin/src/main/java/org/elasticsearch/xpack/XPackSettings.java b/plugin/src/main/java/org/elasticsearch/xpack/XPackSettings.java index b55a3fb59a0..b6467b29073 100644 --- a/plugin/src/main/java/org/elasticsearch/xpack/XPackSettings.java +++ b/plugin/src/main/java/org/elasticsearch/xpack/XPackSettings.java @@ -8,7 +8,6 @@ package org.elasticsearch.xpack; import org.elasticsearch.common.Booleans; import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Setting.Property; -import org.elasticsearch.common.settings.Settings; import org.elasticsearch.xpack.security.Security; import org.elasticsearch.xpack.ssl.SSLClientAuth; import org.elasticsearch.xpack.ssl.SSLConfigurationSettings; @@ -18,47 +17,48 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; -import java.util.function.Function; /** * A container for xpack setting constants. */ public class XPackSettings { - /** All setting constants created in this class. */ - private static final List> ALL_SETTINGS = new ArrayList<>(); - /** Setting for enabling or disabling security. Defaults to true. */ - public static final Setting SECURITY_ENABLED = enabledSetting(XPackPlugin.SECURITY, true); + public static final Setting SECURITY_ENABLED = Setting.boolSetting("xpack.security.enabled", true, Setting.Property.NodeScope); /** Setting for enabling or disabling monitoring. Defaults to true if not a tribe node. */ - public static final Setting MONITORING_ENABLED = enabledSetting(XPackPlugin.MONITORING, - // By default, monitoring is disabled on tribe nodes - s -> String.valueOf(XPackPlugin.isTribeNode(s) == false && XPackPlugin.isTribeClientNode(s) == false)); + public static final Setting MONITORING_ENABLED = Setting.boolSetting("xpack.monitoring.enabled", + // By default, monitoring is disabled on tribe nodes + s -> String.valueOf(XPackPlugin.isTribeNode(s) == false && XPackPlugin.isTribeClientNode(s) == false), + Setting.Property.NodeScope); /** Setting for enabling or disabling watcher. Defaults to true. */ - public static final Setting WATCHER_ENABLED = enabledSetting(XPackPlugin.WATCHER, true); + public static final Setting WATCHER_ENABLED = Setting.boolSetting("xpack.watcher.enabled", true, Setting.Property.NodeScope); /** Setting for enabling or disabling graph. Defaults to true. */ - public static final Setting GRAPH_ENABLED = enabledSetting(XPackPlugin.GRAPH, true); + public static final Setting GRAPH_ENABLED = Setting.boolSetting("xpack.graph.enabled", true, Setting.Property.NodeScope); /** Setting for enabling or disabling machine learning. Defaults to false. */ - public static final Setting MACHINE_LEARNING_ENABLED = enabledSetting(XPackPlugin.MACHINE_LEARNING, true); + public static final Setting MACHINE_LEARNING_ENABLED = Setting.boolSetting("xpack.ml.enabled", true, + Setting.Property.NodeScope); /** Setting for enabling or disabling auditing. Defaults to false. */ - public static final Setting AUDIT_ENABLED = enabledSetting(XPackPlugin.SECURITY + ".audit", false); + public static final Setting AUDIT_ENABLED = Setting.boolSetting("xpack.security.audit.enabled", false, + Setting.Property.NodeScope); /** Setting for enabling or disabling document/field level security. Defaults to true. */ - public static final Setting DLS_FLS_ENABLED = enabledSetting(XPackPlugin.SECURITY + ".dls_fls", true); + public static final Setting DLS_FLS_ENABLED = Setting.boolSetting("xpack.security.dls_fls.enabled", true, + Setting.Property.NodeScope); /** Setting for enabling or disabling Logstash extensions. Defaults to true. */ - public static final Setting LOGSTASH_ENABLED = enabledSetting(XPackPlugin.LOGSTASH, true); + public static final Setting LOGSTASH_ENABLED = Setting.boolSetting("xpack.logstash.enabled", true, + Setting.Property.NodeScope); /** * Legacy setting for enabling or disabling transport ssl. Defaults to true. This is just here to make upgrading easier since the * user needs to set this setting in 5.x to upgrade */ private static final Setting TRANSPORT_SSL_ENABLED = - new Setting<>(XPackPlugin.featureSettingPrefix(XPackPlugin.SECURITY) + ".transport.ssl.enabled", (s) -> Boolean.toString(true), + new Setting<>("xpack.security.transport.ssl.enabled", (s) -> Boolean.toString(true), (s) -> { final boolean parsed = Booleans.parseBoolean(s); if (parsed == false) { @@ -69,14 +69,16 @@ public class XPackSettings { }, Property.NodeScope, Property.Deprecated); /** Setting for enabling or disabling http ssl. Defaults to false. */ - public static final Setting HTTP_SSL_ENABLED = enabledSetting(XPackPlugin.SECURITY + ".http.ssl", false); + public static final Setting HTTP_SSL_ENABLED = Setting.boolSetting("xpack.security.http.ssl.enabled", false, + Setting.Property.NodeScope); /** Setting for enabling or disabling the reserved realm. Defaults to true */ - public static final Setting RESERVED_REALM_ENABLED_SETTING = - enabledSetting(XPackPlugin.SECURITY + ".authc.reserved_realm", true); + public static final Setting RESERVED_REALM_ENABLED_SETTING = Setting.boolSetting("xpack.security.authc.reserved_realm.enabled", + true, Setting.Property.NodeScope); /** Setting for enabling or disabling the token service. Defaults to true */ - public static final Setting TOKEN_SERVICE_ENABLED_SETTING = enabledSetting("security.authc.token", true); + public static final Setting TOKEN_SERVICE_ENABLED_SETTING = Setting.boolSetting("xpack.security.authc.token.enabled", true, + Setting.Property.NodeScope); /* * SSL settings. These are the settings that are specifically registered for SSL. Many are private as we do not explicitly use them @@ -103,49 +105,24 @@ public class XPackSettings { public static final String TRANSPORT_SSL_PREFIX = Security.setting("transport.ssl."); private static final SSLConfigurationSettings TRANSPORT_SSL = SSLConfigurationSettings.withPrefix(TRANSPORT_SSL_PREFIX); - /* End SSL settings */ - - static { - ALL_SETTINGS.addAll(GLOBAL_SSL.getAllSettings()); - ALL_SETTINGS.addAll(HTTP_SSL.getAllSettings()); - ALL_SETTINGS.addAll(TRANSPORT_SSL.getAllSettings()); - ALL_SETTINGS.add(TRANSPORT_SSL_ENABLED); - } - - /** - * Create a Setting for the enabled state of features in xpack. - * - * The given feature by be enabled or disabled with: - * {@code "xpack..enabled": true | false} - * - * For backward compatibility with 1.x and 2.x, the following also works: - * {@code ".enabled": true | false} - * - * @param featureName The name of the feature in xpack - * @param defaultValue True if the feature should be enabled by defualt, false otherwise - */ - private static Setting enabledSetting(String featureName, boolean defaultValue) { - return enabledSetting(featureName, s -> String.valueOf(defaultValue)); - } - - /** - * Create a setting for the enabled state of a feature, with a complex default value. - * @param featureName The name of the feature in xpack - * @param defaultValueFn A function to determine the default value based on the existing settings - * @see #enabledSetting(String,boolean) - */ - private static Setting enabledSetting(String featureName, Function defaultValueFn) { - String fallbackName = featureName + ".enabled"; - Setting fallback = Setting.boolSetting(fallbackName, defaultValueFn, - Setting.Property.NodeScope, Setting.Property.Deprecated); - String settingName = XPackPlugin.featureSettingPrefix(featureName) + ".enabled"; - Setting setting = Setting.boolSetting(settingName, fallback, Setting.Property.NodeScope); - ALL_SETTINGS.add(setting); - return setting; - } - /** Returns all settings created in {@link XPackSettings}. */ static List> getAllSettings() { - return Collections.unmodifiableList(ALL_SETTINGS); + ArrayList> settings = new ArrayList<>(); + settings.addAll(GLOBAL_SSL.getAllSettings()); + settings.addAll(HTTP_SSL.getAllSettings()); + settings.addAll(TRANSPORT_SSL.getAllSettings()); + settings.add(SECURITY_ENABLED); + settings.add(MONITORING_ENABLED); + settings.add(GRAPH_ENABLED); + settings.add(MACHINE_LEARNING_ENABLED); + settings.add(AUDIT_ENABLED); + settings.add(WATCHER_ENABLED); + settings.add(DLS_FLS_ENABLED); + settings.add(LOGSTASH_ENABLED); + settings.add(TRANSPORT_SSL_ENABLED); + settings.add(HTTP_SSL_ENABLED); + settings.add(RESERVED_REALM_ENABLED_SETTING); + settings.add(TOKEN_SERVICE_ENABLED_SETTING); + return Collections.unmodifiableList(settings); } }