diff --git a/pom.xml b/pom.xml
index c4ceeb53a46..d1871624a16 100644
--- a/pom.xml
+++ b/pom.xml
@@ -11,6 +11,8 @@
1.4.0-SNAPSHOT
4.10.1
+ ${basedir}/src/test/resources
+ UTF-8
@@ -132,27 +134,20 @@
+
+
+ ${keys.path}
+ true
+
+ public.key
+
+
+
+ src/main/resources
+ true
+
+
-
- org.apache.maven.plugins
- maven-enforcer-plugin
- 1.3.1
-
-
- enforce-versions
-
- enforce
-
-
-
-
- [1.7,)
-
-
-
-
-
-
org.apache.maven.plugins
maven-compiler-plugin
@@ -194,30 +189,108 @@
maven-assembly-plugin
- 2.3
+ 2.4
- false
${project.build.directory}/releases/
-
- ${basedir}/src/main/assemblies/plugin.xml
-
-
- jar-with-dependencies
-
- package
-
- attached
-
-
-
- assemble-all
+ plugin
package
single
+
+ false
+
+ ${basedir}/src/main/assemblies/plugin.xml
+
+
+
+
+ exec
+ package
+
+ single
+
+
+ true
+
+ ${basedir}/src/main/assemblies/exec.xml
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-enforcer-plugin
+ 1.3.1
+
+
+ enforce-versions
+
+ enforce
+
+
+
+
+ [1.7,)
+
+
+
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-jar-plugin
+ 2.4
+
+
+ for-plugin
+ prepare-package
+
+ jar
+
+
+
+
+ org/elasticsearch/license/licensor/**/*
+
+
+
+
+ for-exec
+ prepare-package
+
+ jar
+
+
+ exec
+
+
+ public.key
+
+ org/elasticsearch/license/plugin/**/*
+
+
diff --git a/src/main/assemblies/exec.xml b/src/main/assemblies/exec.xml
new file mode 100644
index 00000000000..ceff530a3c3
--- /dev/null
+++ b/src/main/assemblies/exec.xml
@@ -0,0 +1,49 @@
+
+
+ exec
+
+ zip
+
+ true
+
+
+ true
+ bin
+ bin
+ 0755
+ 0755
+ unix
+
+ key-pair-generator
+ license-generator
+ verify-license
+
+
+
+
+
+ /lib
+ false
+ true
+ true
+
+ org.elasticsearch:elasticsearch-license:*:exec
+ net.nicholaswilliams.java.licensing:licensing-core
+ net.nicholaswilliams.java.licensing:licensing-licensor-base
+ org.elasticsearch:elasticsearch
+
+
+ org.apache.lucene:*
+
+
+
+ /lib
+ false
+ true
+ true
+
+ org.apache.lucene:lucene-core
+
+
+
+
\ No newline at end of file
diff --git a/src/main/assemblies/plugin.xml b/src/main/assemblies/plugin.xml
index 8e8e42e7c05..ff0f0a39364 100644
--- a/src/main/assemblies/plugin.xml
+++ b/src/main/assemblies/plugin.xml
@@ -14,5 +14,13 @@
org.elasticsearch:elasticsearch
+
+ /
+ true
+ true
+
+ net.nicholaswilliams.java.licensing:licensing-core
+
+
\ No newline at end of file
diff --git a/src/main/java/org/elasticsearch/license/core/ResourcePublicKeyDataProvider.java b/src/main/java/org/elasticsearch/license/core/ResourcePublicKeyDataProvider.java
new file mode 100644
index 00000000000..43e6ea5891a
--- /dev/null
+++ b/src/main/java/org/elasticsearch/license/core/ResourcePublicKeyDataProvider.java
@@ -0,0 +1,33 @@
+/*
+ * 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.core;
+
+import net.nicholaswilliams.java.licensing.encryption.PublicKeyDataProvider;
+import net.nicholaswilliams.java.licensing.exception.KeyNotFoundException;
+import org.elasticsearch.common.io.Streams;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ */
+public class ResourcePublicKeyDataProvider implements PublicKeyDataProvider {
+
+ private final String resource;
+
+ public ResourcePublicKeyDataProvider(String resource) {
+ this.resource = resource;
+ }
+
+ @Override
+ public byte[] getEncryptedPublicKeyData() throws KeyNotFoundException {
+ try(InputStream inputStream = this.getClass().getResourceAsStream(resource)) {
+ return Streams.copyToByteArray(inputStream);
+ } catch (IOException ex) {
+ throw new KeyNotFoundException(ex);
+ }
+ }
+}
diff --git a/src/main/java/org/elasticsearch/license/manager/ESLicenseManager.java b/src/main/java/org/elasticsearch/license/manager/ESLicenseManager.java
index a2fa74a0ca3..34509afb14e 100644
--- a/src/main/java/org/elasticsearch/license/manager/ESLicenseManager.java
+++ b/src/main/java/org/elasticsearch/license/manager/ESLicenseManager.java
@@ -12,11 +12,10 @@ import net.nicholaswilliams.java.licensing.encryption.PasswordProvider;
import net.nicholaswilliams.java.licensing.exception.ExpiredLicenseException;
import net.nicholaswilliams.java.licensing.exception.InvalidLicenseException;
import org.elasticsearch.common.collect.ImmutableSet;
+import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.license.core.ESLicense;
+import org.elasticsearch.license.core.ResourcePublicKeyDataProvider;
-import java.net.URISyntaxException;
-import java.net.URL;
-import java.nio.file.Paths;
import java.util.Collection;
import java.util.HashSet;
import java.util.Map;
@@ -46,31 +45,18 @@ public class ESLicenseManager {
// Initialize LicenseManager
static {
- LicenseManagerProperties.setPublicKeyDataProvider(new FilePublicKeyDataProvider(getPublicKeyPath()));
+ LicenseManagerProperties.setPublicKeyDataProvider(new ResourcePublicKeyDataProvider("/public.key"));
LicenseManagerProperties.setPublicKeyPasswordProvider(new ESPublicKeyPasswordProvider());
LicenseManagerProperties.setLicenseValidator(new DefaultLicenseValidator());
LicenseManagerProperties.setLicenseProvider(new LicenseProvider() {
@Override
public SignedLicense getLicense(Object context) {
- throw new UnsupportedOperationException("This singelton license provider shouldn't be used");
+ throw new UnsupportedOperationException("This singleton license provider shouldn't be used");
}
});
}
- private static String getPublicKeyPath() {
- //TODO: Imporove key management
- URL resource = ESLicenseManager.class.getResource("public.key");
- if (resource == null) {
- //test REMOVE NOCOMMIT!!!!
- resource = ESLicenseManager.class.getResource("/org.elasticsearch.license.plugin/test_pub.key");
- }
- try {
- return Paths.get(resource.toURI()).toFile().getAbsolutePath();
- } catch (URISyntaxException e) {
- throw new IllegalStateException(e);
- }
- }
-
+ @Inject
public ESLicenseManager() {
this.licenseManager = LicenseManager.getInstance();
}
diff --git a/src/main/java/org/elasticsearch/license/plugin/LicenseModule.java b/src/main/java/org/elasticsearch/license/plugin/LicenseModule.java
index 1ace3805f4f..78506b1c402 100644
--- a/src/main/java/org/elasticsearch/license/plugin/LicenseModule.java
+++ b/src/main/java/org/elasticsearch/license/plugin/LicenseModule.java
@@ -7,13 +7,14 @@ package org.elasticsearch.license.plugin;
import org.elasticsearch.common.inject.AbstractModule;
import org.elasticsearch.common.inject.Scopes;
+import org.elasticsearch.license.manager.ESLicenseManager;
import org.elasticsearch.license.plugin.core.LicensesService;
public class LicenseModule extends AbstractModule {
@Override
protected void configure() {
//TODO: bind LicensesManagementService and LicensesValidationService to LicensesServices instead
- //bind(ESLicenseManager.class).asEagerSingleton();
+ bind(ESLicenseManager.class).in(Scopes.SINGLETON);
bind(LicensesService.class).in(Scopes.SINGLETON);
}
}
diff --git a/src/main/java/org/elasticsearch/license/plugin/core/LicensesService.java b/src/main/java/org/elasticsearch/license/plugin/core/LicensesService.java
index fb17db0cb9c..d3b2daf8f08 100644
--- a/src/main/java/org/elasticsearch/license/plugin/core/LicensesService.java
+++ b/src/main/java/org/elasticsearch/license/plugin/core/LicensesService.java
@@ -73,10 +73,10 @@ public class LicensesService extends AbstractLifecycleComponent
private volatile ScheduledFuture notificationScheduler;
@Inject
- public LicensesService(Settings settings, ClusterService clusterService, ThreadPool threadPool, TransportService transportService) {
+ public LicensesService(Settings settings, ClusterService clusterService, ThreadPool threadPool, TransportService transportService, ESLicenseManager esLicenseManager) {
super(settings);
this.clusterService = clusterService;
- this.esLicenseManager = new ESLicenseManager();
+ this.esLicenseManager = esLicenseManager;
this.threadPool = threadPool;
this.transportService = transportService;
transportService.registerHandler(REGISTER_TRIAL_LICENSE_ACTION_NAME, new RegisterTrialLicenseRequestHandler());
diff --git a/src/test/java/org/elasticsearch/license/AbstractLicensingTestBase.java b/src/test/java/org/elasticsearch/license/AbstractLicensingTestBase.java
index 92b5155c83e..21c7bc962d9 100644
--- a/src/test/java/org/elasticsearch/license/AbstractLicensingTestBase.java
+++ b/src/test/java/org/elasticsearch/license/AbstractLicensingTestBase.java
@@ -20,13 +20,13 @@ public class AbstractLicensingTestBase {
@BeforeClass
public static void setup() throws Exception {
- pubKeyPath = getResourcePath("test_pub.key");
- priKeyPath = getResourcePath("test_pri.key");
+ pubKeyPath = getResourcePath("/public.key");
+ priKeyPath = getResourcePath("/private.key");
}
private static String getResourcePath(String resource) throws Exception {
- URL url = ESLicenseManager.class.getResource("/org.elasticsearch.license.plugin/" + resource);
+ URL url = ESLicenseManager.class.getResource(resource);
return url.toURI().getPath();
}
diff --git a/src/test/java/org/elasticsearch/license/plugin/LicenseTransportTests.java b/src/test/java/org/elasticsearch/license/plugin/LicenseTransportTests.java
index 17d57850a42..06575d81abe 100644
--- a/src/test/java/org/elasticsearch/license/plugin/LicenseTransportTests.java
+++ b/src/test/java/org/elasticsearch/license/plugin/LicenseTransportTests.java
@@ -61,8 +61,8 @@ public class LicenseTransportTests extends ElasticsearchIntegrationTest {
@BeforeClass
public static void setup() throws IOException, URISyntaxException {
- priKeyPath = Paths.get(LicenseTransportTests.class.getResource("/org.elasticsearch.license.plugin/test_pri.key").toURI()).toAbsolutePath().toString();
- pubKeyPath = Paths.get(LicenseTransportTests.class.getResource("/org.elasticsearch.license.plugin/test_pub.key").toURI()).toAbsolutePath().toString();
+ priKeyPath = Paths.get(LicenseTransportTests.class.getResource("/private.key").toURI()).toAbsolutePath().toString();
+ pubKeyPath = Paths.get(LicenseTransportTests.class.getResource("/public.key").toURI()).toAbsolutePath().toString();
}
/*
diff --git a/src/test/java/org/elasticsearch/license/plugin/LicensesServiceTests.java b/src/test/java/org/elasticsearch/license/plugin/LicensesServiceTests.java
index 1be183227bf..524859a9d4f 100644
--- a/src/test/java/org/elasticsearch/license/plugin/LicensesServiceTests.java
+++ b/src/test/java/org/elasticsearch/license/plugin/LicensesServiceTests.java
@@ -61,8 +61,8 @@ public class LicensesServiceTests extends ElasticsearchIntegrationTest {
@BeforeClass
public static void setup() throws IOException, URISyntaxException {
- priKeyPath = Paths.get(LicenseTransportTests.class.getResource("/org.elasticsearch.license.plugin/test_pri.key").toURI()).toAbsolutePath().toString();
- pubKeyPath = Paths.get(LicenseTransportTests.class.getResource("/org.elasticsearch.license.plugin/test_pub.key").toURI()).toAbsolutePath().toString();
+ priKeyPath = Paths.get(LicenseTransportTests.class.getResource("/private.key").toURI()).toAbsolutePath().toString();
+ pubKeyPath = Paths.get(LicenseTransportTests.class.getResource("/public.key").toURI()).toAbsolutePath().toString();
}
diff --git a/src/test/resources/org.elasticsearch.license.plugin/test_pri.key b/src/test/resources/private.key
similarity index 100%
rename from src/test/resources/org.elasticsearch.license.plugin/test_pri.key
rename to src/test/resources/private.key
diff --git a/src/test/resources/org.elasticsearch.license.plugin/test_pub.key b/src/test/resources/public.key
similarity index 100%
rename from src/test/resources/org.elasticsearch.license.plugin/test_pub.key
rename to src/test/resources/public.key