Merge pull request elastic/elasticsearch#3069 from rjernst/deguice18

Consolidate settings for enabling xpack features

Original commit: elastic/x-pack-elasticsearch@bdc505dc6b
This commit is contained in:
Ryan Ernst 2016-08-09 16:31:06 -07:00 committed by GitHub
commit 20041446f3
54 changed files with 321 additions and 344 deletions

View File

@ -7,15 +7,14 @@ package org.elasticsearch.xpack.graph;
import org.elasticsearch.action.ActionRequest; import org.elasticsearch.action.ActionRequest;
import org.elasticsearch.action.ActionResponse; import org.elasticsearch.action.ActionResponse;
import org.elasticsearch.common.component.LifecycleComponent;
import org.elasticsearch.common.inject.Module; import org.elasticsearch.common.inject.Module;
import org.elasticsearch.common.inject.util.Providers;
import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Setting;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.plugins.ActionPlugin; import org.elasticsearch.plugins.ActionPlugin;
import org.elasticsearch.plugins.Plugin; import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.rest.RestHandler; import org.elasticsearch.rest.RestHandler;
import org.elasticsearch.xpack.XPackPlugin; import org.elasticsearch.xpack.XPackPlugin;
import org.elasticsearch.xpack.XPackSettings;
import org.elasticsearch.xpack.graph.action.GraphExploreAction; import org.elasticsearch.xpack.graph.action.GraphExploreAction;
import org.elasticsearch.xpack.graph.action.TransportGraphExploreAction; import org.elasticsearch.xpack.graph.action.TransportGraphExploreAction;
import org.elasticsearch.xpack.graph.rest.action.RestGraphAction; import org.elasticsearch.xpack.graph.rest.action.RestGraphAction;
@ -30,17 +29,11 @@ import static java.util.Collections.singletonList;
public class Graph extends Plugin implements ActionPlugin { public class Graph extends Plugin implements ActionPlugin {
public static final String NAME = "graph"; public static final String NAME = "graph";
private final boolean transportClientMode;
protected final boolean enabled; protected final boolean enabled;
public Graph(Settings settings) { public Graph(Settings settings) {
this.transportClientMode = XPackPlugin.transportClientMode(settings); this.enabled = XPackSettings.GRAPH_ENABLED.get(settings);
enabled = enabled(settings);
}
public static boolean enabled(Settings settings) {
return XPackPlugin.featureEnabled(settings, NAME, true);
} }
public Collection<Module> createGuiceModules() { public Collection<Module> createGuiceModules() {
@ -64,10 +57,4 @@ public class Graph extends Plugin implements ActionPlugin {
} }
return singletonList(RestGraphAction.class); return singletonList(RestGraphAction.class);
} }
@Override
public List<Setting<?>> getSettings() {
return Collections.singletonList(Setting.boolSetting(XPackPlugin.featureEnabledSetting(NAME), true, Setting.Property.NodeScope));
}
} }

View File

@ -13,6 +13,8 @@ import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.license.XPackLicenseState;
import org.elasticsearch.xpack.XPackFeatureSet; import org.elasticsearch.xpack.XPackFeatureSet;
import org.elasticsearch.xpack.XPackPlugin;
import org.elasticsearch.xpack.XPackSettings;
/** /**
* *
@ -24,13 +26,13 @@ public class GraphFeatureSet implements XPackFeatureSet {
@Inject @Inject
public GraphFeatureSet(Settings settings, @Nullable XPackLicenseState licenseState) { public GraphFeatureSet(Settings settings, @Nullable XPackLicenseState licenseState) {
this.enabled = Graph.enabled(settings); this.enabled = XPackSettings.GRAPH_ENABLED.get(settings);
this.licenseState = licenseState; this.licenseState = licenseState;
} }
@Override @Override
public String name() { public String name() {
return Graph.NAME; return XPackPlugin.GRAPH;
} }
@Override @Override
@ -60,7 +62,7 @@ public class GraphFeatureSet implements XPackFeatureSet {
} }
public Usage(boolean available, boolean enabled) { public Usage(boolean available, boolean enabled) {
super(Graph.NAME, available, enabled); super(XPackPlugin.GRAPH, available, enabled);
} }
} }
} }

View File

@ -38,6 +38,7 @@ import org.elasticsearch.search.aggregations.bucket.terms.support.IncludeExclude
import org.elasticsearch.search.builder.SearchSourceBuilder; import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.TransportService; import org.elasticsearch.transport.TransportService;
import org.elasticsearch.xpack.XPackPlugin;
import org.elasticsearch.xpack.graph.Graph; import org.elasticsearch.xpack.graph.Graph;
import org.elasticsearch.xpack.graph.action.Connection.ConnectionId; import org.elasticsearch.xpack.graph.action.Connection.ConnectionId;
import org.elasticsearch.xpack.graph.action.GraphExploreRequest.TermBoost; import org.elasticsearch.xpack.graph.action.GraphExploreRequest.TermBoost;
@ -89,7 +90,7 @@ public class TransportGraphExploreAction extends HandledTransportAction<GraphExp
if (licenseState.isGraphAllowed()) { if (licenseState.isGraphAllowed()) {
new AsyncGraphAction(request, listener).start(); new AsyncGraphAction(request, listener).start();
} else { } else {
listener.onFailure(LicenseUtils.newComplianceException(Graph.NAME)); listener.onFailure(LicenseUtils.newComplianceException(XPackPlugin.GRAPH));
} }
} }

View File

@ -7,13 +7,12 @@ package org.elasticsearch.xpack.graph.test;
import org.apache.lucene.search.BooleanQuery; import org.apache.lucene.search.BooleanQuery;
import org.elasticsearch.action.ActionRequestValidationException; import org.elasticsearch.action.ActionRequestValidationException;
import org.elasticsearch.action.search.ShardSearchFailure;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.settings.Settings.Builder; import org.elasticsearch.common.settings.Settings.Builder;
import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.index.query.ScriptQueryBuilder; import org.elasticsearch.index.query.ScriptQueryBuilder;
import org.elasticsearch.xpack.monitoring.Monitoring; import org.elasticsearch.xpack.XPackSettings;
import org.elasticsearch.plugins.Plugin; import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.plugins.ScriptPlugin; import org.elasticsearch.plugins.ScriptPlugin;
import org.elasticsearch.script.AbstractSearchScript; import org.elasticsearch.script.AbstractSearchScript;
@ -21,9 +20,7 @@ import org.elasticsearch.script.ExecutableScript;
import org.elasticsearch.script.NativeScriptFactory; import org.elasticsearch.script.NativeScriptFactory;
import org.elasticsearch.script.Script; import org.elasticsearch.script.Script;
import org.elasticsearch.script.ScriptService.ScriptType; import org.elasticsearch.script.ScriptService.ScriptType;
import org.elasticsearch.xpack.security.Security;
import org.elasticsearch.test.ESSingleNodeTestCase; import org.elasticsearch.test.ESSingleNodeTestCase;
import org.elasticsearch.xpack.watcher.Watcher;
import org.elasticsearch.xpack.XPackPlugin; import org.elasticsearch.xpack.XPackPlugin;
import org.elasticsearch.xpack.graph.action.GraphExploreAction; import org.elasticsearch.xpack.graph.action.GraphExploreAction;
import org.elasticsearch.xpack.graph.action.GraphExploreRequest; import org.elasticsearch.xpack.graph.action.GraphExploreRequest;
@ -128,9 +125,9 @@ public class GraphTests extends ESSingleNodeTestCase {
public Settings nodeSettings() { public Settings nodeSettings() {
// Disable security otherwise authentication failures happen creating indices. // Disable security otherwise authentication failures happen creating indices.
Builder newSettings = Settings.builder(); Builder newSettings = Settings.builder();
newSettings.put(XPackPlugin.featureEnabledSetting(Security.NAME), false); newSettings.put(XPackSettings.SECURITY_ENABLED.getKey(), false);
newSettings.put(XPackPlugin.featureEnabledSetting(Monitoring.NAME), false); newSettings.put(XPackSettings.MONITORING_ENABLED.getKey(), false);
newSettings.put(XPackPlugin.featureEnabledSetting(Watcher.NAME), false); newSettings.put(XPackSettings.WATCHER_ENABLED.getKey(), false);
return newSettings.build(); return newSettings.build();
} }

View File

@ -5,33 +5,30 @@
*/ */
package org.elasticsearch.license; package org.elasticsearch.license;
import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.ClusterStateUpdateTask;
import org.elasticsearch.cluster.metadata.MetaData;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.xpack.monitoring.Monitoring;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.xpack.security.Security;
import org.elasticsearch.test.ESIntegTestCase;
import org.elasticsearch.xpack.watcher.Watcher;
import org.elasticsearch.xpack.XPackPlugin;
import org.elasticsearch.xpack.graph.Graph;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.ClusterStateUpdateTask;
import org.elasticsearch.cluster.metadata.MetaData;
import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.test.ESIntegTestCase;
import org.elasticsearch.xpack.XPackPlugin;
import org.elasticsearch.xpack.XPackSettings;
public abstract class AbstractLicensesIntegrationTestCase extends ESIntegTestCase { public abstract class AbstractLicensesIntegrationTestCase extends ESIntegTestCase {
@Override @Override
protected Settings nodeSettings(int nodeOrdinal) { protected Settings nodeSettings(int nodeOrdinal) {
return Settings.builder() return Settings.builder()
.put(XPackPlugin.featureEnabledSetting(Security.NAME), false) .put(XPackSettings.SECURITY_ENABLED.getKey(), false)
.put(XPackPlugin.featureEnabledSetting(Monitoring.NAME), false) .put(XPackSettings.MONITORING_ENABLED.getKey(), false)
.put(XPackPlugin.featureEnabledSetting(Watcher.NAME), false) .put(XPackSettings.WATCHER_ENABLED.getKey(), false)
.put(XPackPlugin.featureEnabledSetting(Graph.NAME), false) .put(XPackSettings.GRAPH_ENABLED.getKey(), false)
.build(); .build();
} }

View File

@ -18,10 +18,7 @@ import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.plugins.Plugin; import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.test.ESSingleNodeTestCase; import org.elasticsearch.test.ESSingleNodeTestCase;
import org.elasticsearch.xpack.XPackPlugin; import org.elasticsearch.xpack.XPackPlugin;
import org.elasticsearch.xpack.graph.Graph; import org.elasticsearch.xpack.XPackSettings;
import org.elasticsearch.xpack.monitoring.Monitoring;
import org.elasticsearch.xpack.security.Security;
import org.elasticsearch.xpack.watcher.Watcher;
import static org.elasticsearch.license.TestUtils.generateSignedLicense; import static org.elasticsearch.license.TestUtils.generateSignedLicense;
import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.equalTo;
@ -38,12 +35,11 @@ public class LicensesManagerServiceTests extends ESSingleNodeTestCase {
@Override @Override
protected Settings nodeSettings() { protected Settings nodeSettings() {
return Settings.builder(). return Settings.builder()
put(XPackPlugin.featureEnabledSetting(Security.NAME), false) .put(XPackSettings.SECURITY_ENABLED.getKey(), false)
.put(XPackPlugin.featureEnabledSetting(Monitoring.NAME), false) .put(XPackSettings.MONITORING_ENABLED.getKey(), false)
.put(XPackPlugin.featureEnabledSetting(Watcher.NAME), false) .put(XPackSettings.WATCHER_ENABLED.getKey(), false)
.put(XPackPlugin.featureEnabledSetting(Graph.NAME), false) .put(XPackSettings.GRAPH_ENABLED.getKey(), false).build();
.build();
} }
@Override @Override

View File

@ -8,13 +8,11 @@ package org.elasticsearch.license;
import org.elasticsearch.action.ActionFuture; import org.elasticsearch.action.ActionFuture;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.xpack.monitoring.Monitoring; import org.elasticsearch.xpack.XPackSettings;
import org.elasticsearch.node.Node; import org.elasticsearch.node.Node;
import org.elasticsearch.plugins.Plugin; import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.xpack.security.Security;
import org.elasticsearch.test.ESSingleNodeTestCase; import org.elasticsearch.test.ESSingleNodeTestCase;
import org.elasticsearch.xpack.XPackPlugin; import org.elasticsearch.xpack.XPackPlugin;
import org.elasticsearch.xpack.watcher.Watcher;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
@ -39,9 +37,9 @@ public class LicensesTransportTests extends ESSingleNodeTestCase {
@Override @Override
protected Settings nodeSettings() { protected Settings nodeSettings() {
Settings.Builder newSettings = Settings.builder(); Settings.Builder newSettings = Settings.builder();
newSettings.put(XPackPlugin.featureEnabledSetting(Security.NAME), false); newSettings.put(XPackSettings.SECURITY_ENABLED.getKey(), false);
newSettings.put(XPackPlugin.featureEnabledSetting(Monitoring.NAME), false); newSettings.put(XPackSettings.MONITORING_ENABLED.getKey(), false);
newSettings.put(XPackPlugin.featureEnabledSetting(Watcher.NAME), false); newSettings.put(XPackSettings.WATCHER_ENABLED.getKey(), false);
newSettings.put(Node.NODE_DATA_SETTING.getKey(), true); newSettings.put(Node.NODE_DATA_SETTING.getKey(), true);
return newSettings.build(); return newSettings.build();
} }

View File

@ -22,21 +22,17 @@ import org.elasticsearch.common.transport.TransportAddress;
import org.elasticsearch.discovery.DiscoveryModule; import org.elasticsearch.discovery.DiscoveryModule;
import org.elasticsearch.discovery.zen.ping.unicast.UnicastZenPing; import org.elasticsearch.discovery.zen.ping.unicast.UnicastZenPing;
import org.elasticsearch.xpack.XPackPlugin; import org.elasticsearch.xpack.XPackPlugin;
import org.elasticsearch.xpack.monitoring.Monitoring; import org.elasticsearch.xpack.XPackSettings;
import org.elasticsearch.node.Node; import org.elasticsearch.node.Node;
import org.elasticsearch.plugins.Plugin; import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.xpack.security.Security;
import org.elasticsearch.test.ESIntegTestCase; import org.elasticsearch.test.ESIntegTestCase;
import org.elasticsearch.test.ESIntegTestCase.ClusterScope; import org.elasticsearch.test.ESIntegTestCase.ClusterScope;
import org.elasticsearch.test.ESIntegTestCase.Scope; import org.elasticsearch.test.ESIntegTestCase.Scope;
import org.elasticsearch.test.InternalTestCluster; import org.elasticsearch.test.InternalTestCluster;
import org.elasticsearch.test.NodeConfigurationSource; import org.elasticsearch.test.NodeConfigurationSource;
import org.elasticsearch.test.TestCluster; import org.elasticsearch.test.TestCluster;
import org.elasticsearch.xpack.graph.Graph;
import org.elasticsearch.xpack.watcher.Watcher;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
@ -50,9 +46,6 @@ import static org.hamcrest.Matchers.equalTo;
@ClusterScope(scope = Scope.TEST, transportClientRatio = 0, numClientNodes = 1, numDataNodes = 0) @ClusterScope(scope = Scope.TEST, transportClientRatio = 0, numClientNodes = 1, numDataNodes = 0)
public abstract class TribeTransportTestCase extends ESIntegTestCase { public abstract class TribeTransportTestCase extends ESIntegTestCase {
private static final Collection<String> ALL_FEATURES = Arrays.asList(Security.NAME, Monitoring.NAME,
Watcher.NAME, Graph.NAME);
protected List<String> enabledFeatures() { protected List<String> enabledFeatures() {
return Collections.emptyList(); return Collections.emptyList();
} }
@ -64,9 +57,10 @@ public abstract class TribeTransportTestCase extends ESIntegTestCase {
.put("transport.type", "local") .put("transport.type", "local")
.put(DiscoveryModule.DISCOVERY_TYPE_SETTING.getKey(), "local"); .put(DiscoveryModule.DISCOVERY_TYPE_SETTING.getKey(), "local");
List<String> enabledFeatures = enabledFeatures(); List<String> enabledFeatures = enabledFeatures();
for (String feature : ALL_FEATURES) { builder.put(XPackSettings.SECURITY_ENABLED.getKey(), enabledFeatures.contains(XPackPlugin.SECURITY));
builder.put(XPackPlugin.featureEnabledSetting(feature), enabledFeatures.contains(feature)); builder.put(XPackSettings.MONITORING_ENABLED.getKey(), enabledFeatures.contains(XPackPlugin.MONITORING));
} builder.put(XPackSettings.WATCHER_ENABLED.getKey(), enabledFeatures.contains(XPackPlugin.WATCHER));
builder.put(XPackSettings.GRAPH_ENABLED.getKey(), enabledFeatures.contains(XPackPlugin.GRAPH));
return builder.build(); return builder.build();
} }

View File

@ -17,6 +17,7 @@ import org.elasticsearch.license.LicenseService;
import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.license.XPackLicenseState;
import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.xpack.XPackPlugin; import org.elasticsearch.xpack.XPackPlugin;
import org.elasticsearch.xpack.XPackSettings;
import org.elasticsearch.xpack.monitoring.action.MonitoringBulkAction; import org.elasticsearch.xpack.monitoring.action.MonitoringBulkAction;
import org.elasticsearch.xpack.monitoring.action.TransportMonitoringBulkAction; import org.elasticsearch.xpack.monitoring.action.TransportMonitoringBulkAction;
import org.elasticsearch.xpack.monitoring.agent.AgentService; import org.elasticsearch.xpack.monitoring.agent.AgentService;
@ -72,7 +73,7 @@ public class Monitoring implements ActionPlugin {
this.settings = settings; this.settings = settings;
this.env = env; this.env = env;
this.licenseState = licenseState; this.licenseState = licenseState;
this.enabled = enabled(settings); this.enabled = XPackSettings.MONITORING_ENABLED.get(settings);
this.transportClientMode = XPackPlugin.transportClientMode(settings); this.transportClientMode = XPackPlugin.transportClientMode(settings);
this.tribeNode = XPackPlugin.isTribeNode(settings); this.tribeNode = XPackPlugin.isTribeNode(settings);
} }
@ -139,8 +140,4 @@ public class Monitoring implements ActionPlugin {
} }
return singletonList(RestMonitoringBulkAction.class); return singletonList(RestMonitoringBulkAction.class);
} }
public static boolean enabled(Settings settings) {
return MonitoringSettings.ENABLED.get(settings);
}
} }

