fix conflict

Original commit: elastic/x-pack-elasticsearch@d0da2c43e3
This commit is contained in:
Areek Zillur 2014-10-23 12:02:40 -04:00
commit 6f88c44030
12 changed files with 214 additions and 64 deletions

143
pom.xml
View File

@ -11,6 +11,8 @@
<properties>
<elasticsearch.version>1.4.0-SNAPSHOT</elasticsearch.version>
<lucene.version>4.10.1</lucene.version>
<keys.path>${basedir}/src/test/resources</keys.path>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
@ -132,27 +134,20 @@
</dependencies>
<build>
<resources>
<resource>
<directory>${keys.path}</directory>
<filtering>true</filtering>
<includes>
<include>public.key</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>1.3.1</version>
<executions>
<execution>
<id>enforce-versions</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireJavaVersion>
<version>[1.7,)</version>
</requireJavaVersion>
</rules>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
@ -194,30 +189,108 @@
<!-- ============================================================= -->
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.3</version>
<version>2.4</version>
<configuration>
<appendAssemblyId>false</appendAssemblyId>
<outputDirectory>${project.build.directory}/releases/</outputDirectory>
<descriptors>
<descriptor>${basedir}/src/main/assemblies/plugin.xml</descriptor>
</descriptors>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>attached</goal>
</goals>
</execution>
<execution>
<id>assemble-all</id>
<id>plugin</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<appendAssemblyId>false</appendAssemblyId>
<descriptors>
<descriptor>${basedir}/src/main/assemblies/plugin.xml</descriptor>
</descriptors>
</configuration>
</execution>
<execution>
<id>exec</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<appendAssemblyId>true</appendAssemblyId>
<descriptors>
<descriptor>${basedir}/src/main/assemblies/exec.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>1.3.1</version>
<executions>
<execution>
<id>enforce-versions</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireJavaVersion>
<version>[1.7,)</version>
</requireJavaVersion>
</rules>
</configuration>
</execution>
<!-- TODO: do we want to always enforce non-default keys -->
<!-- execution>
<id>enforce-property</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireProperty>
<property>keys.path</property>
<message>"You must set a keys.path property!"</message>
</requireProperty>
</rules>
<fail>true</fail>
</configuration>
</execution -->
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>for-plugin</id>
<phase>prepare-package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<excludes>
<!-- exclude license generation classes -->
<exclude>org/elasticsearch/license/licensor/**/*</exclude>
</excludes>
</configuration>
</execution>
<execution>
<id>for-exec</id>
<phase>prepare-package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classifier>exec</classifier>
<excludes>
<!-- exclude public key -->
<exclude>public.key</exclude>
<!-- exclude plugin-related classes -->
<exclude>org/elasticsearch/license/plugin/**/*</exclude>
</excludes>
</configuration>
</execution>
</executions>
</plugin>

View File

@ -0,0 +1,49 @@
<?xml version="1.0"?>
<assembly>
<id>exec</id>
<formats>
<format>zip</format>
</formats>
<includeBaseDirectory>true</includeBaseDirectory>
<fileSets>
<fileSet>
<filtered>true</filtered>
<directory>bin</directory>
<outputDirectory>bin</outputDirectory>
<fileMode>0755</fileMode>
<directoryMode>0755</directoryMode>
<lineEnding>unix</lineEnding>
<includes>
<include>key-pair-generator</include>
<include>license-generator</include>
<include>verify-license</include>
</includes>
</fileSet>
</fileSets>
<dependencySets>
<dependencySet>
<outputDirectory>/lib</outputDirectory>
<useProjectArtifact>false</useProjectArtifact>
<useProjectAttachments>true</useProjectAttachments>
<useTransitiveFiltering>true</useTransitiveFiltering>
<includes>
<include>org.elasticsearch:elasticsearch-license:*:exec</include>
<include>net.nicholaswilliams.java.licensing:licensing-core</include>
<include>net.nicholaswilliams.java.licensing:licensing-licensor-base</include>
<include>org.elasticsearch:elasticsearch</include>
</includes>
<excludes>
<exclude>org.apache.lucene:*</exclude>
</excludes>
</dependencySet>
<dependencySet>
<outputDirectory>/lib</outputDirectory>
<useProjectArtifact>false</useProjectArtifact>
<useProjectAttachments>true</useProjectAttachments>
<useTransitiveFiltering>true</useTransitiveFiltering>
<includes>
<include>org.apache.lucene:lucene-core</include>
</includes>
</dependencySet>
</dependencySets>
</assembly>

View File

@ -14,5 +14,13 @@
<exclude>org.elasticsearch:elasticsearch</exclude>
</excludes>
</dependencySet>
<dependencySet>
<outputDirectory>/</outputDirectory>
<useProjectArtifact>true</useProjectArtifact>
<useTransitiveFiltering>true</useTransitiveFiltering>
<includes>
<include>net.nicholaswilliams.java.licensing:licensing-core</include>
</includes>
</dependencySet>
</dependencySets>
</assembly>

View File

@ -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);
}
}
}

View File

@ -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();
}

View File

@ -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);
}
}

View File

@ -73,10 +73,10 @@ public class LicensesService extends AbstractLifecycleComponent<LicensesService>
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());

View File

@ -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();
}

View File

@ -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();
}
/*

View File

@ -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();
}