diff --git a/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/plugin/Licensing.java b/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/plugin/Licensing.java index b92bd35752d..037c7b3b206 100644 --- a/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/plugin/Licensing.java +++ b/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/plugin/Licensing.java @@ -19,6 +19,8 @@ import org.elasticsearch.license.plugin.action.get.GetLicenseAction; import org.elasticsearch.license.plugin.action.get.TransportGetLicenseAction; import org.elasticsearch.license.plugin.action.put.PutLicenseAction; import org.elasticsearch.license.plugin.action.put.TransportPutLicenseAction; +import org.elasticsearch.license.plugin.core.LicenseeRegistry; +import org.elasticsearch.license.plugin.core.LicensesManagerService; import org.elasticsearch.license.plugin.core.LicensesMetaData; import org.elasticsearch.license.plugin.core.LicensesService; import org.elasticsearch.license.plugin.rest.RestDeleteLicenseAction; @@ -47,7 +49,6 @@ public class Licensing implements ActionPlugin { MetaData.registerPrototype(LicensesMetaData.TYPE, LicensesMetaData.PROTO); } - @Inject public Licensing(Settings settings) { isTransportClient = transportClientMode(settings); isTribeNode = isTribeNode(settings); @@ -82,7 +83,11 @@ public class Licensing implements ActionPlugin { public Collection nodeModules() { if (isTransportClient == false && isTribeNode == false) { - return Collections.singletonList(new LicensingModule()); + return Collections.singletonList(b -> { + b.bind(LicensesService.class).asEagerSingleton(); + b.bind(LicenseeRegistry.class).to(LicensesService.class); + b.bind(LicensesManagerService.class).to(LicensesService.class); + }); } return Collections.emptyList(); } diff --git a/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/plugin/LicensingModule.java b/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/plugin/LicensingModule.java deleted file mode 100644 index ab37ca62c3e..00000000000 --- a/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/plugin/LicensingModule.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * 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.license.plugin; - -import org.elasticsearch.common.inject.AbstractModule; -import org.elasticsearch.license.core.LicenseVerifier; -import org.elasticsearch.license.plugin.core.LicenseeRegistry; -import org.elasticsearch.license.plugin.core.LicensesManagerService; -import org.elasticsearch.license.plugin.core.LicensesService; - -public class LicensingModule extends AbstractModule { - - @Override - protected void configure() { - bind(LicenseVerifier.class).asEagerSingleton(); - bind(LicensesService.class).asEagerSingleton(); - bind(LicenseeRegistry.class).to(LicensesService.class); - bind(LicensesManagerService.class).to(LicensesService.class); - } - -} diff --git a/elasticsearch/x-pack/security/src/main/java/org/elasticsearch/xpack/security/Security.java b/elasticsearch/x-pack/security/src/main/java/org/elasticsearch/xpack/security/Security.java index e8b03c7fc73..21d29bb730f 100644 --- a/elasticsearch/x-pack/security/src/main/java/org/elasticsearch/xpack/security/Security.java +++ b/elasticsearch/x-pack/security/src/main/java/org/elasticsearch/xpack/security/Security.java @@ -133,6 +133,10 @@ public class Security implements ActionPlugin { } } + public CryptoService getCryptoService() { + return cryptoService; + } + public Collection nodeModules() { List modules = new ArrayList<>(); diff --git a/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/XPackPlugin.java b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/XPackPlugin.java index d3d1aa4e49a..9abcebc57a8 100644 --- a/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/XPackPlugin.java +++ b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/XPackPlugin.java @@ -12,7 +12,9 @@ import java.security.PrivilegedAction; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; +import java.util.HashMap; import java.util.List; +import java.util.Map; import org.elasticsearch.SpecialPermission; import org.elasticsearch.action.ActionRequest; @@ -20,6 +22,7 @@ import org.elasticsearch.action.ActionResponse; import org.elasticsearch.action.support.ActionFilter; import org.elasticsearch.client.Client; import org.elasticsearch.client.transport.TransportClient; +import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.component.LifecycleComponent; import org.elasticsearch.common.inject.Binder; import org.elasticsearch.common.inject.Module; @@ -36,12 +39,18 @@ import org.elasticsearch.plugins.ScriptPlugin; import org.elasticsearch.rest.RestHandler; import org.elasticsearch.script.ScriptContext; import org.elasticsearch.threadpool.ExecutorBuilder; +import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.xpack.action.TransportXPackInfoAction; import org.elasticsearch.xpack.action.TransportXPackUsageAction; import org.elasticsearch.xpack.action.XPackInfoAction; import org.elasticsearch.xpack.action.XPackUsageAction; import org.elasticsearch.xpack.common.ScriptServiceProxy; -import org.elasticsearch.xpack.common.http.HttpClientModule; +import org.elasticsearch.xpack.common.http.HttpClient; +import org.elasticsearch.xpack.common.http.HttpRequestTemplate; +import org.elasticsearch.xpack.common.http.auth.HttpAuthFactory; +import org.elasticsearch.xpack.common.http.auth.HttpAuthRegistry; +import org.elasticsearch.xpack.common.http.auth.basic.BasicAuth; +import org.elasticsearch.xpack.common.http.auth.basic.BasicAuthFactory; import org.elasticsearch.xpack.common.text.TextTemplateModule; import org.elasticsearch.xpack.extensions.XPackExtension; import org.elasticsearch.xpack.extensions.XPackExtensionsService; @@ -100,6 +109,7 @@ public class XPackPlugin extends Plugin implements ScriptPlugin, ActionPlugin { } protected final Settings settings; + private final Environment env; protected boolean transportClientMode; protected final XPackExtensionsService extensionsService; @@ -113,7 +123,7 @@ public class XPackPlugin extends Plugin implements ScriptPlugin, ActionPlugin { public XPackPlugin(Settings settings) throws IOException { this.settings = settings; this.transportClientMode = transportClientMode(settings); - final Environment env = transportClientMode ? null : new Environment(settings); + this.env = transportClientMode ? null : new Environment(settings); this.licensing = new Licensing(settings); this.security = new Security(settings, env); @@ -151,7 +161,6 @@ public class XPackPlugin extends Plugin implements ScriptPlugin, ActionPlugin { modules.addAll(graph.createGuiceModules()); if (transportClientMode == false) { - modules.add(new HttpClientModule()); modules.add(new TextTemplateModule()); } return modules; @@ -169,6 +178,22 @@ public class XPackPlugin extends Plugin implements ScriptPlugin, ActionPlugin { return services; } + @Override + public Collection createComponents(Client client, ClusterService clusterService, ThreadPool threadPool) { + List components = new ArrayList<>(); + if (transportClientMode == false) { + // watcher http stuff + Map httpAuthFactories = new HashMap<>(); + httpAuthFactories.put(BasicAuth.TYPE, new BasicAuthFactory(security.getCryptoService())); + // TODO: add more auth types, or remove this indirection + HttpAuthRegistry httpAuthRegistry = new HttpAuthRegistry(httpAuthFactories); + components.add(new HttpRequestTemplate.Parser(httpAuthRegistry)); + components.add(new HttpClient(settings, httpAuthRegistry, env)); + } + + return components; + } + @Override public Settings additionalSettings() { Settings.Builder builder = Settings.builder(); diff --git a/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/common/http/HttpClient.java b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/common/http/HttpClient.java index 47147abe980..da5f0aa8a93 100644 --- a/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/common/http/HttpClient.java +++ b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/common/http/HttpClient.java @@ -79,7 +79,6 @@ public class HttpClient extends AbstractLifecycleComponent { private SSLSocketFactory sslSocketFactory; private HttpProxy proxy = HttpProxy.NO_PROXY; - @Inject public HttpClient(Settings settings, HttpAuthRegistry httpAuthRegistry, Environment env) { super(settings); this.httpAuthRegistry = httpAuthRegistry; diff --git a/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/common/http/HttpClientModule.java b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/common/http/HttpClientModule.java deleted file mode 100644 index 548d487ec4c..00000000000 --- a/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/common/http/HttpClientModule.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * 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.common.http; - -import org.elasticsearch.common.inject.AbstractModule; -import org.elasticsearch.common.inject.multibindings.MapBinder; -import org.elasticsearch.xpack.common.http.auth.basic.BasicAuth; -import org.elasticsearch.xpack.common.http.auth.basic.BasicAuthFactory; -import org.elasticsearch.xpack.common.http.auth.HttpAuthFactory; -import org.elasticsearch.xpack.common.http.auth.HttpAuthRegistry; - - -/** - */ -public class HttpClientModule extends AbstractModule { - - @Override - protected void configure() { - bind(HttpRequestTemplate.Parser.class).asEagerSingleton(); - bind(HttpRequest.Parser.class).asEagerSingleton(); - bind(HttpClient.class).asEagerSingleton(); - - MapBinder parsersBinder = MapBinder.newMapBinder(binder(), String.class, HttpAuthFactory.class); - - bind(BasicAuthFactory.class).asEagerSingleton(); - parsersBinder.addBinding(BasicAuth.TYPE).to(BasicAuthFactory.class); - - bind(HttpAuthRegistry.class).asEagerSingleton(); - } - -} diff --git a/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/common/http/HttpRequest.java b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/common/http/HttpRequest.java index 1f7730dd895..3b6311a62ae 100644 --- a/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/common/http/HttpRequest.java +++ b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/common/http/HttpRequest.java @@ -250,7 +250,6 @@ public class HttpRequest implements ToXContent { private final HttpAuthRegistry httpAuthRegistry; - @Inject public Parser(HttpAuthRegistry httpAuthRegistry) { this.httpAuthRegistry = httpAuthRegistry; } diff --git a/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/common/http/HttpRequestTemplate.java b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/common/http/HttpRequestTemplate.java index 537cb5b2e1f..936e3faa54e 100644 --- a/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/common/http/HttpRequestTemplate.java +++ b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/common/http/HttpRequestTemplate.java @@ -255,7 +255,6 @@ public class HttpRequestTemplate implements ToXContent { private final HttpAuthRegistry httpAuthRegistry; - @Inject public Parser(HttpAuthRegistry httpAuthRegistry) { this.httpAuthRegistry = httpAuthRegistry; } diff --git a/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/common/http/auth/HttpAuthRegistry.java b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/common/http/auth/HttpAuthRegistry.java index da461ba9aa6..bf301ae0580 100644 --- a/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/common/http/auth/HttpAuthRegistry.java +++ b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/common/http/auth/HttpAuthRegistry.java @@ -21,7 +21,6 @@ public class HttpAuthRegistry { private final Map factories; - @Inject public HttpAuthRegistry(Map factories) { this.factories = factories; } diff --git a/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/common/http/auth/basic/BasicAuthFactory.java b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/common/http/auth/basic/BasicAuthFactory.java index 48dfbe42cf8..9ef970f1da7 100644 --- a/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/common/http/auth/basic/BasicAuthFactory.java +++ b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/common/http/auth/basic/BasicAuthFactory.java @@ -20,7 +20,6 @@ public class BasicAuthFactory extends HttpAuthFactory>asList( - HttpClient.class, EmailService.class, HipChatService.class, SlackService.class,