View File

@ -17,6 +17,7 @@ import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.license.XPackLicenseState;
import org.elasticsearch.xpack.XPackFeatureSet; import org.elasticsearch.xpack.XPackFeatureSet;
import org.elasticsearch.xpack.XPackSettings;
import org.elasticsearch.xpack.monitoring.agent.exporter.Exporter; import org.elasticsearch.xpack.monitoring.agent.exporter.Exporter;
import org.elasticsearch.xpack.monitoring.agent.exporter.Exporters; import org.elasticsearch.xpack.monitoring.agent.exporter.Exporters;
@ -31,7 +32,7 @@ public class MonitoringFeatureSet implements XPackFeatureSet {
@Inject @Inject
public MonitoringFeatureSet(Settings settings, @Nullable XPackLicenseState licenseState, @Nullable Exporters exporters) { public MonitoringFeatureSet(Settings settings, @Nullable XPackLicenseState licenseState, @Nullable Exporters exporters) {
this.enabled = MonitoringSettings.ENABLED.get(settings); this.enabled = XPackSettings.MONITORING_ENABLED.get(settings);
this.licenseState = licenseState; this.licenseState = licenseState;
this.exporters = exporters; this.exporters = exporters;
} }

View File

@ -7,7 +7,6 @@ package org.elasticsearch.xpack.monitoring;
import org.elasticsearch.common.Booleans; import org.elasticsearch.common.Booleans;
import org.elasticsearch.common.component.AbstractComponent; import org.elasticsearch.common.component.AbstractComponent;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.ClusterSettings; import org.elasticsearch.common.settings.ClusterSettings;
import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Setting;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
@ -35,18 +34,6 @@ public class MonitoringSettings extends AbstractComponent {
*/ */
public static final TimeValue HISTORY_DURATION_MINIMUM = TimeValue.timeValueHours(24); public static final TimeValue HISTORY_DURATION_MINIMUM = TimeValue.timeValueHours(24);
/**
* Determines whether monitoring is enabled/disabled
*/
public static final Setting<Boolean> ENABLED =
new Setting<>(XPackPlugin.featureEnabledSetting(Monitoring.NAME),
// By default, monitoring is disabled on tribe nodes
(s) -> String.valueOf(!XPackPlugin.isTribeNode(s) && !XPackPlugin.isTribeClientNode(s)),
Booleans::parseBooleanExact,
Property.NodeScope);
/** /**
* Sampling interval between two collections (default to 10s) * Sampling interval between two collections (default to 10s)
*/ */
@ -135,8 +122,7 @@ public class MonitoringSettings extends AbstractComponent {
CLUSTER_STATE_TIMEOUT, CLUSTER_STATE_TIMEOUT,
CLUSTER_STATS_TIMEOUT, CLUSTER_STATS_TIMEOUT,
HISTORY_DURATION, HISTORY_DURATION,
EXPORTERS_SETTINGS, EXPORTERS_SETTINGS);
ENABLED);
} }
public static List<String> getSettingsFilter() { public static List<String> getSettingsFilter() {

View File

@ -19,11 +19,11 @@ import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.IndexNotFoundException; import org.elasticsearch.index.IndexNotFoundException;
import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.license.XPackLicenseState;
import org.elasticsearch.xpack.XPackSettings;
import org.elasticsearch.xpack.monitoring.MonitoringSettings; import org.elasticsearch.xpack.monitoring.MonitoringSettings;
import org.elasticsearch.xpack.monitoring.agent.collector.AbstractCollector; import org.elasticsearch.xpack.monitoring.agent.collector.AbstractCollector;
import org.elasticsearch.xpack.monitoring.agent.exporter.MonitoringDoc; import org.elasticsearch.xpack.monitoring.agent.exporter.MonitoringDoc;
import org.elasticsearch.xpack.security.InternalClient; import org.elasticsearch.xpack.security.InternalClient;
import org.elasticsearch.xpack.security.Security;
/** /**
* Collector for the Recovery API. * Collector for the Recovery API.
@ -67,7 +67,8 @@ public class IndexRecoveryCollector extends AbstractCollector {
results.add(indexRecoveryDoc); results.add(indexRecoveryDoc);
} }
} catch (IndexNotFoundException e) { } catch (IndexNotFoundException e) {
if (Security.enabled(settings) && IndexNameExpressionResolver.isAllIndices(Arrays.asList(monitoringSettings.indices()))) { if (XPackSettings.SECURITY_ENABLED.get(settings)
&& IndexNameExpressionResolver.isAllIndices(Arrays.asList(monitoringSettings.indices()))) {
logger.debug("collector [{}] - unable to collect data for missing index [{}]", name(), e.getIndex()); logger.debug("collector [{}] - unable to collect data for missing index [{}]", name(), e.getIndex());
} else { } else {
throw e; throw e;

View File

@ -21,11 +21,11 @@ import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.IndexNotFoundException; import org.elasticsearch.index.IndexNotFoundException;
import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.license.XPackLicenseState;
import org.elasticsearch.xpack.XPackSettings;
import org.elasticsearch.xpack.monitoring.MonitoringSettings; import org.elasticsearch.xpack.monitoring.MonitoringSettings;
import org.elasticsearch.xpack.monitoring.agent.collector.AbstractCollector; import org.elasticsearch.xpack.monitoring.agent.collector.AbstractCollector;
import org.elasticsearch.xpack.monitoring.agent.exporter.MonitoringDoc; import org.elasticsearch.xpack.monitoring.agent.exporter.MonitoringDoc;
import org.elasticsearch.xpack.security.InternalClient; import org.elasticsearch.xpack.security.InternalClient;
import org.elasticsearch.xpack.security.Security;
/** /**
* Collector for indices statistics. * Collector for indices statistics.
@ -83,7 +83,8 @@ public class IndexStatsCollector extends AbstractCollector {
results.add(indexStatsDoc); results.add(indexStatsDoc);
} }
} catch (IndexNotFoundException e) { } catch (IndexNotFoundException e) {
if (Security.enabled(settings) && IndexNameExpressionResolver.isAllIndices(Arrays.asList(monitoringSettings.indices()))) { if (XPackSettings.SECURITY_ENABLED.get(settings)
&& IndexNameExpressionResolver.isAllIndices(Arrays.asList(monitoringSettings.indices()))) {
logger.debug("collector [{}] - unable to collect data for missing index [{}]", name(), e.getIndex()); logger.debug("collector [{}] - unable to collect data for missing index [{}]", name(), e.getIndex());
} else { } else {
throw e; throw e;

View File

@ -17,11 +17,11 @@ import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.IndexNotFoundException; import org.elasticsearch.index.IndexNotFoundException;
import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.license.XPackLicenseState;
import org.elasticsearch.xpack.XPackSettings;
import org.elasticsearch.xpack.monitoring.MonitoringSettings; import org.elasticsearch.xpack.monitoring.MonitoringSettings;
import org.elasticsearch.xpack.monitoring.agent.collector.AbstractCollector; import org.elasticsearch.xpack.monitoring.agent.collector.AbstractCollector;
import org.elasticsearch.xpack.monitoring.agent.exporter.MonitoringDoc; import org.elasticsearch.xpack.monitoring.agent.exporter.MonitoringDoc;
import org.elasticsearch.xpack.security.InternalClient; import org.elasticsearch.xpack.security.InternalClient;
import org.elasticsearch.xpack.security.Security;
/** /**
* Collector for indices statistics. * Collector for indices statistics.
@ -66,7 +66,8 @@ public class IndicesStatsCollector extends AbstractCollector {
return Collections.singletonList(indicesStatsDoc); return Collections.singletonList(indicesStatsDoc);
} catch (IndexNotFoundException e) { } catch (IndexNotFoundException e) {
if (Security.enabled(settings) && IndexNameExpressionResolver.isAllIndices(Arrays.asList(monitoringSettings.indices()))) { if (XPackSettings.SECURITY_ENABLED.get(settings)
&& IndexNameExpressionResolver.isAllIndices(Arrays.asList(monitoringSettings.indices()))) {
logger.debug("collector [{}] - unable to collect data for missing index [{}]", name(), e.getIndex()); logger.debug("collector [{}] - unable to collect data for missing index [{}]", name(), e.getIndex());
return Collections.emptyList(); return Collections.emptyList();
} }

View File

@ -11,6 +11,7 @@ import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.plugins.PluginInfo; import org.elasticsearch.plugins.PluginInfo;
import org.elasticsearch.test.ESIntegTestCase.ClusterScope; import org.elasticsearch.test.ESIntegTestCase.ClusterScope;
import org.elasticsearch.xpack.XPackPlugin; import org.elasticsearch.xpack.XPackPlugin;
import org.elasticsearch.xpack.XPackSettings;
import org.elasticsearch.xpack.monitoring.agent.AgentService; import org.elasticsearch.xpack.monitoring.agent.AgentService;
import org.elasticsearch.xpack.monitoring.test.MonitoringIntegTestCase; import org.elasticsearch.xpack.monitoring.test.MonitoringIntegTestCase;
@ -41,7 +42,7 @@ public class MonitoringPluginTests extends MonitoringIntegTestCase {
public void testMonitoringEnabled() { public void testMonitoringEnabled() {
internalCluster().startNode(Settings.builder() internalCluster().startNode(Settings.builder()
.put(XPackPlugin.featureEnabledSetting(Monitoring.NAME), true) .put(XPackSettings.MONITORING_ENABLED.getKey(), true)
.build()); .build());
assertPluginIsLoaded(); assertPluginIsLoaded();
assertServiceIsBound(AgentService.class); assertServiceIsBound(AgentService.class);
@ -49,7 +50,7 @@ public class MonitoringPluginTests extends MonitoringIntegTestCase {
public void testMonitoringDisabled() { public void testMonitoringDisabled() {
internalCluster().startNode(Settings.builder() internalCluster().startNode(Settings.builder()
.put(XPackPlugin.featureEnabledSetting(Monitoring.NAME), false) .put(XPackSettings.MONITORING_ENABLED.getKey(), false)
.build()); .build());
assertPluginIsLoaded(); assertPluginIsLoaded();
assertServiceIsNotBound(AgentService.class); assertServiceIsNotBound(AgentService.class);
@ -57,7 +58,7 @@ public class MonitoringPluginTests extends MonitoringIntegTestCase {
public void testMonitoringEnabledOnTribeNode() { public void testMonitoringEnabledOnTribeNode() {
internalCluster().startNode(Settings.builder() internalCluster().startNode(Settings.builder()
.put(XPackPlugin.featureEnabledSetting(Monitoring.NAME), true) .put(XPackSettings.MONITORING_ENABLED.getKey(), true)
.put("tribe.name", "t1") .put("tribe.name", "t1")
.build()); .build());
assertPluginIsLoaded(); assertPluginIsLoaded();

View File

@ -26,6 +26,7 @@ import org.elasticsearch.test.transport.AssertingLocalTransport;
import org.elasticsearch.test.transport.MockTransportService; import org.elasticsearch.test.transport.MockTransportService;
import org.elasticsearch.xpack.XPackClient; import org.elasticsearch.xpack.XPackClient;
import org.elasticsearch.xpack.XPackPlugin; import org.elasticsearch.xpack.XPackPlugin;
import org.elasticsearch.xpack.XPackSettings;
import org.elasticsearch.xpack.monitoring.MonitoredSystem; import org.elasticsearch.xpack.monitoring.MonitoredSystem;
import org.elasticsearch.xpack.monitoring.MonitoringSettings; import org.elasticsearch.xpack.monitoring.MonitoringSettings;
import org.elasticsearch.xpack.monitoring.agent.AgentService; import org.elasticsearch.xpack.monitoring.agent.AgentService;
@ -39,7 +40,6 @@ import org.elasticsearch.xpack.security.authc.support.Hasher;
import org.elasticsearch.xpack.security.authc.support.SecuredString; import org.elasticsearch.xpack.security.authc.support.SecuredString;
import org.elasticsearch.xpack.security.authz.store.FileRolesStore; import org.elasticsearch.xpack.security.authz.store.FileRolesStore;
import org.elasticsearch.xpack.security.crypto.CryptoService; import org.elasticsearch.xpack.security.crypto.CryptoService;
import org.elasticsearch.xpack.watcher.Watcher;
import org.hamcrest.Matcher; import org.hamcrest.Matcher;
import org.jboss.netty.util.internal.SystemPropertyUtil; import org.jboss.netty.util.internal.SystemPropertyUtil;
import org.junit.After; import org.junit.After;
@ -109,7 +109,7 @@ public abstract class MonitoringIntegTestCase extends ESIntegTestCase {
protected Settings nodeSettings(int nodeOrdinal) { protected Settings nodeSettings(int nodeOrdinal) {
Settings.Builder builder = Settings.builder() Settings.Builder builder = Settings.builder()
.put(super.nodeSettings(nodeOrdinal)) .put(super.nodeSettings(nodeOrdinal))
.put(XPackPlugin.featureEnabledSetting(Watcher.NAME), watcherEnabled) .put(XPackSettings.WATCHER_ENABLED.getKey(), watcherEnabled)
// we do this by default in core, but for monitoring this isn't needed and only adds noise. // we do this by default in core, but for monitoring this isn't needed and only adds noise.
.put("index.store.mock.check_index_on_close", false); .put("index.store.mock.check_index_on_close", false);

View File

@ -13,7 +13,6 @@ import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.List; import java.util.List;
import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.Optional; import java.util.Optional;
import java.util.Set; import java.util.Set;
@ -47,6 +46,7 @@ import org.elasticsearch.rest.RestHandler;
import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.watcher.ResourceWatcherService; import org.elasticsearch.watcher.ResourceWatcherService;
import org.elasticsearch.xpack.XPackPlugin; import org.elasticsearch.xpack.XPackPlugin;
import org.elasticsearch.xpack.XPackSettings;
import org.elasticsearch.xpack.extensions.XPackExtension; import org.elasticsearch.xpack.extensions.XPackExtension;
import org.elasticsearch.xpack.security.action.SecurityActionModule; import org.elasticsearch.xpack.security.action.SecurityActionModule;
import org.elasticsearch.xpack.security.action.filter.SecurityActionFilter; import org.elasticsearch.xpack.security.action.filter.SecurityActionFilter;
@ -137,14 +137,10 @@ public class Security implements ActionPlugin, IngestPlugin {
private static final ESLogger logger = Loggers.getLogger(XPackPlugin.class); private static final ESLogger logger = Loggers.getLogger(XPackPlugin.class);
public static final String NAME = "security"; public static final String NAME3 = XPackPlugin.SECURITY + "3";
public static final String NAME3 = NAME + "3"; public static final String NAME4 = XPackPlugin.SECURITY + "4";
public static final String NAME4 = NAME + "4";
public static final String DLS_FLS_FEATURE = "security.dls_fls";
public static final Setting<Optional<String>> USER_SETTING = OptionalSettings.createString(setting("user"), Property.NodeScope); public static final Setting<Optional<String>> USER_SETTING = OptionalSettings.createString(setting("user"), Property.NodeScope);
public static final Setting<Boolean> AUDIT_ENABLED_SETTING =
Setting.boolSetting(featureEnabledSetting("audit"), false, Property.NodeScope);
public static final Setting<List<String>> AUDIT_OUTPUTS_SETTING = public static final Setting<List<String>> AUDIT_OUTPUTS_SETTING =
Setting.listSetting(setting("audit.outputs"), Setting.listSetting(setting("audit.outputs"),
s -> s.getAsMap().containsKey(setting("audit.outputs")) ? s -> s.getAsMap().containsKey(setting("audit.outputs")) ?
@ -162,7 +158,7 @@ public class Security implements ActionPlugin, IngestPlugin {
this.settings = settings; this.settings = settings;
this.env = env; this.env = env;
this.transportClientMode = XPackPlugin.transportClientMode(settings); this.transportClientMode = XPackPlugin.transportClientMode(settings);
this.enabled = XPackPlugin.featureEnabled(settings, NAME, true); this.enabled = XPackSettings.SECURITY_ENABLED.get(settings);
if (enabled && transportClientMode == false) { if (enabled && transportClientMode == false) {
validateAutoCreateIndex(settings); validateAutoCreateIndex(settings);
cryptoService = new CryptoService(settings, env); cryptoService = new CryptoService(settings, env);
@ -176,10 +172,6 @@ public class Security implements ActionPlugin, IngestPlugin {
return cryptoService; return cryptoService;
} }
public boolean isEnabled() {
return enabled;
}
public Collection<Module> nodeModules() { public Collection<Module> nodeModules() {
List<Module> modules = new ArrayList<>(); List<Module> modules = new ArrayList<>();
@ -215,7 +207,7 @@ public class Security implements ActionPlugin, IngestPlugin {
// everything should have been loaded // everything should have been loaded
modules.add(b -> { modules.add(b -> {
b.bind(CryptoService.class).toInstance(cryptoService); b.bind(CryptoService.class).toInstance(cryptoService);
if (auditingEnabled(settings)) { if (XPackSettings.AUDIT_ENABLED.get(settings)) {
b.bind(AuditTrail.class).to(AuditTrailService.class); // interface used by some actions... b.bind(AuditTrail.class).to(AuditTrailService.class); // interface used by some actions...
} }
}); });
@ -271,11 +263,11 @@ public class Security implements ActionPlugin, IngestPlugin {
// audit trails construction // audit trails construction
IndexAuditTrail indexAuditTrail = null; IndexAuditTrail indexAuditTrail = null;
Set<AuditTrail> auditTrails = new LinkedHashSet<>(); Set<AuditTrail> auditTrails = new LinkedHashSet<>();
if (AUDIT_ENABLED_SETTING.get(settings)) { if (XPackSettings.AUDIT_ENABLED.get(settings)) {
List<String> outputs = AUDIT_OUTPUTS_SETTING.get(settings); List<String> outputs = AUDIT_OUTPUTS_SETTING.get(settings);
if (outputs.isEmpty()) { if (outputs.isEmpty()) {
throw new IllegalArgumentException("Audit logging is enabled but there are zero output types in " throw new IllegalArgumentException("Audit logging is enabled but there are zero output types in "
+ AUDIT_ENABLED_SETTING.getKey()); + XPackSettings.AUDIT_ENABLED.getKey());
} }
for (String output : outputs) { for (String output : outputs) {
@ -375,7 +367,7 @@ public class Security implements ActionPlugin, IngestPlugin {
SecurityNetty4HttpServerTransport.overrideSettings(settingsBuilder, settings); SecurityNetty4HttpServerTransport.overrideSettings(settingsBuilder, settings);
} }
settingsBuilder.put(NetworkModule.TRANSPORT_SERVICE_TYPE_KEY, Security.NAME); settingsBuilder.put(NetworkModule.TRANSPORT_SERVICE_TYPE_KEY, XPackPlugin.SECURITY);
addUserSettings(settings, settingsBuilder); addUserSettings(settings, settingsBuilder);
addTribeSettings(settings, settingsBuilder); addTribeSettings(settings, settingsBuilder);
return settingsBuilder.build(); return settingsBuilder.build();
@ -384,7 +376,6 @@ public class Security implements ActionPlugin, IngestPlugin {
public List<Setting<?>> getSettings() { public List<Setting<?>> getSettings() {
List<Setting<?>> settingsList = new ArrayList<>(); List<Setting<?>> settingsList = new ArrayList<>();
// always register for both client and node modes // always register for both client and node modes
XPackPlugin.addFeatureEnabledSettings(settingsList, NAME, true);
settingsList.add(USER_SETTING); settingsList.add(USER_SETTING);
// SSL settings // SSL settings
@ -398,13 +389,11 @@ public class Security implements ActionPlugin, IngestPlugin {
} }
// The following just apply in node mode // The following just apply in node mode
XPackPlugin.addFeatureEnabledSettings(settingsList, DLS_FLS_FEATURE, true);
// IP Filter settings // IP Filter settings
IPFilter.addSettings(settingsList); IPFilter.addSettings(settingsList);
// audit settings // audit settings
settingsList.add(AUDIT_ENABLED_SETTING);
settingsList.add(AUDIT_OUTPUTS_SETTING); settingsList.add(AUDIT_OUTPUTS_SETTING);
LoggingAuditTrail.registerSettings(settingsList); LoggingAuditTrail.registerSettings(settingsList);
IndexAuditTrail.registerSettings(settingsList); IndexAuditTrail.registerSettings(settingsList);
@ -456,7 +445,7 @@ public class Security implements ActionPlugin, IngestPlugin {
} }
assert licenseState != null; assert licenseState != null;
if (flsDlsEnabled(settings)) { if (XPackSettings.DLS_FLS_ENABLED.get(settings)) {
module.setSearcherWrapper(indexService -> module.setSearcherWrapper(indexService ->
new SecurityIndexSearcherWrapper(indexService.getIndexSettings(), indexService.newQueryShardContext(), new SecurityIndexSearcherWrapper(indexService.getIndexSettings(), indexService.newQueryShardContext(),
indexService.mapperService(), indexService.cache().bitsetFilterCache(), indexService.mapperService(), indexService.cache().bitsetFilterCache(),
@ -529,7 +518,7 @@ public class Security implements ActionPlugin, IngestPlugin {
if (enabled) { if (enabled) {
module.registerTransport(Security.NAME3, SecurityNetty3Transport.class); module.registerTransport(Security.NAME3, SecurityNetty3Transport.class);
module.registerTransport(Security.NAME4, SecurityNetty4Transport.class); module.registerTransport(Security.NAME4, SecurityNetty4Transport.class);
module.registerTransportService(Security.NAME, SecurityClientTransportService.class); module.registerTransportService(XPackPlugin.SECURITY, SecurityClientTransportService.class);
} }
return; return;
} }
@ -537,7 +526,7 @@ public class Security implements ActionPlugin, IngestPlugin {
if (enabled) { if (enabled) {
module.registerTransport(Security.NAME3, SecurityNetty3Transport.class); module.registerTransport(Security.NAME3, SecurityNetty3Transport.class);
module.registerTransport(Security.NAME4, SecurityNetty4Transport.class); module.registerTransport(Security.NAME4, SecurityNetty4Transport.class);
module.registerTransportService(Security.NAME, SecurityServerTransportService.class); module.registerTransportService(XPackPlugin.SECURITY, SecurityServerTransportService.class);
module.registerHttpTransport(Security.NAME3, SecurityNetty3HttpServerTransport.class); module.registerHttpTransport(Security.NAME3, SecurityNetty3HttpServerTransport.class);
module.registerHttpTransport(Security.NAME4, SecurityNetty4HttpServerTransport.class); module.registerHttpTransport(Security.NAME4, SecurityNetty4HttpServerTransport.class);
} }
@ -595,9 +584,9 @@ public class Security implements ActionPlugin, IngestPlugin {
} }
} }
final String tribeEnabledSetting = tribePrefix + XPackPlugin.featureEnabledSetting(NAME); final String tribeEnabledSetting = tribePrefix + XPackSettings.SECURITY_ENABLED.getKey();
if (settings.get(tribeEnabledSetting) != null) { if (settings.get(tribeEnabledSetting) != null) {
boolean enabled = enabled(tribeSettings.getValue()); boolean enabled = XPackSettings.SECURITY_ENABLED.get(tribeSettings.getValue());
if (!enabled) { if (!enabled) {
throw new IllegalStateException("tribe setting [" + tribeEnabledSetting + "] must be set to true but the value is [" throw new IllegalStateException("tribe setting [" + tribeEnabledSetting + "] must be set to true but the value is ["
+ settings.get(tribeEnabledSetting) + "]"); + settings.get(tribeEnabledSetting) + "]");
@ -617,20 +606,8 @@ public class Security implements ActionPlugin, IngestPlugin {
} }
} }
public static boolean enabled(Settings settings) {
return XPackPlugin.featureEnabled(settings, NAME, true);
}
public static boolean flsDlsEnabled(Settings settings) {
return XPackPlugin.featureEnabled(settings, DLS_FLS_FEATURE, true);
}
public static String enabledSetting() {
return XPackPlugin.featureEnabledSetting(NAME);
}
public static String settingPrefix() { public static String settingPrefix() {
return XPackPlugin.featureSettingPrefix(NAME) + "."; return XPackPlugin.featureSettingPrefix(XPackPlugin.SECURITY) + ".";
} }
public static String setting(String setting) { public static String setting(String setting) {
@ -638,17 +615,8 @@ public class Security implements ActionPlugin, IngestPlugin {
return settingPrefix() + setting; return settingPrefix() + setting;
} }
public static String featureEnabledSetting(String feature) { static boolean indexAuditLoggingEnabled(Settings settings) {
assert feature != null && feature.startsWith(".") == false; if (XPackSettings.AUDIT_ENABLED.get(settings)) {
return XPackPlugin.featureEnabledSetting("security." + feature);
}
public static boolean auditingEnabled(Settings settings) {
return AUDIT_ENABLED_SETTING.get(settings);
}
public static boolean indexAuditLoggingEnabled(Settings settings) {
if (auditingEnabled(settings)) {
List<String> outputs = AUDIT_OUTPUTS_SETTING.get(settings); List<String> outputs = AUDIT_OUTPUTS_SETTING.get(settings);
for (String output : outputs) { for (String output : outputs) {
if (output.equals(IndexAuditTrail.NAME)) { if (output.equals(IndexAuditTrail.NAME)) {

View File

@ -5,17 +5,23 @@
*/ */
package org.elasticsearch.xpack.security; package org.elasticsearch.xpack.security;
import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import org.elasticsearch.common.Nullable; import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.license.XPackLicenseState;
import org.elasticsearch.xpack.XPackFeatureSet;
import org.elasticsearch.xpack.XPackPlugin;
import org.elasticsearch.xpack.XPackSettings;
import org.elasticsearch.xpack.security.audit.AuditTrailService; import org.elasticsearch.xpack.security.audit.AuditTrailService;
import org.elasticsearch.xpack.security.authc.Realms; import org.elasticsearch.xpack.security.authc.Realms;
import org.elasticsearch.xpack.XPackFeatureSet;
import org.elasticsearch.xpack.security.authz.store.CompositeRolesStore; import org.elasticsearch.xpack.security.authz.store.CompositeRolesStore;
import org.elasticsearch.xpack.security.authz.store.RolesStore; import org.elasticsearch.xpack.security.authz.store.RolesStore;
import org.elasticsearch.xpack.security.crypto.CryptoService; import org.elasticsearch.xpack.security.crypto.CryptoService;
@ -24,11 +30,6 @@ import org.elasticsearch.xpack.security.transport.netty3.SecurityNetty3HttpServe
import org.elasticsearch.xpack.security.transport.netty3.SecurityNetty3Transport; import org.elasticsearch.xpack.security.transport.netty3.SecurityNetty3Transport;
import org.elasticsearch.xpack.security.user.AnonymousUser; import org.elasticsearch.xpack.security.user.AnonymousUser;
import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
/** /**
* *
*/ */
@ -54,7 +55,7 @@ public class SecurityFeatureSet implements XPackFeatureSet {
public SecurityFeatureSet(Settings settings, @Nullable XPackLicenseState licenseState, @Nullable Realms realms, public SecurityFeatureSet(Settings settings, @Nullable XPackLicenseState licenseState, @Nullable Realms realms,
@Nullable CompositeRolesStore rolesStore, @Nullable IPFilter ipFilter, @Nullable CompositeRolesStore rolesStore, @Nullable IPFilter ipFilter,
@Nullable AuditTrailService auditTrailService, @Nullable CryptoService cryptoService) { @Nullable AuditTrailService auditTrailService, @Nullable CryptoService cryptoService) {
this.enabled = Security.enabled(settings); this.enabled = XPackSettings.SECURITY_ENABLED.get(settings);
this.licenseState = licenseState; this.licenseState = licenseState;
this.realms = realms; this.realms = realms;
this.rolesStore = rolesStore; this.rolesStore = rolesStore;
@ -66,7 +67,7 @@ public class SecurityFeatureSet implements XPackFeatureSet {
@Override @Override
public String name() { public String name() {
return Security.NAME; return XPackPlugin.SECURITY;
} }
@Override @Override
@ -169,7 +170,7 @@ public class SecurityFeatureSet implements XPackFeatureSet {
public Usage(boolean available, boolean enabled, Map<String, Object> realmsUsage, Map<String, Object> rolesStoreUsage, public Usage(boolean available, boolean enabled, Map<String, Object> realmsUsage, Map<String, Object> rolesStoreUsage,
Map<String, Object> sslUsage, Map<String, Object> auditUsage, Map<String, Object> ipFilterUsage, Map<String, Object> sslUsage, Map<String, Object> auditUsage, Map<String, Object> ipFilterUsage,
Map<String, Object> systemKeyUsage, Map<String, Object> anonymousUsage) { Map<String, Object> systemKeyUsage, Map<String, Object> anonymousUsage) {
super(Security.NAME, available, enabled); super(XPackPlugin.SECURITY, available, enabled);
this.realmsUsage = realmsUsage; this.realmsUsage = realmsUsage;
this.rolesStoreUsage = rolesStoreUsage; this.rolesStoreUsage = rolesStoreUsage;
this.sslUsage = sslUsage; this.sslUsage = sslUsage;

View File

@ -5,6 +5,12 @@
*/ */
package org.elasticsearch.xpack.security.action.filter; package org.elasticsearch.xpack.security.action.filter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.function.Predicate;
import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.ActionRequest; import org.elasticsearch.action.ActionRequest;
import org.elasticsearch.action.ActionResponse; import org.elasticsearch.action.ActionResponse;
@ -19,29 +25,23 @@ import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.ThreadContext; import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.elasticsearch.license.LicenseUtils; import org.elasticsearch.license.LicenseUtils;
import org.elasticsearch.xpack.security.Security; import org.elasticsearch.license.XPackLicenseState;
import org.elasticsearch.tasks.Task;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.xpack.XPackPlugin;
import org.elasticsearch.xpack.security.SecurityContext; import org.elasticsearch.xpack.security.SecurityContext;
import org.elasticsearch.xpack.security.action.SecurityActionMapper; import org.elasticsearch.xpack.security.action.SecurityActionMapper;
import org.elasticsearch.xpack.security.action.interceptor.RequestInterceptor;
import org.elasticsearch.xpack.security.audit.AuditTrail;
import org.elasticsearch.xpack.security.audit.AuditTrailService; import org.elasticsearch.xpack.security.audit.AuditTrailService;
import org.elasticsearch.xpack.security.authc.Authentication; import org.elasticsearch.xpack.security.authc.Authentication;
import org.elasticsearch.xpack.security.authc.AuthenticationService; import org.elasticsearch.xpack.security.authc.AuthenticationService;
import org.elasticsearch.xpack.security.authz.AuthorizationService; import org.elasticsearch.xpack.security.authz.AuthorizationService;
import org.elasticsearch.xpack.security.user.SystemUser;
import org.elasticsearch.xpack.security.user.User;
import org.elasticsearch.xpack.security.action.interceptor.RequestInterceptor;
import org.elasticsearch.xpack.security.audit.AuditTrail;
import org.elasticsearch.xpack.security.authz.AuthorizationUtils; import org.elasticsearch.xpack.security.authz.AuthorizationUtils;
import org.elasticsearch.xpack.security.authz.privilege.HealthAndStatsPrivilege; import org.elasticsearch.xpack.security.authz.privilege.HealthAndStatsPrivilege;
import org.elasticsearch.xpack.security.crypto.CryptoService; import org.elasticsearch.xpack.security.crypto.CryptoService;
import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.xpack.security.user.SystemUser;
import org.elasticsearch.tasks.Task; import org.elasticsearch.xpack.security.user.User;
import org.elasticsearch.threadpool.ThreadPool;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.function.Predicate;
import static org.elasticsearch.xpack.security.support.Exceptions.authorizationError; import static org.elasticsearch.xpack.security.support.Exceptions.authorizationError;
@ -87,7 +87,7 @@ public class SecurityActionFilter extends AbstractComponent implements ActionFil
logger.error("blocking [{}] operation due to expired license. Cluster health, cluster stats and indices stats \n" + logger.error("blocking [{}] operation due to expired license. Cluster health, cluster stats and indices stats \n" +
"operations are blocked on license expiration. All data operations (read and write) continue to work. \n" + "operations are blocked on license expiration. All data operations (read and write) continue to work. \n" +
"If you have a new license, please update it. Otherwise, please reach out to your support contact.", action); "If you have a new license, please update it. Otherwise, please reach out to your support contact.", action);
throw LicenseUtils.newComplianceException(Security.NAME); throw LicenseUtils.newComplianceException(XPackPlugin.SECURITY);
} }
// only restore the context if it is not empty. This is needed because sometimes a response is sent to the user // only restore the context if it is not empty. This is needed because sometimes a response is sent to the user

View File

@ -16,6 +16,7 @@ import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.license.XPackLicenseState;
import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.transport.TransportMessage; import org.elasticsearch.transport.TransportMessage;
import org.elasticsearch.xpack.XPackSettings;
import org.elasticsearch.xpack.security.Security; import org.elasticsearch.xpack.security.Security;
import org.elasticsearch.xpack.security.authc.AuthenticationToken; import org.elasticsearch.xpack.security.authc.AuthenticationToken;
import org.elasticsearch.xpack.security.transport.filter.SecurityIpFilterRule; import org.elasticsearch.xpack.security.transport.filter.SecurityIpFilterRule;
@ -209,7 +210,7 @@ public class AuditTrailService extends AbstractComponent implements AuditTrail {
public Map<String, Object> usageStats() { public Map<String, Object> usageStats() {
Map<String, Object> map = new HashMap<>(2); Map<String, Object> map = new HashMap<>(2);
map.put("enabled", Security.AUDIT_ENABLED_SETTING.get(settings)); map.put("enabled", XPackSettings.AUDIT_ENABLED.get(settings));
map.put("outputs", Security.AUDIT_OUTPUTS_SETTING.get(settings)); map.put("outputs", Security.AUDIT_OUTPUTS_SETTING.get(settings));
return map; return map;
} }

View File

@ -32,7 +32,7 @@ import org.elasticsearch.watcher.FileChangesListener;
import org.elasticsearch.watcher.FileWatcher; import org.elasticsearch.watcher.FileWatcher;
import org.elasticsearch.watcher.ResourceWatcherService; import org.elasticsearch.watcher.ResourceWatcherService;
import org.elasticsearch.xpack.XPackPlugin; import org.elasticsearch.xpack.XPackPlugin;
import org.elasticsearch.xpack.security.Security; import org.elasticsearch.xpack.XPackSettings;
import org.elasticsearch.xpack.security.authc.support.RefreshListener; import org.elasticsearch.xpack.security.authc.support.RefreshListener;
import org.elasticsearch.xpack.security.authz.RoleDescriptor; import org.elasticsearch.xpack.security.authz.RoleDescriptor;
import org.elasticsearch.xpack.security.authz.permission.IndicesPermission.Group; import org.elasticsearch.xpack.security.authz.permission.IndicesPermission.Group;
@ -201,10 +201,10 @@ public class FileRolesStore extends AbstractLifecycleComponent implements RolesS
// first check if FLS/DLS is enabled on the role... // first check if FLS/DLS is enabled on the role...
for (RoleDescriptor.IndicesPrivileges privilege : descriptor.getIndicesPrivileges()) { for (RoleDescriptor.IndicesPrivileges privilege : descriptor.getIndicesPrivileges()) {
if ((privilege.getQuery() != null || privilege.getFields() != null) if ((privilege.getQuery() != null || privilege.getFields() != null)
&& Security.flsDlsEnabled(settings) == false) { && XPackSettings.DLS_FLS_ENABLED.get(settings) == false) {
logger.error("invalid role definition [{}] in roles file [{}]. document and field level security is not " + logger.error("invalid role definition [{}] in roles file [{}]. document and field level security is not " +
"enabled. set [{}] to [true] in the configuration file. skipping role...", roleName, path "enabled. set [{}] to [true] in the configuration file. skipping role...", roleName, path
.toAbsolutePath(), XPackPlugin.featureEnabledSetting(Security.DLS_FLS_FEATURE)); .toAbsolutePath(), XPackSettings.DLS_FLS_ENABLED.getKey());
return null; return null;
} }
} }

View File

@ -9,7 +9,7 @@ import org.elasticsearch.client.Client;
import org.elasticsearch.client.transport.TransportClient; import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.inject.AbstractModule; import org.elasticsearch.common.inject.AbstractModule;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.xpack.security.Security; import org.elasticsearch.xpack.XPackSettings;
/** /**
* *
@ -23,7 +23,7 @@ public abstract class AbstractSecurityModule extends AbstractModule {
public AbstractSecurityModule(Settings settings) { public AbstractSecurityModule(Settings settings) {
this.settings = settings; this.settings = settings;
this.clientMode = TransportClient.CLIENT_TYPE.equals(settings.get(Client.CLIENT_TYPE_SETTING_S.getKey())); this.clientMode = TransportClient.CLIENT_TYPE.equals(settings.get(Client.CLIENT_TYPE_SETTING_S.getKey()));
this.securityEnabled = Security.enabled(settings); this.securityEnabled = XPackSettings.SECURITY_ENABLED.get(settings);
} }
@Override @Override

View File

@ -7,7 +7,7 @@ package org.elasticsearch.xpack.security.support;
import org.elasticsearch.ElasticsearchSecurityException; import org.elasticsearch.ElasticsearchSecurityException;
import org.elasticsearch.rest.RestStatus; import org.elasticsearch.rest.RestStatus;
import org.elasticsearch.xpack.security.Security; import org.elasticsearch.xpack.XPackPlugin;
/** /**
* *
@ -19,13 +19,13 @@ public class Exceptions {
public static ElasticsearchSecurityException authenticationError(String msg, Throwable cause, Object... args) { public static ElasticsearchSecurityException authenticationError(String msg, Throwable cause, Object... args) {
ElasticsearchSecurityException e = new ElasticsearchSecurityException(msg, RestStatus.UNAUTHORIZED, cause, args); ElasticsearchSecurityException e = new ElasticsearchSecurityException(msg, RestStatus.UNAUTHORIZED, cause, args);
e.addHeader("WWW-Authenticate", "Basic realm=\"" + Security.NAME + "\" charset=\"UTF-8\""); e.addHeader("WWW-Authenticate", "Basic realm=\"" + XPackPlugin.SECURITY + "\" charset=\"UTF-8\"");
return e; return e;
} }
public static ElasticsearchSecurityException authenticationError(String msg, Object... args) { public static ElasticsearchSecurityException authenticationError(String msg, Object... args) {
ElasticsearchSecurityException e = new ElasticsearchSecurityException(msg, RestStatus.UNAUTHORIZED, args); ElasticsearchSecurityException e = new ElasticsearchSecurityException(msg, RestStatus.UNAUTHORIZED, args);
e.addHeader("WWW-Authenticate", "Basic realm=\"" + Security.NAME + "\" charset=\"UTF-8\""); e.addHeader("WWW-Authenticate", "Basic realm=\"" + XPackPlugin.SECURITY + "\" charset=\"UTF-8\"");
return e; return e;
} }

View File

@ -35,7 +35,6 @@ import java.io.IOException;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.util.List; import java.util.List;
import static org.elasticsearch.xpack.security.Security.featureEnabledSetting;
import static org.elasticsearch.xpack.security.Security.setting; import static org.elasticsearch.xpack.security.Security.setting;
import static org.elasticsearch.xpack.security.Security.settingPrefix; import static org.elasticsearch.xpack.security.Security.settingPrefix;
import static org.elasticsearch.xpack.security.transport.SSLExceptionHelper.isCloseDuringHandshakeException; import static org.elasticsearch.xpack.security.transport.SSLExceptionHelper.isCloseDuringHandshakeException;
@ -53,7 +52,7 @@ public class SecurityNetty3Transport extends Netty3Transport {
new Property[]{Property.NodeScope, Property.Filtered, Property.Deprecated, Property.Shared}); new Property[]{Property.NodeScope, Property.Filtered, Property.Deprecated, Property.Shared});
public static final Setting<Boolean> HOSTNAME_VERIFICATION_SETTING = public static final Setting<Boolean> HOSTNAME_VERIFICATION_SETTING =
Setting.boolSetting(featureEnabledSetting("ssl.hostname_verification"), DEPRECATED_HOSTNAME_VERIFICATION_SETTING, Setting.boolSetting(setting("ssl.hostname_verification.enabled"), DEPRECATED_HOSTNAME_VERIFICATION_SETTING,
Property.NodeScope, Property.Filtered, Property.Shared); Property.NodeScope, Property.Filtered, Property.Shared);
public static final Setting<Boolean> HOSTNAME_VERIFICATION_RESOLVE_NAME_SETTING = public static final Setting<Boolean> HOSTNAME_VERIFICATION_RESOLVE_NAME_SETTING =

View File

@ -40,7 +40,6 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import static org.elasticsearch.xpack.security.Security.featureEnabledSetting;
import static org.elasticsearch.xpack.security.Security.setting; import static org.elasticsearch.xpack.security.Security.setting;
import static org.elasticsearch.xpack.security.Security.settingPrefix; import static org.elasticsearch.xpack.security.Security.settingPrefix;
@ -60,7 +59,7 @@ public class SecurityNetty4Transport extends Netty4Transport {
new Property[]{Property.NodeScope, Property.Filtered, Property.Deprecated, Property.Shared}); new Property[]{Property.NodeScope, Property.Filtered, Property.Deprecated, Property.Shared});
public static final Setting<Boolean> HOSTNAME_VERIFICATION_SETTING = public static final Setting<Boolean> HOSTNAME_VERIFICATION_SETTING =
Setting.boolSetting(featureEnabledSetting("ssl.hostname_verification"), DEPRECATED_HOSTNAME_VERIFICATION_SETTING, Setting.boolSetting(setting("ssl.hostname_verification.enabled"), DEPRECATED_HOSTNAME_VERIFICATION_SETTING,
Property.NodeScope, Property.Filtered, Property.Shared); Property.NodeScope, Property.Filtered, Property.Shared);
public static final Setting<Boolean> HOSTNAME_VERIFICATION_RESOLVE_NAME_SETTING = public static final Setting<Boolean> HOSTNAME_VERIFICATION_RESOLVE_NAME_SETTING =

View File

@ -18,8 +18,7 @@ import org.elasticsearch.common.network.NetworkModule;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.test.SecurityIntegTestCase; import org.elasticsearch.test.SecurityIntegTestCase;
import org.elasticsearch.test.SecuritySettingsSource; import org.elasticsearch.test.SecuritySettingsSource;
import org.elasticsearch.xpack.XPackPlugin; import org.elasticsearch.xpack.XPackSettings;
import org.elasticsearch.xpack.security.Security;
import org.elasticsearch.xpack.security.authc.support.SecuredString; import org.elasticsearch.xpack.security.authc.support.SecuredString;
import org.elasticsearch.xpack.security.authc.support.UsernamePasswordToken; import org.elasticsearch.xpack.security.authc.support.UsernamePasswordToken;
@ -36,7 +35,7 @@ public class BulkUpdateTests extends SecurityIntegTestCase {
return Settings.builder() return Settings.builder()
.put(super.nodeSettings(nodeOrdinal)) .put(super.nodeSettings(nodeOrdinal))
.put(NetworkModule.HTTP_ENABLED.getKey(), true) .put(NetworkModule.HTTP_ENABLED.getKey(), true)
.put(XPackPlugin.featureEnabledSetting(Security.DLS_FLS_FEATURE), randomBoolean()) .put(XPackSettings.DLS_FLS_ENABLED.getKey(), randomBoolean())
.build(); .build();
} }

View File

@ -8,14 +8,12 @@ package org.elasticsearch.integration;
import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.IndexModule; import org.elasticsearch.index.IndexModule;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.sort.SortOrder; import org.elasticsearch.search.sort.SortOrder;
import org.elasticsearch.xpack.security.Security; import org.elasticsearch.xpack.XPackSettings;
import org.elasticsearch.xpack.security.authc.support.Hasher; import org.elasticsearch.xpack.security.authc.support.Hasher;
import org.elasticsearch.xpack.security.authc.support.SecuredString; import org.elasticsearch.xpack.security.authc.support.SecuredString;
import org.elasticsearch.test.SecurityIntegTestCase; import org.elasticsearch.test.SecurityIntegTestCase;
import org.elasticsearch.xpack.XPackPlugin;
import java.util.Collections; import java.util.Collections;
@ -89,7 +87,7 @@ public class DocumentAndFieldLevelSecurityTests extends SecurityIntegTestCase {
public Settings nodeSettings(int nodeOrdinal) { public Settings nodeSettings(int nodeOrdinal) {
return Settings.builder() return Settings.builder()
.put(super.nodeSettings(nodeOrdinal)) .put(super.nodeSettings(nodeOrdinal))
.put(XPackPlugin.featureEnabledSetting(Security.DLS_FLS_FEATURE), true) .put(XPackSettings.DLS_FLS_ENABLED.getKey(), true)
.build(); .build();
} }

View File

@ -10,11 +10,10 @@ import org.elasticsearch.action.index.IndexRequestBuilder;
import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.xpack.security.Security; import org.elasticsearch.xpack.XPackSettings;
import org.elasticsearch.xpack.security.authc.support.Hasher; import org.elasticsearch.xpack.security.authc.support.Hasher;
import org.elasticsearch.xpack.security.authc.support.SecuredString; import org.elasticsearch.xpack.security.authc.support.SecuredString;
import org.elasticsearch.test.SecurityIntegTestCase; import org.elasticsearch.test.SecurityIntegTestCase;
import org.elasticsearch.xpack.XPackPlugin;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
@ -88,7 +87,7 @@ public class DocumentLevelSecurityRandomTests extends SecurityIntegTestCase {
public Settings nodeSettings(int nodeOrdinal) { public Settings nodeSettings(int nodeOrdinal) {
return Settings.builder() return Settings.builder()
.put(super.nodeSettings(nodeOrdinal)) .put(super.nodeSettings(nodeOrdinal))
.put(XPackPlugin.featureEnabledSetting(Security.DLS_FLS_FEATURE), true) .put(XPackSettings.DLS_FLS_ENABLED.getKey(), true)
.build(); .build();
} }

View File

@ -25,11 +25,10 @@ import org.elasticsearch.search.aggregations.bucket.children.Children;
import org.elasticsearch.search.aggregations.bucket.global.Global; import org.elasticsearch.search.aggregations.bucket.global.Global;
import org.elasticsearch.search.aggregations.bucket.terms.Terms; import org.elasticsearch.search.aggregations.bucket.terms.Terms;
import org.elasticsearch.search.sort.SortOrder; import org.elasticsearch.search.sort.SortOrder;
import org.elasticsearch.xpack.security.Security; import org.elasticsearch.xpack.XPackSettings;
import org.elasticsearch.xpack.security.authc.support.Hasher; import org.elasticsearch.xpack.security.authc.support.Hasher;
import org.elasticsearch.xpack.security.authc.support.SecuredString; import org.elasticsearch.xpack.security.authc.support.SecuredString;
import org.elasticsearch.test.SecurityIntegTestCase; import org.elasticsearch.test.SecurityIntegTestCase;
import org.elasticsearch.xpack.XPackPlugin;
import java.util.Collections; import java.util.Collections;
@ -100,7 +99,7 @@ public class DocumentLevelSecurityTests extends SecurityIntegTestCase {
public Settings nodeSettings(int nodeOrdinal) { public Settings nodeSettings(int nodeOrdinal) {
return Settings.builder() return Settings.builder()
.put(super.nodeSettings(nodeOrdinal)) .put(super.nodeSettings(nodeOrdinal))
.put(XPackPlugin.featureEnabledSetting(Security.DLS_FLS_FEATURE), true) .put(XPackSettings.DLS_FLS_ENABLED.getKey(), true)
.build(); .build();
} }

View File

@ -10,11 +10,10 @@ import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.sort.SortOrder; import org.elasticsearch.search.sort.SortOrder;
import org.elasticsearch.xpack.security.Security; import org.elasticsearch.xpack.XPackSettings;
import org.elasticsearch.xpack.security.authc.support.Hasher; import org.elasticsearch.xpack.security.authc.support.Hasher;
import org.elasticsearch.xpack.security.authc.support.SecuredString; import org.elasticsearch.xpack.security.authc.support.SecuredString;
import org.elasticsearch.test.SecurityIntegTestCase; import org.elasticsearch.test.SecurityIntegTestCase;
import org.elasticsearch.xpack.XPackPlugin;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
@ -121,7 +120,7 @@ public class FieldLevelSecurityRandomTests extends SecurityIntegTestCase {
public Settings nodeSettings(int nodeOrdinal) { public Settings nodeSettings(int nodeOrdinal) {
return Settings.builder() return Settings.builder()
.put(super.nodeSettings(nodeOrdinal)) .put(super.nodeSettings(nodeOrdinal))
.put(XPackPlugin.featureEnabledSetting(Security.DLS_FLS_FEATURE), true) .put(XPackSettings.DLS_FLS_ENABLED.getKey(), true)
.build(); .build();
} }

View File

@ -23,12 +23,11 @@ import org.elasticsearch.rest.RestStatus;
import org.elasticsearch.search.aggregations.AggregationBuilders; import org.elasticsearch.search.aggregations.AggregationBuilders;
import org.elasticsearch.search.aggregations.bucket.terms.Terms; import org.elasticsearch.search.aggregations.bucket.terms.Terms;
import org.elasticsearch.search.sort.SortOrder; import org.elasticsearch.search.sort.SortOrder;
import org.elasticsearch.xpack.security.Security; import org.elasticsearch.xpack.XPackSettings;
import org.elasticsearch.xpack.security.authc.support.Hasher; import org.elasticsearch.xpack.security.authc.support.Hasher;
import org.elasticsearch.xpack.security.authc.support.SecuredString; import org.elasticsearch.xpack.security.authc.support.SecuredString;
import org.elasticsearch.test.ESIntegTestCase; import org.elasticsearch.test.ESIntegTestCase;
import org.elasticsearch.test.SecurityIntegTestCase; import org.elasticsearch.test.SecurityIntegTestCase;
import org.elasticsearch.xpack.XPackPlugin;
import java.util.Collections; import java.util.Collections;
@ -129,7 +128,7 @@ public class FieldLevelSecurityTests extends SecurityIntegTestCase {
public Settings nodeSettings(int nodeOrdinal) { public Settings nodeSettings(int nodeOrdinal) {
return Settings.builder() return Settings.builder()
.put(super.nodeSettings(nodeOrdinal)) .put(super.nodeSettings(nodeOrdinal))
.put(XPackPlugin.featureEnabledSetting(Security.DLS_FLS_FEATURE), true) .put(XPackSettings.DLS_FLS_ENABLED.getKey(), true)
.build(); .build();
} }

View File

@ -8,11 +8,10 @@ package org.elasticsearch.integration;
import org.elasticsearch.action.admin.indices.alias.Alias; import org.elasticsearch.action.admin.indices.alias.Alias;
import org.elasticsearch.action.get.GetResponse; import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.xpack.security.Security; import org.elasticsearch.xpack.XPackSettings;
import org.elasticsearch.xpack.security.authc.support.Hasher; import org.elasticsearch.xpack.security.authc.support.Hasher;
import org.elasticsearch.xpack.security.authc.support.SecuredString; import org.elasticsearch.xpack.security.authc.support.SecuredString;
import org.elasticsearch.test.SecurityIntegTestCase; import org.elasticsearch.test.SecurityIntegTestCase;
import org.elasticsearch.xpack.XPackPlugin;
import java.util.Collections; import java.util.Collections;
@ -62,7 +61,7 @@ public class IndicesPermissionsWithAliasesWildcardsAndRegexsTests extends Securi
public Settings nodeSettings(int nodeOrdinal) { public Settings nodeSettings(int nodeOrdinal) {
return Settings.builder() return Settings.builder()
.put(super.nodeSettings(nodeOrdinal)) .put(super.nodeSettings(nodeOrdinal))
.put(XPackPlugin.featureEnabledSetting(Security.DLS_FLS_FEATURE), true) .put(XPackSettings.DLS_FLS_ENABLED.getKey(), true)
.build(); .build();
} }

View File

@ -31,6 +31,7 @@ import org.elasticsearch.test.SecuritySettingsSource;
import org.elasticsearch.transport.Netty3Plugin; import org.elasticsearch.transport.Netty3Plugin;
import org.elasticsearch.transport.Netty4Plugin; import org.elasticsearch.transport.Netty4Plugin;
import org.elasticsearch.transport.Transport; import org.elasticsearch.transport.Transport;
import org.elasticsearch.xpack.XPackPlugin;
import org.elasticsearch.xpack.XPackTransportClient; import org.elasticsearch.xpack.XPackTransportClient;
import org.elasticsearch.xpack.security.Security; import org.elasticsearch.xpack.security.Security;
import org.elasticsearch.xpack.security.authc.support.UsernamePasswordToken; import org.elasticsearch.xpack.security.authc.support.UsernamePasswordToken;
@ -197,7 +198,7 @@ public class LicensingTests extends SecurityIntegTestCase {
private static void assertElasticsearchSecurityException(ThrowingRunnable runnable) { private static void assertElasticsearchSecurityException(ThrowingRunnable runnable) {
ElasticsearchSecurityException ee = expectThrows(ElasticsearchSecurityException.class, runnable); ElasticsearchSecurityException ee = expectThrows(ElasticsearchSecurityException.class, runnable);
assertThat(ee.getHeader("es.license.expired.feature"), hasItem(Security.NAME)); assertThat(ee.getHeader("es.license.expired.feature"), hasItem(XPackPlugin.SECURITY));
assertThat(ee.status(), is(RestStatus.FORBIDDEN)); assertThat(ee.status(), is(RestStatus.FORBIDDEN));
} }

View File

@ -11,13 +11,13 @@ import java.util.stream.Collectors;
import org.elasticsearch.license.License.OperationMode; import org.elasticsearch.license.License.OperationMode;
import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.xpack.XPackPlugin;
import org.elasticsearch.xpack.monitoring.Monitoring; import org.elasticsearch.xpack.monitoring.Monitoring;
import org.elasticsearch.xpack.security.Security;
import org.hamcrest.Matchers; import org.hamcrest.Matchers;
import static org.elasticsearch.license.License.OperationMode.MISSING;
import static org.elasticsearch.license.License.OperationMode.BASIC; import static org.elasticsearch.license.License.OperationMode.BASIC;
import static org.elasticsearch.license.License.OperationMode.GOLD; import static org.elasticsearch.license.License.OperationMode.GOLD;
import static org.elasticsearch.license.License.OperationMode.MISSING;
import static org.elasticsearch.license.License.OperationMode.PLATINUM; import static org.elasticsearch.license.License.OperationMode.PLATINUM;
import static org.elasticsearch.license.License.OperationMode.STANDARD; import static org.elasticsearch.license.License.OperationMode.STANDARD;
import static org.elasticsearch.license.License.OperationMode.TRIAL; import static org.elasticsearch.license.License.OperationMode.TRIAL;
@ -168,25 +168,25 @@ public class XPackLicenseStateTests extends ESTestCase {
public void testSecurityAckBasicToNotGoldOrStandard() { public void testSecurityAckBasicToNotGoldOrStandard() {
OperationMode toMode = randomFrom(OperationMode.values(), mode -> mode != GOLD && mode != STANDARD); OperationMode toMode = randomFrom(OperationMode.values(), mode -> mode != GOLD && mode != STANDARD);
assertAckMesssages(Security.NAME, BASIC, toMode, 0); assertAckMesssages(XPackPlugin.SECURITY, BASIC, toMode, 0);
} }
public void testSecurityAckAnyToTrialOrPlatinum() { public void testSecurityAckAnyToTrialOrPlatinum() {
assertAckMesssages(Security.NAME, randomMode(), randomTrialOrPlatinumMode(), 0); assertAckMesssages(XPackPlugin.SECURITY, randomMode(), randomTrialOrPlatinumMode(), 0);
} }
public void testSecurityAckTrialStandardGoldOrPlatinumToBasic() { public void testSecurityAckTrialStandardGoldOrPlatinumToBasic() {
assertAckMesssages(Security.NAME, randomTrialStandardGoldOrPlatinumMode(), BASIC, 3); assertAckMesssages(XPackPlugin.SECURITY, randomTrialStandardGoldOrPlatinumMode(), BASIC, 3);
} }
public void testSecurityAckAnyToStandard() { public void testSecurityAckAnyToStandard() {
OperationMode from = randomFrom(BASIC, GOLD, PLATINUM, TRIAL); OperationMode from = randomFrom(BASIC, GOLD, PLATINUM, TRIAL);
assertAckMesssages(Security.NAME, from, STANDARD, 4); assertAckMesssages(XPackPlugin.SECURITY, from, STANDARD, 4);
} }
public void testSecurityAckBasicStandardTrialOrPlatinumToGold() { public void testSecurityAckBasicStandardTrialOrPlatinumToGold() {
OperationMode from = randomFrom(BASIC, PLATINUM, TRIAL, STANDARD); OperationMode from = randomFrom(BASIC, PLATINUM, TRIAL, STANDARD);
assertAckMesssages(Security.NAME, from, GOLD, 2); assertAckMesssages(XPackPlugin.SECURITY, from, GOLD, 2);
} }
public void testMonitoringAckBasicToAny() { public void testMonitoringAckBasicToAny() {

View File

@ -11,9 +11,9 @@ import org.elasticsearch.common.io.PathUtils;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.ThreadContext; import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.elasticsearch.discovery.DiscoveryModule; import org.elasticsearch.discovery.DiscoveryModule;
import org.elasticsearch.xpack.XPackSettings;
import org.elasticsearch.transport.Netty3Plugin; import org.elasticsearch.transport.Netty3Plugin;
import org.elasticsearch.transport.Netty4Plugin; import org.elasticsearch.transport.Netty4Plugin;
import org.elasticsearch.xpack.monitoring.Monitoring;
import org.elasticsearch.plugins.Plugin; import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.test.ESIntegTestCase.Scope; import org.elasticsearch.test.ESIntegTestCase.Scope;
import org.elasticsearch.xpack.security.authc.file.FileRealm; import org.elasticsearch.xpack.security.authc.file.FileRealm;
@ -28,7 +28,6 @@ import org.elasticsearch.xpack.security.test.SecurityTestUtils;
import org.elasticsearch.xpack.security.transport.netty3.SecurityNetty3HttpServerTransport; import org.elasticsearch.xpack.security.transport.netty3.SecurityNetty3HttpServerTransport;
import org.elasticsearch.xpack.security.transport.netty3.SecurityNetty3Transport; import org.elasticsearch.xpack.security.transport.netty3.SecurityNetty3Transport;
import org.elasticsearch.test.discovery.ClusterDiscoveryConfiguration; import org.elasticsearch.test.discovery.ClusterDiscoveryConfiguration;
import org.elasticsearch.xpack.watcher.Watcher;
import org.elasticsearch.xpack.XPackPlugin; import org.elasticsearch.xpack.XPackPlugin;
import java.net.URISyntaxException; import java.net.URISyntaxException;
@ -127,9 +126,9 @@ public class SecuritySettingsSource extends ClusterDiscoveryConfiguration.Unicas
Settings.Builder builder = Settings.builder().put(super.nodeSettings(nodeOrdinal)) Settings.Builder builder = Settings.builder().put(super.nodeSettings(nodeOrdinal))
//TODO: for now isolate security tests from watcher & monitoring (randomize this later) //TODO: for now isolate security tests from watcher & monitoring (randomize this later)
.put(XPackPlugin.featureEnabledSetting(Watcher.NAME), false) .put(XPackSettings.WATCHER_ENABLED.getKey(), false)
.put(XPackPlugin.featureEnabledSetting(Monitoring.NAME), false) .put(XPackSettings.MONITORING_ENABLED.getKey(), false)
.put(Security.AUDIT_ENABLED_SETTING.getKey(), randomBoolean()) .put(XPackSettings.AUDIT_ENABLED.getKey(), randomBoolean())
.put(LoggingAuditTrail.HOST_ADDRESS_SETTING.getKey(), randomBoolean()) .put(LoggingAuditTrail.HOST_ADDRESS_SETTING.getKey(), randomBoolean())
.put(LoggingAuditTrail.HOST_NAME_SETTING.getKey(), randomBoolean()) .put(LoggingAuditTrail.HOST_NAME_SETTING.getKey(), randomBoolean())
.put(LoggingAuditTrail.NODE_NAME_SETTING.getKey(), randomBoolean()) .put(LoggingAuditTrail.NODE_NAME_SETTING.getKey(), randomBoolean())

View File

@ -5,13 +5,13 @@
*/ */
package org.elasticsearch.transport; package org.elasticsearch.transport;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.xpack.security.Security;
import org.elasticsearch.xpack.security.transport.SecurityServerTransportService;
import org.elasticsearch.test.SecurityIntegTestCase;
import java.util.Map; import java.util.Map;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.test.SecurityIntegTestCase;
import org.elasticsearch.xpack.XPackSettings;
import org.elasticsearch.xpack.security.transport.SecurityServerTransportService;
import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.startsWith; import static org.hamcrest.Matchers.startsWith;
@ -21,7 +21,7 @@ public class SecurityServerTransportServiceTests extends SecurityIntegTestCase {
protected Settings transportClientSettings() { protected Settings transportClientSettings() {
return Settings.builder() return Settings.builder()
.put(super.transportClientSettings()) .put(super.transportClientSettings())
.put(Security.enabledSetting(), true) .put(XPackSettings.SECURITY_ENABLED.getKey(), true)
.build(); .build();
} }

View File

@ -15,6 +15,7 @@ import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.license.XPackLicenseState;
import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.xpack.XPackFeatureSet; import org.elasticsearch.xpack.XPackFeatureSet;
import org.elasticsearch.xpack.XPackPlugin;
import org.elasticsearch.xpack.security.audit.AuditTrailService; import org.elasticsearch.xpack.security.audit.AuditTrailService;
import org.elasticsearch.xpack.security.authc.Realms; import org.elasticsearch.xpack.security.authc.Realms;
import org.elasticsearch.xpack.security.authz.store.CompositeRolesStore; import org.elasticsearch.xpack.security.authz.store.CompositeRolesStore;
@ -157,7 +158,7 @@ public class SecurityFeatureSetTests extends ESTestCase {
ipFilter, auditTrail, cryptoService); ipFilter, auditTrail, cryptoService);
XPackFeatureSet.Usage usage = featureSet.usage(); XPackFeatureSet.Usage usage = featureSet.usage();
assertThat(usage, is(notNullValue())); assertThat(usage, is(notNullValue()));
assertThat(usage.name(), is(Security.NAME)); assertThat(usage.name(), is(XPackPlugin.SECURITY));
assertThat(usage.enabled(), is(enabled)); assertThat(usage.enabled(), is(enabled));
assertThat(usage.available(), is(authcAuthzAvailable)); assertThat(usage.available(), is(authcAuthzAvailable));
XContentSource source = new XContentSource(usage); XContentSource source = new XContentSource(usage);

View File

@ -9,9 +9,10 @@ import java.io.IOException;
import org.elasticsearch.common.Strings; import org.elasticsearch.common.Strings;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.xpack.security.audit.index.IndexAuditTrail;
import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.xpack.XPackPlugin; import org.elasticsearch.xpack.XPackPlugin;
import org.elasticsearch.xpack.XPackSettings;
import org.elasticsearch.xpack.security.audit.index.IndexAuditTrail;
import static org.hamcrest.CoreMatchers.containsString; import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.equalTo;
@ -23,8 +24,8 @@ import static org.hamcrest.Matchers.not;
public class SecuritySettingsTests extends ESTestCase { public class SecuritySettingsTests extends ESTestCase {
private static final String TRIBE_T1_SECURITY_ENABLED = "tribe.t1." + Security.enabledSetting(); private static final String TRIBE_T1_SECURITY_ENABLED = "tribe.t1." + XPackSettings.SECURITY_ENABLED.getKey();
private static final String TRIBE_T2_SECURITY_ENABLED = "tribe.t2." + Security.enabledSetting(); private static final String TRIBE_T2_SECURITY_ENABLED = "tribe.t2." + XPackSettings.SECURITY_ENABLED.getKey();
public void testSecurityIsMandatoryOnTribes() throws IOException { public void testSecurityIsMandatoryOnTribes() throws IOException {
Settings settings = Settings.builder().put("tribe.t1.cluster.name", "non_existing") Settings settings = Settings.builder().put("tribe.t1.cluster.name", "non_existing")
@ -157,13 +158,13 @@ public class SecuritySettingsTests extends ESTestCase {
Security.validateAutoCreateIndex(Settings.builder() Security.validateAutoCreateIndex(Settings.builder()
.put("action.auto_create_index", ".security") .put("action.auto_create_index", ".security")
.put(Security.AUDIT_ENABLED_SETTING.getKey(), true) .put(XPackSettings.AUDIT_ENABLED.getKey(), true)
.build()); .build());
try { try {
Security.validateAutoCreateIndex(Settings.builder() Security.validateAutoCreateIndex(Settings.builder()
.put("action.auto_create_index", ".security") .put("action.auto_create_index", ".security")
.put(Security.AUDIT_ENABLED_SETTING.getKey(), true) .put(XPackSettings.AUDIT_ENABLED.getKey(), true)
.put(Security.AUDIT_OUTPUTS_SETTING.getKey(), randomFrom("index", "logfile,index")) .put(Security.AUDIT_OUTPUTS_SETTING.getKey(), randomFrom("index", "logfile,index"))
.build()); .build());
fail("IllegalArgumentException expected"); fail("IllegalArgumentException expected");
@ -174,7 +175,7 @@ public class SecuritySettingsTests extends ESTestCase {
Security.validateAutoCreateIndex(Settings.builder() Security.validateAutoCreateIndex(Settings.builder()
.put("action.auto_create_index", ".security_audit_log*,.security") .put("action.auto_create_index", ".security_audit_log*,.security")
.put(Security.AUDIT_ENABLED_SETTING.getKey(), true) .put(XPackSettings.AUDIT_ENABLED.getKey(), true)
.put(Security.AUDIT_OUTPUTS_SETTING.getKey(), randomFrom("index", "logfile,index")) .put(Security.AUDIT_OUTPUTS_SETTING.getKey(), randomFrom("index", "logfile,index"))
.build()); .build());
} }

View File

@ -18,6 +18,7 @@ import org.elasticsearch.env.Environment;
import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.license.XPackLicenseState;
import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.xpack.XPackSettings;
import org.elasticsearch.xpack.extensions.XPackExtension; import org.elasticsearch.xpack.extensions.XPackExtension;
import org.elasticsearch.xpack.security.audit.AuditTrailService; import org.elasticsearch.xpack.security.audit.AuditTrailService;
import org.elasticsearch.xpack.security.audit.index.IndexAuditTrail; import org.elasticsearch.xpack.security.audit.index.IndexAuditTrail;
@ -84,7 +85,7 @@ public class SecurityTests extends ESTestCase {
public void testAuditEnabled() throws Exception { public void testAuditEnabled() throws Exception {
Settings settings = Settings.builder().put(Security.AUDIT_ENABLED_SETTING.getKey(), true).build(); Settings settings = Settings.builder().put(XPackSettings.AUDIT_ENABLED.getKey(), true).build();
Collection<Object> components = createComponents(settings); Collection<Object> components = createComponents(settings);
AuditTrailService service = findComponent(AuditTrailService.class, components); AuditTrailService service = findComponent(AuditTrailService.class, components);
assertNotNull(service); assertNotNull(service);
@ -100,7 +101,7 @@ public class SecurityTests extends ESTestCase {
public void testIndexAuditTrail() throws Exception { public void testIndexAuditTrail() throws Exception {
Settings settings = Settings.builder() Settings settings = Settings.builder()
.put(Security.AUDIT_ENABLED_SETTING.getKey(), true) .put(XPackSettings.AUDIT_ENABLED.getKey(), true)
.put(Security.AUDIT_OUTPUTS_SETTING.getKey(), "index").build(); .put(Security.AUDIT_OUTPUTS_SETTING.getKey(), "index").build();
Collection<Object> components = createComponents(settings); Collection<Object> components = createComponents(settings);
AuditTrailService service = findComponent(AuditTrailService.class, components); AuditTrailService service = findComponent(AuditTrailService.class, components);
@ -111,7 +112,7 @@ public class SecurityTests extends ESTestCase {
public void testIndexAndLoggingAuditTrail() throws Exception { public void testIndexAndLoggingAuditTrail() throws Exception {
Settings settings = Settings.builder() Settings settings = Settings.builder()
.put(Security.AUDIT_ENABLED_SETTING.getKey(), true) .put(XPackSettings.AUDIT_ENABLED.getKey(), true)
.put(Security.AUDIT_OUTPUTS_SETTING.getKey(), "index,logfile").build(); .put(Security.AUDIT_OUTPUTS_SETTING.getKey(), "index,logfile").build();
Collection<Object> components = createComponents(settings); Collection<Object> components = createComponents(settings);
AuditTrailService service = findComponent(AuditTrailService.class, components); AuditTrailService service = findComponent(AuditTrailService.class, components);
@ -123,7 +124,7 @@ public class SecurityTests extends ESTestCase {
public void testUnknownOutput() throws Exception { public void testUnknownOutput() throws Exception {
Settings settings = Settings.builder() Settings settings = Settings.builder()
.put(Security.AUDIT_ENABLED_SETTING.getKey(), true) .put(XPackSettings.AUDIT_ENABLED.getKey(), true)
.put(Security.AUDIT_OUTPUTS_SETTING.getKey(), "foo").build(); .put(Security.AUDIT_OUTPUTS_SETTING.getKey(), "foo").build();
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> createComponents(settings)); IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> createComponents(settings));
assertEquals("Unknown audit trail output [foo]", e.getMessage()); assertEquals("Unknown audit trail output [foo]", e.getMessage());

View File

@ -47,7 +47,7 @@ import org.elasticsearch.transport.MockTcpTransportPlugin;
import org.elasticsearch.transport.TransportInfo; import org.elasticsearch.transport.TransportInfo;
import org.elasticsearch.transport.TransportMessage; import org.elasticsearch.transport.TransportMessage;
import org.elasticsearch.transport.TransportRequest; import org.elasticsearch.transport.TransportRequest;
import org.elasticsearch.xpack.security.Security; import org.elasticsearch.xpack.XPackSettings;
import org.elasticsearch.xpack.security.audit.index.IndexAuditTrail.Message; import org.elasticsearch.xpack.security.audit.index.IndexAuditTrail.Message;
import org.elasticsearch.xpack.security.authc.AuthenticationToken; import org.elasticsearch.xpack.security.authc.AuthenticationToken;
import org.elasticsearch.xpack.security.crypto.CryptoService; import org.elasticsearch.xpack.security.crypto.CryptoService;
@ -140,7 +140,7 @@ public class IndexAuditTrailTests extends SecurityIntegTestCase {
public Settings nodeSettings(int nodeOrdinal) { public Settings nodeSettings(int nodeOrdinal) {
Settings.Builder builder = Settings.builder() Settings.Builder builder = Settings.builder()
.put(super.nodeSettings(nodeOrdinal)) .put(super.nodeSettings(nodeOrdinal))
.put(Security.enabledSetting(), useSecurity); .put(XPackSettings.SECURITY_ENABLED.getKey(), useSecurity);
if (useSecurity == false && builder.get(NetworkModule.TRANSPORT_TYPE_KEY) == null) { if (useSecurity == false && builder.get(NetworkModule.TRANSPORT_TYPE_KEY) == null) {
builder.put(NetworkModule.TRANSPORT_TYPE_KEY, MockTcpTransportPlugin.MOCK_TCP_TRANSPORT_NAME); builder.put(NetworkModule.TRANSPORT_TYPE_KEY, MockTcpTransportPlugin.MOCK_TCP_TRANSPORT_NAME);
} }
@ -163,7 +163,7 @@ public class IndexAuditTrailTests extends SecurityIntegTestCase {
InetSocketTransportAddress inet = (InetSocketTransportAddress) info.address().publishAddress(); InetSocketTransportAddress inet = (InetSocketTransportAddress) info.address().publishAddress();
Settings.Builder builder = Settings.builder() Settings.Builder builder = Settings.builder()
.put(Security.enabledSetting(), useSecurity) .put(XPackSettings.SECURITY_ENABLED.getKey(), useSecurity)
.put(remoteSettings(NetworkAddress.format(inet.address().getAddress()), inet.address().getPort(), cluster2Name)) .put(remoteSettings(NetworkAddress.format(inet.address().getAddress()), inet.address().getPort(), cluster2Name))
.put("xpack.security.audit.index.client.xpack.security.user", SecuritySettingsSource.DEFAULT_USER_NAME + ":" + .put("xpack.security.audit.index.client.xpack.security.user", SecuritySettingsSource.DEFAULT_USER_NAME + ":" +
SecuritySettingsSource.DEFAULT_PASSWORD); SecuritySettingsSource.DEFAULT_PASSWORD);

View File

@ -11,6 +11,7 @@ import org.elasticsearch.common.logging.ESLogger;
import org.elasticsearch.common.logging.ESLoggerFactory; import org.elasticsearch.common.logging.ESLoggerFactory;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.env.Environment; import org.elasticsearch.env.Environment;
import org.elasticsearch.xpack.XPackSettings;
import org.elasticsearch.xpack.security.audit.logfile.CapturingLogger; import org.elasticsearch.xpack.security.audit.logfile.CapturingLogger;
import org.elasticsearch.xpack.security.authc.RealmConfig; import org.elasticsearch.xpack.security.authc.RealmConfig;
import org.elasticsearch.xpack.security.authc.support.RefreshListener; import org.elasticsearch.xpack.security.authc.support.RefreshListener;
@ -18,8 +19,6 @@ import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.threadpool.TestThreadPool; import org.elasticsearch.threadpool.TestThreadPool;
import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.watcher.ResourceWatcherService; import org.elasticsearch.watcher.ResourceWatcherService;
import org.elasticsearch.xpack.XPackPlugin;
import org.elasticsearch.xpack.watcher.Watcher;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
@ -226,7 +225,7 @@ public class FileUserRolesStoreTests extends ESTestCase {
Path usersRoles = writeUsersRoles("role1:admin"); Path usersRoles = writeUsersRoles("role1:admin");
Settings settings = Settings.builder() Settings settings = Settings.builder()
.put(XPackPlugin.featureEnabledSetting(Watcher.NAME), "false") .put(XPackSettings.WATCHER_ENABLED.getKey(), "false")
.put("path.home", createTempDir()) .put("path.home", createTempDir())
.build(); .build();

View File

@ -7,6 +7,7 @@ package org.elasticsearch.xpack.security.authz.store;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.env.Environment; import org.elasticsearch.env.Environment;
import org.elasticsearch.xpack.XPackSettings;
import org.elasticsearch.xpack.security.Security; import org.elasticsearch.xpack.security.Security;
import org.elasticsearch.xpack.security.audit.logfile.CapturingLogger; import org.elasticsearch.xpack.security.audit.logfile.CapturingLogger;
import org.elasticsearch.xpack.security.authc.support.RefreshListener; import org.elasticsearch.xpack.security.authc.support.RefreshListener;
@ -56,7 +57,7 @@ public class FileRolesStoreTests extends ESTestCase {
public void testParseFile() throws Exception { public void testParseFile() throws Exception {
Path path = getDataPath("roles.yml"); Path path = getDataPath("roles.yml");
Map<String, Role> roles = FileRolesStore.parseFile(path, logger, Settings.builder() Map<String, Role> roles = FileRolesStore.parseFile(path, logger, Settings.builder()
.put(XPackPlugin.featureEnabledSetting(Security.DLS_FLS_FEATURE), true) .put(XPackSettings.DLS_FLS_ENABLED.getKey(), true)
.build()); .build());
assertThat(roles, notNullValue()); assertThat(roles, notNullValue());
assertThat(roles.size(), is(9)); assertThat(roles.size(), is(9));
@ -209,7 +210,7 @@ public class FileRolesStoreTests extends ESTestCase {
Path path = getDataPath("roles.yml"); Path path = getDataPath("roles.yml");
CapturingLogger logger = new CapturingLogger(CapturingLogger.Level.ERROR); CapturingLogger logger = new CapturingLogger(CapturingLogger.Level.ERROR);
Map<String, Role> roles = FileRolesStore.parseFile(path, logger, Settings.builder() Map<String, Role> roles = FileRolesStore.parseFile(path, logger, Settings.builder()
.put(XPackPlugin.featureEnabledSetting(Security.DLS_FLS_FEATURE), false) .put(XPackSettings.DLS_FLS_ENABLED.getKey(), false)
.build()); .build());
assertThat(roles, notNullValue()); assertThat(roles, notNullValue());
assertThat(roles.size(), is(6)); assertThat(roles.size(), is(6));
@ -378,7 +379,7 @@ public class FileRolesStoreTests extends ESTestCase {
.put("resource.reload.interval.high", "500ms") .put("resource.reload.interval.high", "500ms")
.put(FileRolesStore.ROLES_FILE_SETTING.getKey(), tmp.toAbsolutePath()) .put(FileRolesStore.ROLES_FILE_SETTING.getKey(), tmp.toAbsolutePath())
.put("path.home", createTempDir()) .put("path.home", createTempDir())
.put(XPackPlugin.featureEnabledSetting(Security.DLS_FLS_FEATURE), flsDlsEnabled) .put(XPackSettings.DLS_FLS_ENABLED.getKey(), flsDlsEnabled)
.build(); .build();
Environment env = new Environment(settings); Environment env = new Environment(settings);
FileRolesStore store = new FileRolesStore(settings, env, mock(ResourceWatcherService.class)); FileRolesStore store = new FileRolesStore(settings, env, mock(ResourceWatcherService.class));

View File

@ -7,7 +7,7 @@ package org.elasticsearch.xpack.security.test;
import org.elasticsearch.ElasticsearchSecurityException; import org.elasticsearch.ElasticsearchSecurityException;
import org.elasticsearch.rest.RestStatus; import org.elasticsearch.rest.RestStatus;
import org.elasticsearch.xpack.security.Security; import org.elasticsearch.xpack.XPackPlugin;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.contains;
@ -21,6 +21,6 @@ public class SecurityAssertions {
assertThat(e.status(), is(RestStatus.UNAUTHORIZED)); assertThat(e.status(), is(RestStatus.UNAUTHORIZED));
assertThat(e.getHeaderKeys(), hasSize(1)); assertThat(e.getHeaderKeys(), hasSize(1));
assertThat(e.getHeader("WWW-Authenticate"), notNullValue()); assertThat(e.getHeader("WWW-Authenticate"), notNullValue());
assertThat(e.getHeader("WWW-Authenticate"), contains("Basic realm=\"" + Security.NAME + "\" charset=\"UTF-8\"")); assertThat(e.getHeader("WWW-Authenticate"), contains("Basic realm=\"" + XPackPlugin.SECURITY + "\" charset=\"UTF-8\""));
} }
} }

View File

@ -14,6 +14,7 @@ import org.elasticsearch.common.Strings;
import org.elasticsearch.common.logging.LoggerMessageFormat; import org.elasticsearch.common.logging.LoggerMessageFormat;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.license.License.OperationMode; import org.elasticsearch.license.License.OperationMode;
import org.elasticsearch.xpack.XPackPlugin;
import org.elasticsearch.xpack.graph.Graph; import org.elasticsearch.xpack.graph.Graph;
import org.elasticsearch.xpack.monitoring.Monitoring; import org.elasticsearch.xpack.monitoring.Monitoring;
import org.elasticsearch.xpack.monitoring.MonitoringSettings; import org.elasticsearch.xpack.monitoring.MonitoringSettings;
@ -29,20 +30,20 @@ public class XPackLicenseState {
static final Map<String, String[]> EXPIRATION_MESSAGES; static final Map<String, String[]> EXPIRATION_MESSAGES;
static { static {
Map<String, String[]> messages = new LinkedHashMap<>(); Map<String, String[]> messages = new LinkedHashMap<>();
messages.put(Security.NAME, new String[] { messages.put(XPackPlugin.SECURITY, new String[] {
"Cluster health, cluster stats and indices stats operations are blocked", "Cluster health, cluster stats and indices stats operations are blocked",
"All data operations (read and write) continue to work" "All data operations (read and write) continue to work"
}); });
messages.put(Watcher.NAME, new String[] { messages.put(XPackPlugin.WATCHER, new String[] {
"PUT / GET watch APIs are disabled, DELETE watch API continues to work", "PUT / GET watch APIs are disabled, DELETE watch API continues to work",
"Watches execute and write to the history", "Watches execute and write to the history",
"The actions of the watches don't execute" "The actions of the watches don't execute"
}); });
messages.put(Monitoring.NAME, new String[] { messages.put(XPackPlugin.MONITORING, new String[] {
"The agent will stop collecting cluster and indices metrics", "The agent will stop collecting cluster and indices metrics",
"The agent will stop automatically cleaning indices older than [xpack.monitoring.history.duration]" "The agent will stop automatically cleaning indices older than [xpack.monitoring.history.duration]"
}); });
messages.put(Graph.NAME, new String[] { messages.put(XPackPlugin.GRAPH, new String[] {
"Graph explore APIs are disabled" "Graph explore APIs are disabled"
}); });
EXPIRATION_MESSAGES = Collections.unmodifiableMap(messages); EXPIRATION_MESSAGES = Collections.unmodifiableMap(messages);
@ -55,10 +56,10 @@ public class XPackLicenseState {
static final Map<String, BiFunction<OperationMode, OperationMode, String[]>> ACKNOWLEDGMENT_MESSAGES; static final Map<String, BiFunction<OperationMode, OperationMode, String[]>> ACKNOWLEDGMENT_MESSAGES;
static { static {
Map<String, BiFunction<OperationMode, OperationMode, String[]>> messages = new LinkedHashMap<>(); Map<String, BiFunction<OperationMode, OperationMode, String[]>> messages = new LinkedHashMap<>();
messages.put(Security.NAME, XPackLicenseState::securityAcknowledgementMessages); messages.put(XPackPlugin.SECURITY, XPackLicenseState::securityAcknowledgementMessages);
messages.put(Watcher.NAME, XPackLicenseState::watcherAcknowledgementMessages); messages.put(XPackPlugin.WATCHER, XPackLicenseState::watcherAcknowledgementMessages);
messages.put(Monitoring.NAME, XPackLicenseState::monitoringAcknowledgementMessages); messages.put(XPackPlugin.MONITORING, XPackLicenseState::monitoringAcknowledgementMessages);
messages.put(Graph.NAME, XPackLicenseState::graphAcknowledgementMessages); messages.put(XPackPlugin.GRAPH, XPackLicenseState::graphAcknowledgementMessages);
ACKNOWLEDGMENT_MESSAGES = Collections.unmodifiableMap(messages); ACKNOWLEDGMENT_MESSAGES = Collections.unmodifiableMap(messages);
} }

View File

@ -98,8 +98,20 @@ public class XPackPlugin extends Plugin implements ScriptPlugin, ActionPlugin, I
public static final String NAME = "x-pack"; public static final String NAME = "x-pack";
/** Name constant for the security feature. */
public static final String SECURITY = "security";
/** Name constant for the monitoring feature. */
public static final String MONITORING = "monitoring";
/** Name constant for the watcher feature. */
public static final String WATCHER = "watcher";
/** Name constant for the graph feature. */
public static final String GRAPH = "graph";
// inside of YAML settings we still use xpack do not having handle issues with dashes // inside of YAML settings we still use xpack do not having handle issues with dashes
public static final String SETTINGS_NAME = "xpack"; private static final String SETTINGS_NAME = "xpack";
// TODO: clean up this library to not ask for write access to all system properties! // TODO: clean up this library to not ask for write access to all system properties!
static { static {
@ -274,8 +286,10 @@ public class XPackPlugin extends Plugin implements ScriptPlugin, ActionPlugin, I
settings.addAll(security.getSettings()); settings.addAll(security.getSettings());
settings.addAll(MonitoringSettings.getSettings()); settings.addAll(MonitoringSettings.getSettings());
settings.addAll(watcher.getSettings()); settings.addAll(watcher.getSettings());
settings.addAll(graph.getSettings());
settings.addAll(licensing.getSettings()); settings.addAll(licensing.getSettings());
settings.addAll(XPackSettings.getAllSettings());
// we add the `xpack.version` setting to all internal indices // we add the `xpack.version` setting to all internal indices
settings.add(Setting.simpleString("index.xpack.version", Setting.Property.IndexScope)); settings.add(Setting.simpleString("index.xpack.version", Setting.Property.IndexScope));
@ -360,10 +374,10 @@ public class XPackPlugin extends Plugin implements ScriptPlugin, ActionPlugin, I
@Override @Override
public List<NamedWriteableRegistry.Entry> getNamedWriteables() { public List<NamedWriteableRegistry.Entry> getNamedWriteables() {
return Arrays.asList( return Arrays.asList(
new NamedWriteableRegistry.Entry(XPackFeatureSet.Usage.class, Security.NAME, SecurityFeatureSet.Usage::new), new NamedWriteableRegistry.Entry(XPackFeatureSet.Usage.class, SECURITY, SecurityFeatureSet.Usage::new),
new NamedWriteableRegistry.Entry(XPackFeatureSet.Usage.class, Watcher.NAME, WatcherFeatureSet.Usage::new), new NamedWriteableRegistry.Entry(XPackFeatureSet.Usage.class, WATCHER, WatcherFeatureSet.Usage::new),
new NamedWriteableRegistry.Entry(XPackFeatureSet.Usage.class, Monitoring.NAME, MonitoringFeatureSet.Usage::new), new NamedWriteableRegistry.Entry(XPackFeatureSet.Usage.class, MONITORING, MonitoringFeatureSet.Usage::new),
new NamedWriteableRegistry.Entry(XPackFeatureSet.Usage.class, Graph.NAME, GraphFeatureSet.Usage::new) new NamedWriteableRegistry.Entry(XPackFeatureSet.Usage.class, GRAPH, GraphFeatureSet.Usage::new)
); );
} }
@ -394,47 +408,10 @@ public class XPackPlugin extends Plugin implements ScriptPlugin, ActionPlugin, I
return env.configFile().resolve(NAME).resolve(name); return env.configFile().resolve(NAME).resolve(name);
} }
/**
* A consistent way to enable disable features using the following setting:
*
* {@code "xpack.<feature>.enabled": true | false}
*
* Also supports the following setting as a fallback (for BWC with 1.x/2.x):
*
* {@code "<feature>.enabled": true | false}
*/
public static boolean featureEnabled(Settings settings, String featureName, boolean defaultValue) {
return settings.getAsBoolean(featureEnabledSetting(featureName),
settings.getAsBoolean(legacyFeatureEnabledSetting(featureName), defaultValue)); // for bwc
}
public static String featureEnabledSetting(String featureName) {
return featureSettingPrefix(featureName) + ".enabled";
}
public static String featureSettingPrefix(String featureName) { public static String featureSettingPrefix(String featureName) {
return SETTINGS_NAME + "." + featureName; return SETTINGS_NAME + "." + featureName;
} }
public static String legacyFeatureEnabledSetting(String featureName) {
return featureName + ".enabled";
}
/**
* A consistent way to register the settings used to enable disable features, supporting the following format:
*
* {@code "xpack.<feature>.enabled": true | false}
*
* Also supports the following setting as a fallback (for BWC with 1.x/2.x):
*
* {@code "<feature>.enabled": true | false}
*/
public static void addFeatureEnabledSettings(List<Setting<?>> settingsList, String featureName, boolean defaultValue) {
settingsList.add(Setting.boolSetting(featureEnabledSetting(featureName), defaultValue, Setting.Property.NodeScope));
settingsList.add(Setting.boolSetting(legacyFeatureEnabledSetting(featureName),
defaultValue, Setting.Property.NodeScope));
}
public static Path resolveXPackExtensionsFile(Environment env) { public static Path resolveXPackExtensionsFile(Environment env) {
return env.pluginsFile().resolve(XPackPlugin.NAME).resolve("extensions"); return env.pluginsFile().resolve(XPackPlugin.NAME).resolve("extensions");
} }

View File

@ -0,0 +1,80 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
package org.elasticsearch.xpack;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import org.elasticsearch.common.settings.Setting;
import org.elasticsearch.common.settings.Settings;
/**
* A container for xpack setting constants.
*/
public class XPackSettings {
/** All setting constants created in this class. */
private static final List<Setting<?>> ALL_SETTINGS = new ArrayList<>();
/** Setting for enabling or disabling security. Defaults to true. */
public static final Setting<Boolean> SECURITY_ENABLED = enabledSetting(XPackPlugin.SECURITY, true);
/** Setting for enabling or disabling monitoring. Defaults to true if not a tribe node. */
public static final Setting<Boolean> MONITORING_ENABLED = enabledSetting(XPackPlugin.MONITORING,
// By default, monitoring is disabled on tribe nodes
s -> String.valueOf(XPackPlugin.isTribeNode(s) == false && XPackPlugin.isTribeClientNode(s) == false));
/** Setting for enabling or disabling watcher. Defaults to true. */
public static final Setting<Boolean> WATCHER_ENABLED = enabledSetting(XPackPlugin.WATCHER, true);
/** Setting for enabling or disabling graph. Defaults to true. */
public static final Setting<Boolean> GRAPH_ENABLED = enabledSetting(XPackPlugin.GRAPH, true);
/** Setting for enabling or disabling auditing. Defaults to false. */
public static final Setting<Boolean> AUDIT_ENABLED = enabledSetting(XPackPlugin.SECURITY + ".audit", false);
/** Setting for enabling or disabling document/field level security. Defaults to true. */
public static final Setting<Boolean> DLS_FLS_ENABLED = enabledSetting(XPackPlugin.SECURITY + ".dls_fls", true);
/**
* Create a Setting for the enabled state of features in xpack.
*
* The given feature by be enabled or disabled with:
* {@code "xpack.<feature>.enabled": true | false}
*
* For backward compatibility with 1.x and 2.x, the following also works:
* {@code "<feature>.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<Boolean> 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<Boolean> enabledSetting(String featureName, Function<Settings,String> defaultValueFn) {
String fallbackName = featureName + ".enabled";
Setting<Boolean> fallback = Setting.boolSetting(fallbackName, defaultValueFn,
Setting.Property.NodeScope, Setting.Property.Deprecated);
String settingName = XPackPlugin.featureSettingPrefix(featureName) + ".enabled";
Setting<Boolean> setting = Setting.boolSetting(settingName, fallback, Setting.Property.NodeScope);
ALL_SETTINGS.add(setting);
return setting;
}
/** Returns all settings created in {@link XPackSettings}. */
static List<Setting<?>> getAllSettings() {
return Collections.unmodifiableList(ALL_SETTINGS);
}
}

View File

@ -25,6 +25,7 @@ import org.elasticsearch.rest.RestHandler;
import org.elasticsearch.threadpool.ExecutorBuilder; import org.elasticsearch.threadpool.ExecutorBuilder;
import org.elasticsearch.threadpool.FixedExecutorBuilder; import org.elasticsearch.threadpool.FixedExecutorBuilder;
import org.elasticsearch.xpack.XPackPlugin; import org.elasticsearch.xpack.XPackPlugin;
import org.elasticsearch.xpack.XPackSettings;
import org.elasticsearch.xpack.watcher.actions.WatcherActionModule; import org.elasticsearch.xpack.watcher.actions.WatcherActionModule;
import org.elasticsearch.xpack.watcher.client.WatcherClientModule; import org.elasticsearch.xpack.watcher.client.WatcherClientModule;
import org.elasticsearch.xpack.watcher.condition.ConditionModule; import org.elasticsearch.xpack.watcher.condition.ConditionModule;
@ -81,8 +82,6 @@ import static java.util.Collections.emptyList;
public class Watcher implements ActionPlugin { public class Watcher implements ActionPlugin {
public static final String NAME = "watcher";
public static final Setting<String> INDEX_WATCHER_VERSION_SETTING = public static final Setting<String> INDEX_WATCHER_VERSION_SETTING =
new Setting<>("index.xpack.watcher.plugin.version", "", Function.identity(), Setting.Property.IndexScope); new Setting<>("index.xpack.watcher.plugin.version", "", Function.identity(), Setting.Property.IndexScope);
public static final Setting<String> INDEX_WATCHER_TEMPLATE_VERSION_SETTING = public static final Setting<String> INDEX_WATCHER_TEMPLATE_VERSION_SETTING =
@ -105,7 +104,7 @@ public class Watcher implements ActionPlugin {
public Watcher(Settings settings) { public Watcher(Settings settings) {
this.settings = settings; this.settings = settings;
transportClient = "transport".equals(settings.get(Client.CLIENT_TYPE_SETTING_S.getKey())); transportClient = "transport".equals(settings.get(Client.CLIENT_TYPE_SETTING_S.getKey()));
enabled = enabled(settings); this.enabled = XPackSettings.WATCHER_ENABLED.get(settings);
validAutoCreateIndex(settings); validAutoCreateIndex(settings);
} }
@ -143,7 +142,6 @@ public class Watcher implements ActionPlugin {
settings.add(ExecutionService.DEFAULT_THROTTLE_PERIOD_SETTING); settings.add(ExecutionService.DEFAULT_THROTTLE_PERIOD_SETTING);
settings.add(Setting.intSetting("xpack.watcher.execution.scroll.size", 0, Setting.Property.NodeScope)); settings.add(Setting.intSetting("xpack.watcher.execution.scroll.size", 0, Setting.Property.NodeScope));
settings.add(Setting.intSetting("xpack.watcher.watch.scroll.size", 0, Setting.Property.NodeScope)); settings.add(Setting.intSetting("xpack.watcher.watch.scroll.size", 0, Setting.Property.NodeScope));
settings.add(Setting.boolSetting(XPackPlugin.featureEnabledSetting(Watcher.NAME), true, Setting.Property.NodeScope));
settings.add(ENCRYPT_SENSITIVE_DATA_SETTING); settings.add(ENCRYPT_SENSITIVE_DATA_SETTING);
settings.add(Setting.simpleString("xpack.watcher.internal.ops.search.default_timeout", Setting.Property.NodeScope)); settings.add(Setting.simpleString("xpack.watcher.internal.ops.search.default_timeout", Setting.Property.NodeScope));
@ -161,7 +159,7 @@ public class Watcher implements ActionPlugin {
} }
public List<ExecutorBuilder<?>> getExecutorBuilders(final Settings settings) { public List<ExecutorBuilder<?>> getExecutorBuilders(final Settings settings) {
if (XPackPlugin.featureEnabled(settings, Watcher.NAME, true)) { if (enabled) {
final FixedExecutorBuilder builder = final FixedExecutorBuilder builder =
new FixedExecutorBuilder( new FixedExecutorBuilder(
settings, settings,
@ -205,10 +203,6 @@ public class Watcher implements ActionPlugin {
RestHijackOperationAction.class); RestHijackOperationAction.class);
} }
public static boolean enabled(Settings settings) {
return XPackPlugin.featureEnabled(settings, NAME, true);
}
static void validAutoCreateIndex(Settings settings) { static void validAutoCreateIndex(Settings settings) {
String value = settings.get("action.auto_create_index"); String value = settings.get("action.auto_create_index");
if (value == null) { if (value == null) {

View File

@ -17,6 +17,8 @@ import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.license.XPackLicenseState;
import org.elasticsearch.xpack.XPackFeatureSet; import org.elasticsearch.xpack.XPackFeatureSet;
import org.elasticsearch.xpack.XPackPlugin;
import org.elasticsearch.xpack.XPackSettings;
/** /**
* *
@ -30,13 +32,13 @@ public class WatcherFeatureSet implements XPackFeatureSet {
@Inject @Inject
public WatcherFeatureSet(Settings settings, @Nullable XPackLicenseState licenseState, @Nullable WatcherService watcherService) { public WatcherFeatureSet(Settings settings, @Nullable XPackLicenseState licenseState, @Nullable WatcherService watcherService) {
this.watcherService = watcherService; this.watcherService = watcherService;
this.enabled = Watcher.enabled(settings); this.enabled = XPackSettings.WATCHER_ENABLED.get(settings);
this.licenseState = licenseState; this.licenseState = licenseState;
} }
@Override @Override
public String name() { public String name() {
return Watcher.NAME; return XPackPlugin.WATCHER;
} }
@Override @Override
@ -69,7 +71,7 @@ public class WatcherFeatureSet implements XPackFeatureSet {
} }
public Usage(boolean available, boolean enabled, Map<String, Object> stats) { public Usage(boolean available, boolean enabled, Map<String, Object> stats) {
super(Watcher.NAME, available, enabled); super(XPackPlugin.WATCHER, available, enabled);
this.stats = stats; this.stats = stats;
} }

View File

@ -5,17 +5,17 @@
*/ */
package org.elasticsearch.xpack.watcher.execution; package org.elasticsearch.xpack.watcher.execution;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.util.concurrent.EsThreadPoolExecutor;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.xpack.watcher.Watcher;
import java.util.concurrent.BlockingQueue; import java.util.concurrent.BlockingQueue;
import java.util.stream.Stream; import java.util.stream.Stream;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.util.concurrent.EsThreadPoolExecutor;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.xpack.XPackPlugin;
public class InternalWatchExecutor implements WatchExecutor { public class InternalWatchExecutor implements WatchExecutor {
public static final String THREAD_POOL_NAME = Watcher.NAME; public static final String THREAD_POOL_NAME = XPackPlugin.WATCHER;
private final ThreadPool threadPool; private final ThreadPool threadPool;

View File

@ -5,22 +5,22 @@
*/ */
package org.elasticsearch.xpack.watcher.transport.actions; package org.elasticsearch.xpack.watcher.transport.actions;
import java.util.function.Supplier;
import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.ActionResponse; import org.elasticsearch.action.ActionResponse;
import org.elasticsearch.action.support.ActionFilters; import org.elasticsearch.action.support.ActionFilters;
import org.elasticsearch.action.support.master.MasterNodeRequest; import org.elasticsearch.action.support.master.MasterNodeRequest;
import org.elasticsearch.action.support.master.TransportMasterNodeAction; import org.elasticsearch.action.support.master.TransportMasterNodeAction;
import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.license.LicenseUtils; import org.elasticsearch.license.LicenseUtils;
import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.license.XPackLicenseState;
import org.elasticsearch.tasks.Task; import org.elasticsearch.tasks.Task;
import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.TransportService; import org.elasticsearch.transport.TransportService;
import org.elasticsearch.xpack.watcher.Watcher; import org.elasticsearch.xpack.XPackPlugin;
import java.util.function.Supplier;
/** /**
* *
@ -43,7 +43,7 @@ public abstract class WatcherTransportAction<Request extends MasterNodeRequest<R
if (licenseState.isWatcherAllowed()) { if (licenseState.isWatcherAllowed()) {
super.doExecute(task, request, listener); super.doExecute(task, request, listener);
} else { } else {
listener.onFailure(LicenseUtils.newComplianceException(Watcher.NAME)); listener.onFailure(LicenseUtils.newComplianceException(XPackPlugin.WATCHER));
} }
} }
} }

View File

@ -5,14 +5,16 @@
*/ */
package org.elasticsearch.xpack.watcher.transport.actions.get; package org.elasticsearch.xpack.watcher.transport.actions.get;
import java.io.IOException;
import org.elasticsearch.ElasticsearchException; import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.support.ActionFilters; import org.elasticsearch.action.support.ActionFilters;
import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.block.ClusterBlockException; import org.elasticsearch.cluster.block.ClusterBlockException;
import org.elasticsearch.cluster.block.ClusterBlockLevel; import org.elasticsearch.cluster.block.ClusterBlockLevel;
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
@ -22,15 +24,13 @@ import org.elasticsearch.license.LicenseUtils;
import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.license.XPackLicenseState;
import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.TransportService; import org.elasticsearch.transport.TransportService;
import org.elasticsearch.xpack.watcher.Watcher; import org.elasticsearch.xpack.XPackPlugin;
import org.elasticsearch.xpack.watcher.WatcherService; import org.elasticsearch.xpack.watcher.WatcherService;
import org.elasticsearch.xpack.watcher.support.xcontent.WatcherParams; import org.elasticsearch.xpack.watcher.support.xcontent.WatcherParams;
import org.elasticsearch.xpack.watcher.transport.actions.WatcherTransportAction; import org.elasticsearch.xpack.watcher.transport.actions.WatcherTransportAction;
import org.elasticsearch.xpack.watcher.watch.Watch; import org.elasticsearch.xpack.watcher.watch.Watch;
import org.elasticsearch.xpack.watcher.watch.WatchStore; import org.elasticsearch.xpack.watcher.watch.WatchStore;
import java.io.IOException;
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
/** /**
@ -64,7 +64,7 @@ public class TransportGetWatchAction extends WatcherTransportAction<GetWatchRequ
protected void masterOperation(GetWatchRequest request, ClusterState state, ActionListener<GetWatchResponse> listener) throws protected void masterOperation(GetWatchRequest request, ClusterState state, ActionListener<GetWatchResponse> listener) throws
ElasticsearchException { ElasticsearchException {
if (licenseState.isWatcherAllowed() == false) { if (licenseState.isWatcherAllowed() == false) {
listener.onFailure(LicenseUtils.newComplianceException(Watcher.NAME)); listener.onFailure(LicenseUtils.newComplianceException(XPackPlugin.WATCHER));
return; return;
} }

View File

@ -10,18 +10,18 @@ import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.DocWriteResponse; import org.elasticsearch.action.DocWriteResponse;
import org.elasticsearch.action.index.IndexResponse; import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.action.support.ActionFilters; import org.elasticsearch.action.support.ActionFilters;
import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.block.ClusterBlockException; import org.elasticsearch.cluster.block.ClusterBlockException;
import org.elasticsearch.cluster.block.ClusterBlockLevel; import org.elasticsearch.cluster.block.ClusterBlockLevel;
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.license.LicenseUtils; import org.elasticsearch.license.LicenseUtils;
import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.license.XPackLicenseState;
import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.TransportService; import org.elasticsearch.transport.TransportService;
import org.elasticsearch.xpack.watcher.Watcher; import org.elasticsearch.xpack.XPackPlugin;
import org.elasticsearch.xpack.watcher.WatcherService; import org.elasticsearch.xpack.watcher.WatcherService;
import org.elasticsearch.xpack.watcher.transport.actions.WatcherTransportAction; import org.elasticsearch.xpack.watcher.transport.actions.WatcherTransportAction;
import org.elasticsearch.xpack.watcher.watch.WatchStore; import org.elasticsearch.xpack.watcher.watch.WatchStore;
@ -56,7 +56,7 @@ public class TransportPutWatchAction extends WatcherTransportAction<PutWatchRequ
protected void masterOperation(PutWatchRequest request, ClusterState state, ActionListener<PutWatchResponse> listener) throws protected void masterOperation(PutWatchRequest request, ClusterState state, ActionListener<PutWatchResponse> listener) throws
ElasticsearchException { ElasticsearchException {
if (licenseState.isWatcherAllowed() == false) { if (licenseState.isWatcherAllowed() == false) {
listener.onFailure(LicenseUtils.newComplianceException(Watcher.NAME)); listener.onFailure(LicenseUtils.newComplianceException(XPackPlugin.WATCHER));
return; return;
} }

View File

@ -5,6 +5,10 @@
*/ */
package org.elasticsearch.xpack.watcher; package org.elasticsearch.xpack.watcher;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import org.apache.http.HttpStatus; import org.apache.http.HttpStatus;
import org.elasticsearch.action.admin.cluster.node.info.NodeInfo; import org.elasticsearch.action.admin.cluster.node.info.NodeInfo;
import org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse; import org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse;
@ -13,20 +17,15 @@ import org.elasticsearch.common.network.NetworkModule;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.transport.Netty3Plugin; import org.elasticsearch.transport.Netty3Plugin;
import org.elasticsearch.transport.Netty4Plugin; import org.elasticsearch.transport.Netty4Plugin;
import org.elasticsearch.xpack.monitoring.Monitoring;
import org.elasticsearch.plugins.Plugin; import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.xpack.security.Security;
import org.elasticsearch.test.ESIntegTestCase; import org.elasticsearch.test.ESIntegTestCase;
import org.elasticsearch.test.ESIntegTestCase.ClusterScope; import org.elasticsearch.test.ESIntegTestCase.ClusterScope;
import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.threadpool.ThreadPoolInfo; import org.elasticsearch.threadpool.ThreadPoolInfo;
import org.elasticsearch.xpack.XPackPlugin; import org.elasticsearch.xpack.XPackPlugin;
import org.elasticsearch.xpack.XPackSettings;
import org.elasticsearch.xpack.watcher.execution.InternalWatchExecutor; import org.elasticsearch.xpack.watcher.execution.InternalWatchExecutor;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import static org.elasticsearch.test.ESIntegTestCase.Scope.SUITE; import static org.elasticsearch.test.ESIntegTestCase.Scope.SUITE;
import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.not;
@ -40,11 +39,11 @@ public class WatcherPluginDisableTests extends ESIntegTestCase {
protected Settings nodeSettings(int nodeOrdinal) { protected Settings nodeSettings(int nodeOrdinal) {
return Settings.builder() return Settings.builder()
.put(super.nodeSettings(nodeOrdinal)) .put(super.nodeSettings(nodeOrdinal))
.put(XPackPlugin.featureEnabledSetting(Watcher.NAME), false) .put(XPackSettings.WATCHER_ENABLED.getKey(), false)
// disable security because of query cache check and authentication/authorization // disable security because of query cache check and authentication/authorization
.put(XPackPlugin.featureEnabledSetting(Security.NAME), false) .put(XPackSettings.SECURITY_ENABLED.getKey(), false)
.put(XPackPlugin.featureEnabledSetting(Monitoring.NAME), false) .put(XPackSettings.MONITORING_ENABLED.getKey(), false)
.put(NetworkModule.HTTP_ENABLED.getKey(), true) .put(NetworkModule.HTTP_ENABLED.getKey(), true)
.build(); .build();

View File

@ -24,6 +24,7 @@ import org.elasticsearch.common.xcontent.XContentHelper;
import org.elasticsearch.common.xcontent.support.XContentMapValues; import org.elasticsearch.common.xcontent.support.XContentMapValues;
import org.elasticsearch.index.query.QueryBuilder; import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.license.XPackLicenseState;
import org.elasticsearch.xpack.XPackSettings;
import org.elasticsearch.xpack.monitoring.Monitoring; import org.elasticsearch.xpack.monitoring.Monitoring;
import org.elasticsearch.plugins.Plugin; import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.script.MockMustacheScriptEngine; import org.elasticsearch.script.MockMustacheScriptEngine;
@ -137,7 +138,7 @@ public abstract class AbstractWatcherIntegrationTestCase extends ESIntegTestCase
return Settings.builder() return Settings.builder()
.put(super.nodeSettings(nodeOrdinal)) .put(super.nodeSettings(nodeOrdinal))
//TODO: for now lets isolate watcher tests from monitoring (randomize this later) //TODO: for now lets isolate watcher tests from monitoring (randomize this later)
.put(XPackPlugin.featureEnabledSetting(Monitoring.NAME), false) .put(XPackSettings.MONITORING_ENABLED.getKey(), false)
// we do this by default in core, but for watcher this isn't needed and only adds noise. // we do this by default in core, but for watcher this isn't needed and only adds noise.
.put("index.store.mock.check_index_on_close", false) .put("index.store.mock.check_index_on_close", false)
.put("xpack.watcher.execution.scroll.size", randomIntBetween(1, 100)) .put("xpack.watcher.execution.scroll.size", randomIntBetween(1, 100))