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> <properties>
<elasticsearch.version>1.4.0-SNAPSHOT</elasticsearch.version> <elasticsearch.version>1.4.0-SNAPSHOT</elasticsearch.version>
<lucene.version>4.10.1</lucene.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> </properties>
<dependencies> <dependencies>
@ -132,27 +134,20 @@
</dependencies> </dependencies>
<build> <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> <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> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId> <artifactId>maven-compiler-plugin</artifactId>
@ -194,30 +189,108 @@
<!-- ============================================================= --> <!-- ============================================================= -->
<plugin> <plugin>
<artifactId>maven-assembly-plugin</artifactId> <artifactId>maven-assembly-plugin</artifactId>
<version>2.3</version> <version>2.4</version>
<configuration> <configuration>
<appendAssemblyId>false</appendAssemblyId>
<outputDirectory>${project.build.directory}/releases/</outputDirectory> <outputDirectory>${project.build.directory}/releases/</outputDirectory>
<descriptors>
<descriptor>${basedir}/src/main/assemblies/plugin.xml</descriptor>
</descriptors>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration> </configuration>
<executions> <executions>
<execution> <execution>
<phase>package</phase> <id>plugin</id>
<goals>
<goal>attached</goal>
</goals>
</execution>
<execution>
<id>assemble-all</id>
<phase>package</phase> <phase>package</phase>
<goals> <goals>
<goal>single</goal> <goal>single</goal>
</goals> </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> </execution>
</executions> </executions>
</plugin> </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> <exclude>org.elasticsearch:elasticsearch</exclude>
</excludes> </excludes>
</dependencySet> </dependencySet>
<dependencySet>
<outputDirectory>/</outputDirectory>
<useProjectArtifact>true</useProjectArtifact>
<useTransitiveFiltering>true</useTransitiveFiltering>
<includes>
<include>net.nicholaswilliams.java.licensing:licensing-core</include>
</includes>
</dependencySet>
</dependencySets> </dependencySets>
</assembly> </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.ExpiredLicenseException;
import net.nicholaswilliams.java.licensing.exception.InvalidLicenseException; import net.nicholaswilliams.java.licensing.exception.InvalidLicenseException;
import org.elasticsearch.common.collect.ImmutableSet; import org.elasticsearch.common.collect.ImmutableSet;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.license.core.ESLicense; 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.Collection;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map; import java.util.Map;
@ -46,31 +45,18 @@ public class ESLicenseManager {
// Initialize LicenseManager // Initialize LicenseManager
static { static {
LicenseManagerProperties.setPublicKeyDataProvider(new FilePublicKeyDataProvider(getPublicKeyPath())); LicenseManagerProperties.setPublicKeyDataProvider(new ResourcePublicKeyDataProvider("/public.key"));
LicenseManagerProperties.setPublicKeyPasswordProvider(new ESPublicKeyPasswordProvider()); LicenseManagerProperties.setPublicKeyPasswordProvider(new ESPublicKeyPasswordProvider());
LicenseManagerProperties.setLicenseValidator(new DefaultLicenseValidator()); LicenseManagerProperties.setLicenseValidator(new DefaultLicenseValidator());
LicenseManagerProperties.setLicenseProvider(new LicenseProvider() { LicenseManagerProperties.setLicenseProvider(new LicenseProvider() {
@Override @Override
public SignedLicense getLicense(Object context) { 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() { @Inject
//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);
}
}
public ESLicenseManager() { public ESLicenseManager() {
this.licenseManager = LicenseManager.getInstance(); 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.AbstractModule;
import org.elasticsearch.common.inject.Scopes; import org.elasticsearch.common.inject.Scopes;
import org.elasticsearch.license.manager.ESLicenseManager;
import org.elasticsearch.license.plugin.core.LicensesService; import org.elasticsearch.license.plugin.core.LicensesService;
public class LicenseModule extends AbstractModule { public class LicenseModule extends AbstractModule {
@Override @Override
protected void configure() { protected void configure() {
//TODO: bind LicensesManagementService and LicensesValidationService to LicensesServices instead //TODO: bind LicensesManagementService and LicensesValidationService to LicensesServices instead
//bind(ESLicenseManager.class).asEagerSingleton(); bind(ESLicenseManager.class).in(Scopes.SINGLETON);
bind(LicensesService.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; private volatile ScheduledFuture notificationScheduler;
@Inject @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); super(settings);
this.clusterService = clusterService; this.clusterService = clusterService;
this.esLicenseManager = new ESLicenseManager(); this.esLicenseManager = esLicenseManager;
this.threadPool = threadPool; this.threadPool = threadPool;
this.transportService = transportService; this.transportService = transportService;
transportService.registerHandler(REGISTER_TRIAL_LICENSE_ACTION_NAME, new RegisterTrialLicenseRequestHandler()); transportService.registerHandler(REGISTER_TRIAL_LICENSE_ACTION_NAME, new RegisterTrialLicenseRequestHandler());

View File

@ -20,13 +20,13 @@ public class AbstractLicensingTestBase {
@BeforeClass @BeforeClass
public static void setup() throws Exception { public static void setup() throws Exception {
pubKeyPath = getResourcePath("test_pub.key"); pubKeyPath = getResourcePath("/public.key");
priKeyPath = getResourcePath("test_pri.key"); priKeyPath = getResourcePath("/private.key");
} }
private static String getResourcePath(String resource) throws Exception { 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(); return url.toURI().getPath();
} }

View File

@ -61,8 +61,8 @@ public class LicenseTransportTests extends ElasticsearchIntegrationTest {
@BeforeClass @BeforeClass
public static void setup() throws IOException, URISyntaxException { public static void setup() throws IOException, URISyntaxException {
priKeyPath = Paths.get(LicenseTransportTests.class.getResource("/org.elasticsearch.license.plugin/test_pri.key").toURI()).toAbsolutePath().toString(); priKeyPath = Paths.get(LicenseTransportTests.class.getResource("/private.key").toURI()).toAbsolutePath().toString();
pubKeyPath = Paths.get(LicenseTransportTests.class.getResource("/org.elasticsearch.license.plugin/test_pub.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 @BeforeClass
public static void setup() throws IOException, URISyntaxException { public static void setup() throws IOException, URISyntaxException {
priKeyPath = Paths.get(LicenseTransportTests.class.getResource("/org.elasticsearch.license.plugin/test_pri.key").toURI()).toAbsolutePath().toString(); priKeyPath = Paths.get(LicenseTransportTests.class.getResource("/private.key").toURI()).toAbsolutePath().toString();
pubKeyPath = Paths.get(LicenseTransportTests.class.getResource("/org.elasticsearch.license.plugin/test_pub.key").toURI()).toAbsolutePath().toString(); pubKeyPath = Paths.get(LicenseTransportTests.class.getResource("/public.key").toURI()).toAbsolutePath().toString();
} }