unify encoding; minor fixes & clean up imports
Original commit: elastic/x-pack-elasticsearch@0d00a7b177
This commit is contained in:
parent
3c551ab6d9
commit
1f153402ef
|
@ -7,10 +7,11 @@ package org.elasticsearch.license.core;
|
|||
|
||||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||
import org.elasticsearch.common.xcontent.*;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class ESLicense implements Comparable<ESLicense> {
|
||||
|
||||
|
|
|
@ -5,17 +5,13 @@
|
|||
*/
|
||||
package org.elasticsearch.license.core;
|
||||
|
||||
import org.elasticsearch.common.bytes.BytesArray;
|
||||
import org.elasticsearch.common.bytes.BytesReference;
|
||||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.*;
|
||||
|
||||
public class ESLicenses {
|
||||
|
@ -31,7 +27,7 @@ public class ESLicenses {
|
|||
}
|
||||
|
||||
public static Set<ESLicense> fromSource(String content) throws IOException {
|
||||
return fromSource(content.getBytes(Charset.forName("UTF-8")));
|
||||
return fromSource(content.getBytes(LicensesCharset.UTF_8));
|
||||
}
|
||||
|
||||
public static Set<ESLicense> fromSource(byte[] bytes) throws IOException {
|
||||
|
@ -41,6 +37,7 @@ public class ESLicenses {
|
|||
private static Set<ESLicense> fromXContent(XContentParser parser) throws IOException {
|
||||
Set<ESLicense> esLicenses = new HashSet<>();
|
||||
final Map<String, Object> licensesMap = parser.mapAndClose();
|
||||
@SuppressWarnings("unchecked")
|
||||
final List<Map<String, Object>> licenseMaps = (ArrayList<Map<String, Object>>)licensesMap.get("licenses");
|
||||
for (Map<String, Object> licenseMap : licenseMaps) {
|
||||
final ESLicense esLicense = ESLicense.fromXContent(licenseMap);
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
/*
|
||||
* 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 java.nio.charset.Charset;
|
||||
|
||||
public class LicensesCharset {
|
||||
|
||||
/**
|
||||
* All operations in should use the universal UTF-8 character set.
|
||||
*/
|
||||
public static final Charset UTF_8 = Charset.forName("UTF-8");
|
||||
|
||||
}
|
|
@ -13,13 +13,12 @@ import net.nicholaswilliams.java.licensing.exception.KeyNotFoundException;
|
|||
import net.nicholaswilliams.java.licensing.licensor.LicenseCreator;
|
||||
import net.nicholaswilliams.java.licensing.licensor.LicenseCreatorProperties;
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.elasticsearch.common.collect.ImmutableMap;
|
||||
import org.elasticsearch.common.collect.ImmutableSet;
|
||||
import org.elasticsearch.license.core.*;
|
||||
import org.elasticsearch.license.core.ESLicense;
|
||||
import org.elasticsearch.license.core.LicensesCharset;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
@ -105,7 +104,7 @@ public class ESLicenseSigner {
|
|||
final byte[] licenseSignature = licenseCreator.signAndSerializeLicense(license);
|
||||
final byte[] hash = Hasher.hash(Base64.encodeBase64String(
|
||||
Files.readAllBytes(publicKeyPath))
|
||||
).getBytes(Charset.forName("UTF-8"));
|
||||
).getBytes(LicensesCharset.UTF_8);
|
||||
int headerLength = MAGIC_LENGTH + hash.length + 4 + 4;
|
||||
byte[] bytes = new byte[headerLength + licenseSignature.length];
|
||||
|
||||
|
|
|
@ -8,14 +8,14 @@ package org.elasticsearch.license.licensor;
|
|||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.license.core.DateUtils;
|
||||
import org.elasticsearch.license.core.LicensesCharset;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.text.ParseException;
|
||||
import java.util.*;
|
||||
|
||||
import static org.elasticsearch.license.core.ESLicense.Type;
|
||||
import static org.elasticsearch.license.core.ESLicense.SubscriptionType;
|
||||
import static org.elasticsearch.license.core.ESLicense.Type;
|
||||
|
||||
public class LicenseSpec {
|
||||
final String uid;
|
||||
|
@ -43,7 +43,7 @@ public class LicenseSpec {
|
|||
}
|
||||
|
||||
|
||||
public static class Builder {
|
||||
private static class Builder {
|
||||
private String uid;
|
||||
private String issuer;
|
||||
private String issuedTo;
|
||||
|
@ -104,6 +104,7 @@ public class LicenseSpec {
|
|||
if (uid == null) {
|
||||
uid = UUID.randomUUID().toString();
|
||||
}
|
||||
//TODO: verify params
|
||||
return new LicenseSpec(uid, issuer, issuedTo, issueDate, type, subscriptionType,
|
||||
feature ,expiryDate, maxNodes);
|
||||
}
|
||||
|
@ -128,7 +129,7 @@ public class LicenseSpec {
|
|||
}
|
||||
|
||||
public static Set<LicenseSpec> fromSource(String content) throws IOException, ParseException {
|
||||
return fromSource(content.getBytes(Charset.forName("UTF-8")));
|
||||
return fromSource(content.getBytes(LicensesCharset.UTF_8));
|
||||
}
|
||||
|
||||
public static Set<LicenseSpec> fromSource(byte[] bytes) throws IOException, ParseException {
|
||||
|
@ -138,6 +139,7 @@ public class LicenseSpec {
|
|||
private static Set<LicenseSpec> fromXContents(XContentParser parser) throws IOException, ParseException {
|
||||
Set<LicenseSpec> licenseSpecs = new HashSet<>();
|
||||
final Map<String, Object> licenseSpecMap = parser.mapAndClose();
|
||||
@SuppressWarnings("unchecked")
|
||||
final List<Map<String, Object>> licenseSpecDefinitions = (ArrayList<Map<String, Object>>)licenseSpecMap.get("licenses");
|
||||
for (Map<String, Object> licenseSpecDef : licenseSpecDefinitions) {
|
||||
final LicenseSpec licenseSpec = fromXContent(licenseSpecDef);
|
||||
|
|
|
@ -7,8 +7,6 @@ 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.LicensesManagerService;
|
||||
import org.elasticsearch.license.plugin.core.LicensesService;
|
||||
|
||||
public class LicenseModule extends AbstractModule {
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
package org.elasticsearch.license.plugin;
|
||||
|
||||
import org.elasticsearch.action.ActionModule;
|
||||
import org.elasticsearch.action.admin.cluster.ClusterAction;
|
||||
import org.elasticsearch.cluster.metadata.MetaData;
|
||||
import org.elasticsearch.cluster.node.DiscoveryNode;
|
||||
import org.elasticsearch.common.collect.ImmutableSet;
|
||||
|
@ -22,10 +21,10 @@ 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.LicensesMetaData;
|
||||
import org.elasticsearch.license.plugin.core.LicensesService;
|
||||
import org.elasticsearch.license.plugin.rest.RestDeleteLicenseAction;
|
||||
import org.elasticsearch.license.plugin.rest.RestGetLicenseAction;
|
||||
import org.elasticsearch.license.plugin.rest.RestPutLicenseAction;
|
||||
import org.elasticsearch.license.plugin.core.LicensesService;
|
||||
import org.elasticsearch.plugins.AbstractPlugin;
|
||||
import org.elasticsearch.rest.RestModule;
|
||||
|
||||
|
|
|
@ -5,13 +5,10 @@
|
|||
*/
|
||||
package org.elasticsearch.license.plugin.action.delete;
|
||||
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.action.ActionRequestValidationException;
|
||||
import org.elasticsearch.action.support.master.AcknowledgedRequest;
|
||||
import org.elasticsearch.action.support.master.MasterNodeReadOperationRequest;
|
||||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||
import org.elasticsearch.license.core.ESLicenses;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
|
|
|
@ -17,9 +17,6 @@ import org.elasticsearch.cluster.block.ClusterBlockLevel;
|
|||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.license.plugin.core.LicensesManagerService;
|
||||
import org.elasticsearch.license.plugin.core.LicensesService;
|
||||
import org.elasticsearch.node.Node;
|
||||
import org.elasticsearch.node.internal.InternalNode;
|
||||
import org.elasticsearch.threadpool.ThreadPool;
|
||||
import org.elasticsearch.transport.TransportService;
|
||||
|
||||
|
|
|
@ -14,7 +14,9 @@ import org.elasticsearch.common.xcontent.XContentBuilder;
|
|||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Contains metadata about registered licenses
|
||||
|
|
|
@ -6,16 +6,9 @@
|
|||
package org.elasticsearch.license.plugin.core.trial;
|
||||
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.elasticsearch.common.collect.ImmutableMap;
|
||||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||
import org.elasticsearch.license.core.ESLicenses;
|
||||
import org.elasticsearch.license.core.LicensesCharset;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.elasticsearch.license.plugin.core.trial.TrialLicensesBuilder.trialLicensesBuilder;
|
||||
|
@ -29,17 +22,17 @@ public class TrialLicenseUtils {
|
|||
int uidLen = byteBuffer.getInt();
|
||||
byte[] uidBytes = new byte[uidLen];
|
||||
byteBuffer.get(uidBytes);
|
||||
String uid = new String(uidBytes, Charset.forName("UTF-8"));
|
||||
String uid = new String(uidBytes, LicensesCharset.UTF_8);
|
||||
|
||||
int issuedToLen = byteBuffer.getInt();
|
||||
byte[] issuedToBytes = new byte[issuedToLen];
|
||||
byteBuffer.get(issuedToBytes);
|
||||
String issuedTo = new String(issuedToBytes, Charset.forName("UTF-8"));
|
||||
String issuedTo = new String(issuedToBytes, LicensesCharset.UTF_8);
|
||||
|
||||
int featureLen = byteBuffer.getInt();
|
||||
byte[] featureBytes = new byte[featureLen];
|
||||
byteBuffer.get(featureBytes);
|
||||
String feature = new String(featureBytes, Charset.forName("UTF-8"));
|
||||
String feature = new String(featureBytes, LicensesCharset.UTF_8);
|
||||
|
||||
int maxNodes = byteBuffer.getInt();
|
||||
long issueDate = byteBuffer.getLong();
|
||||
|
@ -56,9 +49,9 @@ public class TrialLicenseUtils {
|
|||
}
|
||||
|
||||
public static String toEncodedTrialLicense(TrialLicenses.TrialLicense trialLicense) {
|
||||
byte[] uidBytes = trialLicense.uid().getBytes(Charset.forName("UTF-8"));
|
||||
byte[] featureBytes = trialLicense.feature().getBytes(Charset.forName("UTF-8"));
|
||||
byte[] issuedToBytes = trialLicense.issuedTo().getBytes(Charset.forName("UTF-8"));
|
||||
byte[] uidBytes = trialLicense.uid().getBytes(LicensesCharset.UTF_8);
|
||||
byte[] featureBytes = trialLicense.feature().getBytes(LicensesCharset.UTF_8);
|
||||
byte[] issuedToBytes = trialLicense.issuedTo().getBytes(LicensesCharset.UTF_8);
|
||||
|
||||
// uid len + uid bytes + issuedTo len + issuedTo bytes + feature bytes length + feature bytes + maxNodes + issueDate + expiryDate
|
||||
int len = 4 + uidBytes.length + 4 + issuedToBytes.length + 4 + featureBytes.length + 4 + 8 + 8;
|
||||
|
|
|
@ -9,7 +9,9 @@ import org.elasticsearch.common.collect.ImmutableMap;
|
|||
import org.elasticsearch.license.core.DateUtils;
|
||||
import org.elasticsearch.license.core.ESLicense;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.elasticsearch.license.plugin.core.trial.TrialLicenses.TrialLicense;
|
||||
|
||||
|
|
|
@ -15,7 +15,6 @@ import java.io.File;
|
|||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.text.ParseException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
|
|
|
@ -11,7 +11,8 @@ import org.elasticsearch.common.collect.ImmutableSet;
|
|||
import org.elasticsearch.common.settings.ImmutableSettings;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.license.TestUtils;
|
||||
import org.elasticsearch.license.core.*;
|
||||
import org.elasticsearch.license.core.ESLicense;
|
||||
import org.elasticsearch.license.core.ESLicenses;
|
||||
import org.elasticsearch.license.manager.Utils;
|
||||
import org.elasticsearch.license.plugin.action.delete.DeleteLicenseRequestBuilder;
|
||||
import org.elasticsearch.license.plugin.action.delete.DeleteLicenseResponse;
|
||||
|
|
|
@ -15,7 +15,8 @@ import org.elasticsearch.common.Nullable;
|
|||
import org.elasticsearch.common.settings.ImmutableSettings;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.license.TestUtils;
|
||||
import org.elasticsearch.license.core.*;
|
||||
import org.elasticsearch.license.core.ESLicense;
|
||||
import org.elasticsearch.license.core.ESLicenses;
|
||||
import org.elasticsearch.license.manager.ESLicenseManager;
|
||||
import org.elasticsearch.license.manager.Utils;
|
||||
import org.elasticsearch.license.plugin.action.put.PutLicenseRequest;
|
||||
|
|
Loading…
Reference in New Issue