Use method references rather than Class instances to register transport handler.

This is caused by upstream changes in core.

Original commit: elastic/x-pack-elasticsearch@67f602abd1
This commit is contained in:
Simon Willnauer 2015-09-14 10:07:35 +02:00
parent ddcc757bb3
commit 6fb4f7817c
28 changed files with 82 additions and 86 deletions

View File

@ -5,7 +5,6 @@
*/ */
package org.elasticsearch.marvel.agent.renderer.cluster; package org.elasticsearch.marvel.agent.renderer.cluster;
import com.google.common.base.Charsets;
import com.google.common.hash.Hashing; import com.google.common.hash.Hashing;
import org.elasticsearch.action.admin.cluster.stats.ClusterStatsResponse; import org.elasticsearch.action.admin.cluster.stats.ClusterStatsResponse;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContent;
@ -16,6 +15,7 @@ import org.elasticsearch.marvel.agent.collector.cluster.ClusterInfoMarvelDoc;
import org.elasticsearch.marvel.agent.renderer.AbstractRenderer; import org.elasticsearch.marvel.agent.renderer.AbstractRenderer;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.List; import java.util.List;
public class ClusterInfoRenderer extends AbstractRenderer<ClusterInfoMarvelDoc> { public class ClusterInfoRenderer extends AbstractRenderer<ClusterInfoMarvelDoc> {
@ -64,7 +64,7 @@ public class ClusterInfoRenderer extends AbstractRenderer<ClusterInfoMarvelDoc>
public static String hash(String licenseStatus, String licenseUid, String licenseType, String licenseExpiryDate, String clusterUUID) { public static String hash(String licenseStatus, String licenseUid, String licenseType, String licenseExpiryDate, String clusterUUID) {
String toHash = licenseStatus + licenseUid + licenseType + licenseExpiryDate + clusterUUID; String toHash = licenseStatus + licenseUid + licenseType + licenseExpiryDate + clusterUUID;
return Hashing.sha256().hashString(toHash, Charsets.UTF_8).toString(); return Hashing.sha256().hashString(toHash, StandardCharsets.UTF_8).toString();
} }
static final class Fields { static final class Fields {

View File

@ -36,7 +36,7 @@ public class TransportClearRealmCacheAction extends TransportNodesAction<ClearRe
ActionFilters actionFilters, Realms realms, ActionFilters actionFilters, Realms realms,
IndexNameExpressionResolver indexNameExpressionResolver) { IndexNameExpressionResolver indexNameExpressionResolver) {
super(settings, ClearRealmCacheAction.NAME, clusterName, threadPool, clusterService, transportService, actionFilters, super(settings, ClearRealmCacheAction.NAME, clusterName, threadPool, clusterService, transportService, actionFilters,
indexNameExpressionResolver, ClearRealmCacheRequest.class, ClearRealmCacheRequest.Node.class, ThreadPool.Names.MANAGEMENT); indexNameExpressionResolver, ClearRealmCacheRequest::new, ClearRealmCacheRequest.Node::new, ThreadPool.Names.MANAGEMENT);
this.realms = realms; this.realms = realms;
} }

View File

@ -5,7 +5,6 @@
*/ */
package org.elasticsearch.shield.authc.esusers; package org.elasticsearch.shield.authc.esusers;
import com.google.common.base.Charsets;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import org.elasticsearch.ElasticsearchException; import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.common.inject.internal.Nullable; import org.elasticsearch.common.inject.internal.Nullable;
@ -25,6 +24,7 @@ import org.elasticsearch.watcher.ResourceWatcherService;
import java.io.IOException; import java.io.IOException;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.List; import java.util.List;
@ -130,7 +130,7 @@ public class FileUserPasswdStore {
List<String> lines; List<String> lines;
try { try {
lines = Files.readAllLines(path, Charsets.UTF_8); lines = Files.readAllLines(path, StandardCharsets.UTF_8);
} catch (IOException ioe) { } catch (IOException ioe) {
throw new IllegalStateException("could not read users file [" + path.toAbsolutePath() + "]", ioe); throw new IllegalStateException("could not read users file [" + path.toAbsolutePath() + "]", ioe);
} }

View File

@ -5,7 +5,6 @@
*/ */
package org.elasticsearch.shield.authc.esusers; package org.elasticsearch.shield.authc.esusers;
import com.google.common.base.Charsets;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import org.elasticsearch.ElasticsearchException; import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.common.Strings; import org.elasticsearch.common.Strings;
@ -24,6 +23,7 @@ import org.elasticsearch.watcher.ResourceWatcherService;
import java.io.IOException; import java.io.IOException;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.*; import java.util.*;
@ -122,7 +122,7 @@ public class FileUserRolesStore {
List<String> lines; List<String> lines;
try { try {
lines = Files.readAllLines(path, Charsets.UTF_8); lines = Files.readAllLines(path, StandardCharsets.UTF_8);
} catch (IOException ioe) { } catch (IOException ioe) {
throw new ElasticsearchException("could not read users file [" + path.toAbsolutePath() + "]", ioe); throw new ElasticsearchException("could not read users file [" + path.toAbsolutePath() + "]", ioe);
} }

View File

@ -5,10 +5,9 @@
*/ */
package org.elasticsearch.shield.authc.support; package org.elasticsearch.shield.authc.support;
import com.google.common.base.Charsets;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.CharBuffer; import java.nio.CharBuffer;
import java.nio.charset.StandardCharsets;
import java.util.Arrays; import java.util.Arrays;
/** /**
@ -18,7 +17,7 @@ public class CharArrays {
public static char[] utf8BytesToChars(byte[] utf8Bytes) { public static char[] utf8BytesToChars(byte[] utf8Bytes) {
ByteBuffer byteBuffer = ByteBuffer.wrap(utf8Bytes); ByteBuffer byteBuffer = ByteBuffer.wrap(utf8Bytes);
CharBuffer charBuffer = Charsets.UTF_8.decode(byteBuffer); CharBuffer charBuffer = StandardCharsets.UTF_8.decode(byteBuffer);
char[] chars = Arrays.copyOfRange(charBuffer.array(), charBuffer.position(), charBuffer.limit()); char[] chars = Arrays.copyOfRange(charBuffer.array(), charBuffer.position(), charBuffer.limit());
byteBuffer.clear(); byteBuffer.clear();
charBuffer.clear(); charBuffer.clear();
@ -39,7 +38,7 @@ public class CharArrays {
public static byte[] toUtf8Bytes(char[] chars) { public static byte[] toUtf8Bytes(char[] chars) {
CharBuffer charBuffer = CharBuffer.wrap(chars); CharBuffer charBuffer = CharBuffer.wrap(chars);
ByteBuffer byteBuffer = Charsets.UTF_8.encode(charBuffer); ByteBuffer byteBuffer = StandardCharsets.UTF_8.encode(charBuffer);
byte[] bytes = Arrays.copyOfRange(byteBuffer.array(), byteBuffer.position(), byteBuffer.limit()); byte[] bytes = Arrays.copyOfRange(byteBuffer.array(), byteBuffer.position(), byteBuffer.limit());
Arrays.fill(byteBuffer.array(), (byte) 0); // clear sensitive data Arrays.fill(byteBuffer.array(), (byte) 0); // clear sensitive data
return bytes; return bytes;

View File

@ -5,9 +5,9 @@
*/ */
package org.elasticsearch.shield.authc.support; package org.elasticsearch.shield.authc.support;
import com.google.common.base.Charsets;
import org.elasticsearch.common.Base64; import org.elasticsearch.common.Base64;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest; import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.util.Locale; import java.util.Locale;
@ -211,7 +211,7 @@ public enum Hasher {
char[] saltAndHash = hashStr.toCharArray(); char[] saltAndHash = hashStr.toCharArray();
MessageDigest md = SHA256Provider.sha256(); MessageDigest md = SHA256Provider.sha256();
md.update(CharArrays.toUtf8Bytes(text.internalChars())); md.update(CharArrays.toUtf8Bytes(text.internalChars()));
md.update(new String(saltAndHash, 0, 8).getBytes(Charsets.UTF_8)); md.update(new String(saltAndHash, 0, 8).getBytes(StandardCharsets.UTF_8));
String computedHash = Base64.encodeBytes(md.digest()); String computedHash = Base64.encodeBytes(md.digest());
return SecuredString.constantTimeEquals(computedHash, new String(saltAndHash, 8, saltAndHash.length - 8)); return SecuredString.constantTimeEquals(computedHash, new String(saltAndHash, 8, saltAndHash.length - 8));
} }

View File

@ -6,7 +6,6 @@
package org.elasticsearch.shield.authz.store; package org.elasticsearch.shield.authz.store;
import com.fasterxml.jackson.dataformat.yaml.snakeyaml.error.YAMLException; import com.fasterxml.jackson.dataformat.yaml.snakeyaml.error.YAMLException;
import com.google.common.base.Charsets;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import org.elasticsearch.ElasticsearchException; import org.elasticsearch.ElasticsearchException;
@ -35,6 +34,7 @@ import org.elasticsearch.watcher.FileWatcher;
import org.elasticsearch.watcher.ResourceWatcherService; import org.elasticsearch.watcher.ResourceWatcherService;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.*; import java.util.*;
@ -370,7 +370,7 @@ public class FileRolesStore extends AbstractLifecycleComponent<RolesStore> imple
private static List<String> roleSegments(Path path) throws IOException { private static List<String> roleSegments(Path path) throws IOException {
List<String> segments = new ArrayList<>(); List<String> segments = new ArrayList<>();
StringBuilder builder = null; StringBuilder builder = null;
for (String line : Files.readAllLines(path, Charsets.UTF_8)) { for (String line : Files.readAllLines(path, StandardCharsets.UTF_8)) {
if (!SKIP_LINE.matcher(line).matches()) { if (!SKIP_LINE.matcher(line).matches()) {
if (IN_SEGMENT_LINE.matcher(line).matches()) { if (IN_SEGMENT_LINE.matcher(line).matches()) {
if (builder != null) { if (builder != null) {

View File

@ -5,7 +5,6 @@
*/ */
package org.elasticsearch.shield.crypto; package org.elasticsearch.shield.crypto;
import com.google.common.base.Charsets;
import org.elasticsearch.ElasticsearchException; import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.common.Base64; import org.elasticsearch.common.Base64;
import org.elasticsearch.common.component.AbstractLifecycleComponent; import org.elasticsearch.common.component.AbstractLifecycleComponent;
@ -22,6 +21,7 @@ import javax.crypto.*;
import javax.crypto.spec.IvParameterSpec; import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec; import javax.crypto.spec.SecretKeySpec;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.security.MessageDigest; import java.security.MessageDigest;
@ -49,7 +49,7 @@ public class InternalCryptoService extends AbstractLifecycleComponent<InternalCr
static final String DEFAULT_ENCRYPTION_ALGORITHM = "AES/CTR/NoPadding"; static final String DEFAULT_ENCRYPTION_ALGORITHM = "AES/CTR/NoPadding";
static final String DEFAULT_KEY_ALGORITH = "AES"; static final String DEFAULT_KEY_ALGORITH = "AES";
static final String ENCRYPTED_TEXT_PREFIX = "::es_encrypted::"; static final String ENCRYPTED_TEXT_PREFIX = "::es_encrypted::";
static final byte[] ENCRYPTED_BYTE_PREFIX = ENCRYPTED_TEXT_PREFIX.getBytes(Charsets.UTF_8); static final byte[] ENCRYPTED_BYTE_PREFIX = ENCRYPTED_TEXT_PREFIX.getBytes(StandardCharsets.UTF_8);
static final int DEFAULT_KEY_LENGTH = 128; static final int DEFAULT_KEY_LENGTH = 128;
private static final Pattern SIG_PATTERN = Pattern.compile("^\\$\\$[0-9]+\\$\\$.+"); private static final Pattern SIG_PATTERN = Pattern.compile("^\\$\\$[0-9]+\\$\\$.+");
@ -338,7 +338,7 @@ public class InternalCryptoService extends AbstractLifecycleComponent<InternalCr
private static String signInternal(String text, SecretKey key) throws IOException { private static String signInternal(String text, SecretKey key) throws IOException {
Mac mac = createMac(key); Mac mac = createMac(key);
byte[] sig = mac.doFinal(text.getBytes(Charsets.UTF_8)); byte[] sig = mac.doFinal(text.getBytes(StandardCharsets.UTF_8));
return Base64.encodeBytes(sig, 0, sig.length, Base64.URL_SAFE); return Base64.encodeBytes(sig, 0, sig.length, Base64.URL_SAFE);
} }

View File

@ -5,11 +5,11 @@
*/ */
package org.elasticsearch.shield.support; package org.elasticsearch.shield.support;
import com.google.common.base.Charsets;
import org.elasticsearch.env.Environment; import org.elasticsearch.env.Environment;
import java.io.IOException; import java.io.IOException;
import java.io.Writer; import java.io.Writer;
import java.nio.charset.StandardCharsets;
import java.nio.file.*; import java.nio.file.*;
import java.nio.file.attribute.PosixFileAttributeView; import java.nio.file.attribute.PosixFileAttributeView;
import java.nio.file.attribute.PosixFileAttributes; import java.nio.file.attribute.PosixFileAttributes;
@ -32,7 +32,7 @@ public class ShieldFiles {
*/ */
public static final Writer openAtomicMoveWriter(final Path path) throws IOException { public static final Writer openAtomicMoveWriter(final Path path) throws IOException {
final Path tempFile = Files.createTempFile(path.getParent(), path.getFileName().toString(), "tmp"); final Path tempFile = Files.createTempFile(path.getParent(), path.getFileName().toString(), "tmp");
final Writer writer = Files.newBufferedWriter(tempFile, Charsets.UTF_8, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.WRITE); final Writer writer = Files.newBufferedWriter(tempFile, StandardCharsets.UTF_8, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.WRITE);
return new Writer() { return new Writer() {
@Override @Override
public void write(char[] cbuf, int off, int len) throws IOException { public void write(char[] cbuf, int off, int len) throws IOException {

View File

@ -20,7 +20,7 @@ import org.elasticsearch.transport.netty.NettyTransport;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.concurrent.Callable; import java.util.function.Supplier;
import static org.elasticsearch.shield.transport.netty.ShieldNettyTransport.*; import static org.elasticsearch.shield.transport.netty.ShieldNettyTransport.*;
@ -63,13 +63,7 @@ public class ShieldServerTransportService extends TransportService {
} }
@Override @Override
public <Request extends TransportRequest> void registerRequestHandler(String action, Class<Request> request, String executor, boolean forceExecution, TransportRequestHandler<Request> handler) { public <Request extends TransportRequest> void registerRequestHandler(String action, Supplier<Request> requestFactory, String executor, TransportRequestHandler<Request> handler) {
TransportRequestHandler<Request> wrappedHandler = new ProfileSecuredRequestHandler<>(action, handler, profileFilters);
super.registerRequestHandler(action, request, executor, forceExecution, wrappedHandler);
}
@Override
public <Request extends TransportRequest> void registerRequestHandler(String action, Callable<Request> requestFactory, String executor, TransportRequestHandler<Request> handler) {
TransportRequestHandler<Request> wrappedHandler = new ProfileSecuredRequestHandler<>(action, handler, profileFilters); TransportRequestHandler<Request> wrappedHandler = new ProfileSecuredRequestHandler<>(action, handler, profileFilters);
super.registerRequestHandler(action, requestFactory, executor, wrappedHandler); super.registerRequestHandler(action, requestFactory, executor, wrappedHandler);
} }

View File

@ -5,7 +5,6 @@
*/ */
package org.elasticsearch.shield.authc; package org.elasticsearch.shield.authc;
import com.google.common.base.Charsets;
import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.CloseableHttpClient;
@ -20,6 +19,7 @@ import org.elasticsearch.test.ShieldIntegTestCase;
import org.junit.Test; import org.junit.Test;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.Locale; import java.util.Locale;
import static org.hamcrest.Matchers.*; import static org.hamcrest.Matchers.*;
@ -56,7 +56,7 @@ public class AnonymousUserTests extends ShieldIntegTestCase {
try (CloseableHttpClient client = HttpClients.createDefault(); try (CloseableHttpClient client = HttpClients.createDefault();
CloseableHttpResponse response = client.execute(new HttpGet(getNodeUrl() + "_nodes"))) { CloseableHttpResponse response = client.execute(new HttpGet(getNodeUrl() + "_nodes"))) {
int statusCode = response.getStatusLine().getStatusCode(); int statusCode = response.getStatusLine().getStatusCode();
String data = Streams.copyToString(new InputStreamReader(response.getEntity().getContent(), Charsets.UTF_8)); String data = Streams.copyToString(new InputStreamReader(response.getEntity().getContent(), StandardCharsets.UTF_8));
if (authorizationExceptionsEnabled) { if (authorizationExceptionsEnabled) {
assertThat(statusCode, is(403)); assertThat(statusCode, is(403));
assertThat(response.getFirstHeader("WWW-Authenticate"), nullValue()); assertThat(response.getFirstHeader("WWW-Authenticate"), nullValue());

View File

@ -5,7 +5,6 @@
*/ */
package org.elasticsearch.shield.authc.esusers; package org.elasticsearch.shield.authc.esusers;
import com.google.common.base.Charsets;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.logging.ESLogger;
import org.elasticsearch.common.logging.ESLoggerFactory; import org.elasticsearch.common.logging.ESLoggerFactory;
@ -24,6 +23,7 @@ import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import java.io.BufferedWriter; import java.io.BufferedWriter;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.StandardCopyOption; import java.nio.file.StandardCopyOption;
@ -69,7 +69,7 @@ public class FileUserPasswdStoreTests extends ESTestCase {
Path file = createTempFile(); Path file = createTempFile();
// writing in utf_16 should cause a parsing error as we try to read the file in utf_8 // writing in utf_16 should cause a parsing error as we try to read the file in utf_8
Files.write(file, Collections.singletonList("aldlfkjldjdflkjd"), Charsets.UTF_16); Files.write(file, Collections.singletonList("aldlfkjldjdflkjd"), StandardCharsets.UTF_16);
Settings esusersSettings = Settings.builder() Settings esusersSettings = Settings.builder()
.put("files.users", file.toAbsolutePath()) .put("files.users", file.toAbsolutePath())
@ -108,7 +108,7 @@ public class FileUserPasswdStoreTests extends ESTestCase {
watcherService.start(); watcherService.start();
try (BufferedWriter writer = Files.newBufferedWriter(tmp, Charsets.UTF_8, StandardOpenOption.APPEND)) { try (BufferedWriter writer = Files.newBufferedWriter(tmp, StandardCharsets.UTF_8, StandardOpenOption.APPEND)) {
writer.newLine(); writer.newLine();
writer.append("foobar:").append(new String(Hasher.BCRYPT.hash(SecuredStringTests.build("barfoo")))); writer.append("foobar:").append(new String(Hasher.BCRYPT.hash(SecuredStringTests.build("barfoo"))));
} }
@ -148,7 +148,7 @@ public class FileUserPasswdStoreTests extends ESTestCase {
watcherService.start(); watcherService.start();
// now replacing the content of the users file with something that cannot be read // now replacing the content of the users file with something that cannot be read
Files.write(tmp, Collections.singletonList("aldlfkjldjdflkjd"), Charsets.UTF_16); Files.write(tmp, Collections.singletonList("aldlfkjldjdflkjd"), StandardCharsets.UTF_16);
if (!latch.await(5, TimeUnit.SECONDS)) { if (!latch.await(5, TimeUnit.SECONDS)) {
fail("Waited too long for the updated file to be picked up"); fail("Waited too long for the updated file to be picked up");
@ -200,7 +200,7 @@ public class FileUserPasswdStoreTests extends ESTestCase {
public void testParseFile_WhenCannotReadFile() throws Exception { public void testParseFile_WhenCannotReadFile() throws Exception {
Path file = createTempFile(); Path file = createTempFile();
// writing in utf_16 should cause a parsing error as we try to read the file in utf_8 // writing in utf_16 should cause a parsing error as we try to read the file in utf_8
Files.write(file, Collections.singletonList("aldlfkjldjdflkjd"), Charsets.UTF_16); Files.write(file, Collections.singletonList("aldlfkjldjdflkjd"), StandardCharsets.UTF_16);
CapturingLogger logger = new CapturingLogger(CapturingLogger.Level.INFO); CapturingLogger logger = new CapturingLogger(CapturingLogger.Level.INFO);
try { try {
FileUserPasswdStore.parseFile(file, logger); FileUserPasswdStore.parseFile(file, logger);
@ -213,7 +213,7 @@ public class FileUserPasswdStoreTests extends ESTestCase {
@Test @Test
public void testParseFile_InvalidLineDoesNotResultInLoggerNPE() throws Exception { public void testParseFile_InvalidLineDoesNotResultInLoggerNPE() throws Exception {
Path file = createTempFile(); Path file = createTempFile();
Files.write(file, Arrays.asList("NotValidUsername=Password", "user:pass"), Charsets.UTF_8); Files.write(file, Arrays.asList("NotValidUsername=Password", "user:pass"), StandardCharsets.UTF_8);
Map<String, char[]> users = FileUserPasswdStore.parseFile(file, null); Map<String, char[]> users = FileUserPasswdStore.parseFile(file, null);
assertThat(users, notNullValue()); assertThat(users, notNullValue());
assertThat(users.keySet(), hasSize(1)); assertThat(users.keySet(), hasSize(1));
@ -223,7 +223,7 @@ public class FileUserPasswdStoreTests extends ESTestCase {
public void testParseFileLenient_WhenCannotReadFile() throws Exception { public void testParseFileLenient_WhenCannotReadFile() throws Exception {
Path file = createTempFile(); Path file = createTempFile();
// writing in utf_16 should cause a parsing error as we try to read the file in utf_8 // writing in utf_16 should cause a parsing error as we try to read the file in utf_8
Files.write(file, Collections.singletonList("aldlfkjldjdflkjd"), Charsets.UTF_16); Files.write(file, Collections.singletonList("aldlfkjldjdflkjd"), StandardCharsets.UTF_16);
CapturingLogger logger = new CapturingLogger(CapturingLogger.Level.INFO); CapturingLogger logger = new CapturingLogger(CapturingLogger.Level.INFO);
Map<String, char[]> users = FileUserPasswdStore.parseFileLenient(file, logger); Map<String, char[]> users = FileUserPasswdStore.parseFileLenient(file, logger);
assertThat(users, notNullValue()); assertThat(users, notNullValue());
@ -236,7 +236,7 @@ public class FileUserPasswdStoreTests extends ESTestCase {
@Test @Test
public void testParseFileWithLineWithEmptyPasswordAndWhitespace() throws Exception { public void testParseFileWithLineWithEmptyPasswordAndWhitespace() throws Exception {
Path file = createTempFile(); Path file = createTempFile();
Files.write(file, Collections.singletonList("user: "), Charsets.UTF_8); Files.write(file, Collections.singletonList("user: "), StandardCharsets.UTF_8);
Map<String, char[]> users = FileUserPasswdStore.parseFile(file, null); Map<String, char[]> users = FileUserPasswdStore.parseFile(file, null);
assertThat(users, notNullValue()); assertThat(users, notNullValue());
assertThat(users.keySet(), is(empty())); assertThat(users.keySet(), is(empty()));

View File

@ -5,7 +5,6 @@
*/ */
package org.elasticsearch.shield.authc.esusers; package org.elasticsearch.shield.authc.esusers;
import com.google.common.base.Charsets;
import org.elasticsearch.common.Strings; import org.elasticsearch.common.Strings;
import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.logging.ESLogger;
import org.elasticsearch.common.logging.ESLoggerFactory; import org.elasticsearch.common.logging.ESLoggerFactory;
@ -22,6 +21,7 @@ import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import java.io.BufferedWriter; import java.io.BufferedWriter;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.StandardCopyOption; import java.nio.file.StandardCopyOption;
@ -66,7 +66,7 @@ public class FileUserRolesStoreTests extends ESTestCase {
lines.add("aldlfkjldjdflkjd"); lines.add("aldlfkjldjdflkjd");
// writing in utf_16 should cause a parsing error as we try to read the file in utf_8 // writing in utf_16 should cause a parsing error as we try to read the file in utf_8
Files.write(file, lines, Charsets.UTF_16); Files.write(file, lines, StandardCharsets.UTF_16);
Settings esusersSettings = Settings.builder() Settings esusersSettings = Settings.builder()
.put("files.users_roles", file.toAbsolutePath()) .put("files.users_roles", file.toAbsolutePath())
@ -107,7 +107,7 @@ public class FileUserRolesStoreTests extends ESTestCase {
watcherService.start(); watcherService.start();
try (BufferedWriter writer = Files.newBufferedWriter(tmp, Charsets.UTF_8, StandardOpenOption.APPEND)) { try (BufferedWriter writer = Files.newBufferedWriter(tmp, StandardCharsets.UTF_8, StandardOpenOption.APPEND)) {
writer.newLine(); writer.newLine();
writer.append("role4:user4\nrole5:user4\n"); writer.append("role4:user4\nrole5:user4\n");
} }
@ -152,7 +152,7 @@ public class FileUserRolesStoreTests extends ESTestCase {
watcherService.start(); watcherService.start();
// now replacing the content of the users file with something that cannot be read // now replacing the content of the users file with something that cannot be read
Files.write(tmp, Collections.singletonList("aldlfkjldjdflkjd"), Charsets.UTF_16); Files.write(tmp, Collections.singletonList("aldlfkjldjdflkjd"), StandardCharsets.UTF_16);
if (!latch.await(5, TimeUnit.SECONDS)) { if (!latch.await(5, TimeUnit.SECONDS)) {
fail("Waited too long for the updated file to be picked up"); fail("Waited too long for the updated file to be picked up");
@ -205,7 +205,7 @@ public class FileUserRolesStoreTests extends ESTestCase {
lines.add("aldlfkjldjdflkjd"); lines.add("aldlfkjldjdflkjd");
// writing in utf_16 should cause a parsing error as we try to read the file in utf_8 // writing in utf_16 should cause a parsing error as we try to read the file in utf_8
Files.write(file, lines, Charsets.UTF_16); Files.write(file, lines, StandardCharsets.UTF_16);
CapturingLogger logger = new CapturingLogger(CapturingLogger.Level.INFO); CapturingLogger logger = new CapturingLogger(CapturingLogger.Level.INFO);
try { try {
FileUserRolesStore.parseFile(file, logger); FileUserRolesStore.parseFile(file, logger);
@ -267,7 +267,7 @@ public class FileUserRolesStoreTests extends ESTestCase {
lines.add("aldlfkjldjdflkjd"); lines.add("aldlfkjldjdflkjd");
// writing in utf_16 should cause a parsing error as we try to read the file in utf_8 // writing in utf_16 should cause a parsing error as we try to read the file in utf_8
Files.write(file, lines, Charsets.UTF_16); Files.write(file, lines, StandardCharsets.UTF_16);
CapturingLogger logger = new CapturingLogger(CapturingLogger.Level.INFO); CapturingLogger logger = new CapturingLogger(CapturingLogger.Level.INFO);
Map<String, String[]> usersRoles = FileUserRolesStore.parseFileLenient(file, logger); Map<String, String[]> usersRoles = FileUserRolesStore.parseFileLenient(file, logger);
assertThat(usersRoles, notNullValue()); assertThat(usersRoles, notNullValue());
@ -279,13 +279,13 @@ public class FileUserRolesStoreTests extends ESTestCase {
private Path writeUsersRoles(String input) throws Exception { private Path writeUsersRoles(String input) throws Exception {
Path file = createTempFile(); Path file = createTempFile();
Files.write(file, input.getBytes(Charsets.UTF_8)); Files.write(file, input.getBytes(StandardCharsets.UTF_8));
return file; return file;
} }
private void assertInvalidInputIsSilentlyIgnored(String input) throws Exception { private void assertInvalidInputIsSilentlyIgnored(String input) throws Exception {
Path file = createTempFile(); Path file = createTempFile();
Files.write(file, input.getBytes(Charsets.UTF_8)); Files.write(file, input.getBytes(StandardCharsets.UTF_8));
Map<String, String[]> usersRoles = FileUserRolesStore.parseFile(file, null); Map<String, String[]> usersRoles = FileUserRolesStore.parseFile(file, null);
assertThat(String.format(Locale.ROOT, "Expected userRoles to be empty, but was %s", usersRoles.keySet()), usersRoles.keySet(), hasSize(0)); assertThat(String.format(Locale.ROOT, "Expected userRoles to be empty, but was %s", usersRoles.keySet()), usersRoles.keySet(), hasSize(0));
} }

View File

@ -5,7 +5,6 @@
*/ */
package org.elasticsearch.shield.authc.esusers.tool; package org.elasticsearch.shield.authc.esusers.tool;
import com.google.common.base.Charsets;
import org.elasticsearch.common.Strings; import org.elasticsearch.common.Strings;
import org.elasticsearch.common.cli.CliTool; import org.elasticsearch.common.cli.CliTool;
import org.elasticsearch.common.cli.CliToolTestCase; import org.elasticsearch.common.cli.CliToolTestCase;
@ -18,6 +17,7 @@ import org.elasticsearch.shield.authc.support.SecuredStringTests;
import org.junit.Test; import org.junit.Test;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.List; import java.util.List;
@ -122,7 +122,7 @@ public class ESUsersToolTests extends CliToolTestCase {
assertThat(status, is(CliTool.ExitStatus.OK)); assertThat(status, is(CliTool.ExitStatus.OK));
assertFileExists(userFile); assertFileExists(userFile);
List<String> lines = Files.readAllLines(userFile, Charsets.UTF_8); List<String> lines = Files.readAllLines(userFile, StandardCharsets.UTF_8);
assertThat(lines.size(), is(1)); assertThat(lines.size(), is(1));
// we can't just hash again and compare the lines, as every time we hash a new salt is generated // we can't just hash again and compare the lines, as every time we hash a new salt is generated
// instead we'll just verify the generated hash against the correct password. // instead we'll just verify the generated hash against the correct password.
@ -132,7 +132,7 @@ public class ESUsersToolTests extends CliToolTestCase {
assertThat(Hasher.BCRYPT.verify(SecuredStringTests.build("changeme"), hash.toCharArray()), is(true)); assertThat(Hasher.BCRYPT.verify(SecuredStringTests.build("changeme"), hash.toCharArray()), is(true));
assertFileExists(userRolesFile); assertFileExists(userRolesFile);
lines = Files.readAllLines(userRolesFile, Charsets.UTF_8); lines = Files.readAllLines(userRolesFile, StandardCharsets.UTF_8);
assertThat(lines, hasSize(2)); assertThat(lines, hasSize(2));
assertThat(lines, containsInAnyOrder("r1:user1", "r2:user1")); assertThat(lines, containsInAnyOrder("r1:user1", "r2:user1"));
} }
@ -154,7 +154,7 @@ public class ESUsersToolTests extends CliToolTestCase {
assertThat(status, is(CliTool.ExitStatus.OK)); assertThat(status, is(CliTool.ExitStatus.OK));
assertFileExists(userFile); assertFileExists(userFile);
List<String> lines = Files.readAllLines(userFile, Charsets.UTF_8); List<String> lines = Files.readAllLines(userFile, StandardCharsets.UTF_8);
assertThat(lines, hasSize(2)); assertThat(lines, hasSize(2));
assertThat(lines, hasItem("user2:hash2")); assertThat(lines, hasItem("user2:hash2"));
assertThat(lines, hasItem(startsWith("user1:"))); assertThat(lines, hasItem(startsWith("user1:")));
@ -169,7 +169,7 @@ public class ESUsersToolTests extends CliToolTestCase {
} }
assertFileExists(userRolesFile); assertFileExists(userRolesFile);
lines = Files.readAllLines(userRolesFile, Charsets.UTF_8); lines = Files.readAllLines(userRolesFile, StandardCharsets.UTF_8);
assertThat(lines, hasSize(4)); assertThat(lines, hasSize(4));
assertThat(lines, containsInAnyOrder("r1:user1", "r2:user1", "r3:user2", "r4:user2")); assertThat(lines, containsInAnyOrder("r1:user1", "r2:user1", "r3:user2", "r4:user2"));
} }
@ -191,7 +191,7 @@ public class ESUsersToolTests extends CliToolTestCase {
assertThat(status, is(CliTool.ExitStatus.OK)); assertThat(status, is(CliTool.ExitStatus.OK));
assertFileExists(userRolesFile); assertFileExists(userRolesFile);
List<String> lines = Files.readAllLines(userRolesFile, Charsets.UTF_8); List<String> lines = Files.readAllLines(userRolesFile, StandardCharsets.UTF_8);
assertThat(lines, hasSize(2)); assertThat(lines, hasSize(2));
assertThat(lines, not(hasItem(containsString("user1")))); assertThat(lines, not(hasItem(containsString("user1"))));
} }
@ -303,11 +303,11 @@ public class ESUsersToolTests extends CliToolTestCase {
assertThat(status, is(CliTool.ExitStatus.OK)); assertThat(status, is(CliTool.ExitStatus.OK));
assertFileExists(userFile); assertFileExists(userFile);
List<String> lines = Files.readAllLines(userFile, Charsets.UTF_8); List<String> lines = Files.readAllLines(userFile, StandardCharsets.UTF_8);
assertThat(lines.size(), is(0)); assertThat(lines.size(), is(0));
assertFileExists(userRolesFile); assertFileExists(userRolesFile);
lines = Files.readAllLines(userRolesFile, Charsets.UTF_8); lines = Files.readAllLines(userRolesFile, StandardCharsets.UTF_8);
assertThat(lines.size(), is(0)); assertThat(lines.size(), is(0));
} }
@ -333,11 +333,11 @@ public class ESUsersToolTests extends CliToolTestCase {
assertThat(output, hasItem(startsWith("User [user2] doesn't exist"))); assertThat(output, hasItem(startsWith("User [user2] doesn't exist")));
assertFileExists(userFile); assertFileExists(userFile);
List<String> lines = Files.readAllLines(userFile, Charsets.UTF_8); List<String> lines = Files.readAllLines(userFile, StandardCharsets.UTF_8);
assertThat(lines.size(), is(1)); assertThat(lines.size(), is(1));
assertFileExists(userRolesFile); assertFileExists(userRolesFile);
lines = Files.readAllLines(userRolesFile, Charsets.UTF_8); lines = Files.readAllLines(userRolesFile, StandardCharsets.UTF_8);
assertThat(lines, hasSize(2)); assertThat(lines, hasSize(2));
} }
@ -422,7 +422,7 @@ public class ESUsersToolTests extends CliToolTestCase {
CliTool.ExitStatus status = execute(cmd, settings); CliTool.ExitStatus status = execute(cmd, settings);
assertThat(status, is(CliTool.ExitStatus.OK)); assertThat(status, is(CliTool.ExitStatus.OK));
List<String> lines = Files.readAllLines(userFile, Charsets.UTF_8); List<String> lines = Files.readAllLines(userFile, StandardCharsets.UTF_8);
assertThat(lines.size(), is(1)); assertThat(lines.size(), is(1));
// we can't just hash again and compare the lines, as every time we hash a new salt is generated // we can't just hash again and compare the lines, as every time we hash a new salt is generated
// instead we'll just verify the generated hash against the correct password. // instead we'll just verify the generated hash against the correct password.
@ -592,7 +592,7 @@ public class ESUsersToolTests extends CliToolTestCase {
assertThat(status, is(CliTool.ExitStatus.OK)); assertThat(status, is(CliTool.ExitStatus.OK));
List<String> usersRoleFileLines = Files.readAllLines(usersRoleFile, Charsets.UTF_8); List<String> usersRoleFileLines = Files.readAllLines(usersRoleFile, StandardCharsets.UTF_8);
assertThat(usersRoleFileLines, not(hasItem(containsString("user")))); assertThat(usersRoleFileLines, not(hasItem(containsString("user"))));
} }
@ -866,7 +866,7 @@ public class ESUsersToolTests extends CliToolTestCase {
assertThat(status, is(CliTool.ExitStatus.OK)); assertThat(status, is(CliTool.ExitStatus.OK));
assertFileExists(userFile); assertFileExists(userFile);
List<String> lines = Files.readAllLines(userFile, Charsets.UTF_8); List<String> lines = Files.readAllLines(userFile, StandardCharsets.UTF_8);
assertThat(lines.size(), is(1)); assertThat(lines.size(), is(1));
// we can't just hash again and compare the lines, as every time we hash a new salt is generated // we can't just hash again and compare the lines, as every time we hash a new salt is generated
// instead we'll just verify the generated hash against the correct password. // instead we'll just verify the generated hash against the correct password.
@ -876,7 +876,7 @@ public class ESUsersToolTests extends CliToolTestCase {
assertThat(Hasher.BCRYPT.verify(SecuredStringTests.build("changeme"), hash.toCharArray()), is(true)); assertThat(Hasher.BCRYPT.verify(SecuredStringTests.build("changeme"), hash.toCharArray()), is(true));
assertFileExists(userRolesFile); assertFileExists(userRolesFile);
lines = Files.readAllLines(userRolesFile, Charsets.UTF_8); lines = Files.readAllLines(userRolesFile, StandardCharsets.UTF_8);
assertThat(lines, hasSize(3)); assertThat(lines, hasSize(3));
assertThat(lines, containsInAnyOrder("r1:john.doe", "r2:john.doe", "r3:john.doe")); assertThat(lines, containsInAnyOrder("r1:john.doe", "r2:john.doe", "r3:john.doe"));
} }
@ -888,7 +888,7 @@ public class ESUsersToolTests extends CliToolTestCase {
private Path writeFile(String content) throws IOException { private Path writeFile(String content) throws IOException {
Path file = createTempFile(); Path file = createTempFile();
Files.write(file, content.getBytes(Charsets.UTF_8)); Files.write(file, content.getBytes(StandardCharsets.UTF_8));
return file; return file;
} }

View File

@ -5,7 +5,6 @@
*/ */
package org.elasticsearch.shield.authc.support; package org.elasticsearch.shield.authc.support;
import com.google.common.base.Charsets;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.unboundid.ldap.sdk.DN; import com.unboundid.ldap.sdk.DN;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
@ -22,6 +21,7 @@ import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import java.io.BufferedWriter; import java.io.BufferedWriter;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.StandardCopyOption; import java.nio.file.StandardCopyOption;
@ -74,7 +74,7 @@ public class DnRoleMapperTests extends ESTestCase {
public void testMapper_ConfiguredWithUnreadableFile() throws Exception { public void testMapper_ConfiguredWithUnreadableFile() throws Exception {
Path file = createTempFile(); Path file = createTempFile();
// writing in utf_16 should cause a parsing error as we try to read the file in utf_8 // writing in utf_16 should cause a parsing error as we try to read the file in utf_8
Files.write(file, Collections.singletonList("aldlfkjldjdflkjd"), Charsets.UTF_16); Files.write(file, Collections.singletonList("aldlfkjldjdflkjd"), StandardCharsets.UTF_16);
ResourceWatcherService watcherService = new ResourceWatcherService(settings, threadPool); ResourceWatcherService watcherService = new ResourceWatcherService(settings, threadPool);
DnRoleMapper mapper = createMapper(file, watcherService); DnRoleMapper mapper = createMapper(file, watcherService);
@ -105,7 +105,7 @@ public class DnRoleMapperTests extends ESTestCase {
watcherService.start(); watcherService.start();
try (BufferedWriter writer = Files.newBufferedWriter(file, Charsets.UTF_8, StandardOpenOption.APPEND)) { try (BufferedWriter writer = Files.newBufferedWriter(file, StandardCharsets.UTF_8, StandardOpenOption.APPEND)) {
writer.newLine(); writer.newLine();
writer.append("fantastic_four:\n") writer.append("fantastic_four:\n")
.append(" - \"cn=fantastic_four,ou=marvel,o=superheros\""); .append(" - \"cn=fantastic_four,ou=marvel,o=superheros\"");
@ -146,7 +146,7 @@ public class DnRoleMapperTests extends ESTestCase {
watcherService.start(); watcherService.start();
// now replacing the content of the users file with something that cannot be read // now replacing the content of the users file with something that cannot be read
Files.write(file, Collections.singletonList("aldlfkjldjdflkjd"), Charsets.UTF_16); Files.write(file, Collections.singletonList("aldlfkjldjdflkjd"), StandardCharsets.UTF_16);
if (!latch.await(5, TimeUnit.SECONDS)) { if (!latch.await(5, TimeUnit.SECONDS)) {
fail("Waited too long for the updated file to be picked up"); fail("Waited too long for the updated file to be picked up");
@ -210,7 +210,7 @@ public class DnRoleMapperTests extends ESTestCase {
public void testParseFile_WhenCannotReadFile() throws Exception { public void testParseFile_WhenCannotReadFile() throws Exception {
Path file = createTempFile(); Path file = createTempFile();
// writing in utf_16 should cause a parsing error as we try to read the file in utf_8 // writing in utf_16 should cause a parsing error as we try to read the file in utf_8
Files.write(file, Collections.singletonList("aldlfkjldjdflkjd"), Charsets.UTF_16); Files.write(file, Collections.singletonList("aldlfkjldjdflkjd"), StandardCharsets.UTF_16);
CapturingLogger logger = new CapturingLogger(CapturingLogger.Level.INFO); CapturingLogger logger = new CapturingLogger(CapturingLogger.Level.INFO);
try { try {
DnRoleMapper.parseFile(file, logger, "_type", "_name"); DnRoleMapper.parseFile(file, logger, "_type", "_name");
@ -224,7 +224,7 @@ public class DnRoleMapperTests extends ESTestCase {
public void testParseFileLenient_WhenCannotReadFile() throws Exception { public void testParseFileLenient_WhenCannotReadFile() throws Exception {
Path file = createTempFile(); Path file = createTempFile();
// writing in utf_16 should cause a parsing error as we try to read the file in utf_8 // writing in utf_16 should cause a parsing error as we try to read the file in utf_8
Files.write(file, Collections.singletonList("aldlfkjldjdflkjd"), Charsets.UTF_16); Files.write(file, Collections.singletonList("aldlfkjldjdflkjd"), StandardCharsets.UTF_16);
CapturingLogger logger = new CapturingLogger(CapturingLogger.Level.INFO); CapturingLogger logger = new CapturingLogger(CapturingLogger.Level.INFO);
ImmutableMap<DN, Set<String>> mappings = DnRoleMapper.parseFileLenient(file, logger, "_type", "_name"); ImmutableMap<DN, Set<String>> mappings = DnRoleMapper.parseFileLenient(file, logger, "_type", "_name");
assertThat(mappings, notNullValue()); assertThat(mappings, notNullValue());

View File

@ -5,7 +5,6 @@
*/ */
package org.elasticsearch.shield.authc.support; package org.elasticsearch.shield.authc.support;
import com.google.common.base.Charsets;
import org.elasticsearch.ElasticsearchSecurityException; import org.elasticsearch.ElasticsearchSecurityException;
import org.elasticsearch.common.Base64; import org.elasticsearch.common.Base64;
import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestRequest;
@ -15,6 +14,8 @@ import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.ExpectedException; import org.junit.rules.ExpectedException;
import java.nio.charset.StandardCharsets;
import static org.elasticsearch.test.ShieldTestsUtils.assertAuthenticationException; import static org.elasticsearch.test.ShieldTestsUtils.assertAuthenticationException;
import static org.hamcrest.Matchers.*; import static org.hamcrest.Matchers.*;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
@ -36,7 +37,7 @@ public class UsernamePasswordTokenTests extends ESTestCase {
assertThat(header, notNullValue()); assertThat(header, notNullValue());
assertTrue(header.startsWith("Basic ")); assertTrue(header.startsWith("Basic "));
String token = header.substring("Basic ".length()); String token = header.substring("Basic ".length());
token = new String(Base64.decode(token), Charsets.UTF_8); token = new String(Base64.decode(token), StandardCharsets.UTF_8);
int i = token.indexOf(":"); int i = token.indexOf(":");
assertTrue(i > 0); assertTrue(i > 0);
String username = token.substring(0, i); String username = token.substring(0, i);
@ -48,7 +49,7 @@ public class UsernamePasswordTokenTests extends ESTestCase {
@Test @Test
public void testExtractToken() throws Exception { public void testExtractToken() throws Exception {
TransportRequest request = new TransportRequest() {}; TransportRequest request = new TransportRequest() {};
String header = "Basic " + Base64.encodeBytes("user1:test123".getBytes(Charsets.UTF_8)); String header = "Basic " + Base64.encodeBytes("user1:test123".getBytes(StandardCharsets.UTF_8));
request.putHeader(UsernamePasswordToken.BASIC_AUTH_HEADER, header); request.putHeader(UsernamePasswordToken.BASIC_AUTH_HEADER, header);
UsernamePasswordToken token = UsernamePasswordToken.extractToken(request, null); UsernamePasswordToken token = UsernamePasswordToken.extractToken(request, null);
assertThat(token, notNullValue()); assertThat(token, notNullValue());

View File

@ -5,7 +5,6 @@
*/ */
package org.elasticsearch.shield.authz.store; package org.elasticsearch.shield.authz.store;
import com.google.common.base.Charsets;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.env.Environment; import org.elasticsearch.env.Environment;
@ -20,6 +19,7 @@ import org.junit.Test;
import java.io.BufferedWriter; import java.io.BufferedWriter;
import java.io.OutputStream; import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.StandardOpenOption; import java.nio.file.StandardOpenOption;
@ -192,7 +192,7 @@ public class FileRolesStoreTests extends ESTestCase {
watcherService.start(); watcherService.start();
try (BufferedWriter writer = Files.newBufferedWriter(tmp, Charsets.UTF_8, StandardOpenOption.APPEND)) { try (BufferedWriter writer = Files.newBufferedWriter(tmp, StandardCharsets.UTF_8, StandardOpenOption.APPEND)) {
writer.newLine(); writer.newLine();
writer.newLine(); writer.newLine();
writer.newLine(); writer.newLine();
@ -221,7 +221,7 @@ public class FileRolesStoreTests extends ESTestCase {
@Test @Test
public void testThatEmptyFileDoesNotResultInLoop() throws Exception { public void testThatEmptyFileDoesNotResultInLoop() throws Exception {
Path file = createTempFile(); Path file = createTempFile();
Files.write(file, Collections.singletonList("#"), Charsets.UTF_8); Files.write(file, Collections.singletonList("#"), StandardCharsets.UTF_8);
Map<String, Permission.Global.Role> roles = FileRolesStore.parseFile(file, Collections.<Permission.Global.Role>emptySet(), logger); Map<String, Permission.Global.Role> roles = FileRolesStore.parseFile(file, Collections.<Permission.Global.Role>emptySet(), logger);
assertThat(roles.keySet(), is(empty())); assertThat(roles.keySet(), is(empty()));
} }

View File

@ -79,12 +79,12 @@ public class TransportFilterTests extends ESIntegTestCase {
TransportService targetService = internalCluster().getInstance(TransportService.class, target); TransportService targetService = internalCluster().getInstance(TransportService.class, target);
CountDownLatch latch = new CountDownLatch(2); CountDownLatch latch = new CountDownLatch(2);
targetService.registerRequestHandler("_action", Request.class, ThreadPool.Names.SAME, new RequestHandler(new Response("trgt_to_src"), latch)); targetService.registerRequestHandler("_action", Request::new, ThreadPool.Names.SAME, new RequestHandler(new Response("trgt_to_src"), latch));
sourceService.sendRequest(targetNode, "_action", new Request("src_to_trgt"), new ResponseHandler(new Response("trgt_to_src"), latch)); sourceService.sendRequest(targetNode, "_action", new Request("src_to_trgt"), new ResponseHandler(new Response("trgt_to_src"), latch));
await(latch); await(latch);
latch = new CountDownLatch(2); latch = new CountDownLatch(2);
sourceService.registerRequestHandler("_action", Request.class, ThreadPool.Names.SAME, new RequestHandler(new Response("src_to_trgt"), latch)); sourceService.registerRequestHandler("_action", Request::new, ThreadPool.Names.SAME, new RequestHandler(new Response("src_to_trgt"), latch));
targetService.sendRequest(sourceNode, "_action", new Request("trgt_to_src"), new ResponseHandler(new Response("src_to_trgt"), latch)); targetService.sendRequest(sourceNode, "_action", new Request("trgt_to_src"), new ResponseHandler(new Response("src_to_trgt"), latch));
await(latch); await(latch);

View File

@ -5,7 +5,6 @@
*/ */
package org.elasticsearch.shield.transport.ssl; package org.elasticsearch.shield.transport.ssl;
import com.google.common.base.Charsets;
import org.apache.http.auth.AuthScope; import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials; import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.CredentialsProvider; import org.apache.http.client.CredentialsProvider;
@ -34,6 +33,7 @@ import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLHandshakeException; import javax.net.ssl.SSLHandshakeException;
import javax.net.ssl.TrustManagerFactory; import javax.net.ssl.TrustManagerFactory;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.security.KeyStore; import java.security.KeyStore;
import java.security.SecureRandom; import java.security.SecureRandom;
import java.util.Locale; import java.util.Locale;
@ -99,7 +99,7 @@ public class SslIntegrationTests extends ShieldIntegTestCase {
try (CloseableHttpClient client = HttpClients.custom().setSslcontext(service.sslContext()).setDefaultCredentialsProvider(provider).build(); try (CloseableHttpClient client = HttpClients.custom().setSslcontext(service.sslContext()).setDefaultCredentialsProvider(provider).build();
CloseableHttpResponse response = client.execute(new HttpGet(getNodeUrl()))) { CloseableHttpResponse response = client.execute(new HttpGet(getNodeUrl()))) {
assertThat(response.getStatusLine().getStatusCode(), is(200)); assertThat(response.getStatusLine().getStatusCode(), is(200));
String data = Streams.copyToString(new InputStreamReader(response.getEntity().getContent(), Charsets.UTF_8)); String data = Streams.copyToString(new InputStreamReader(response.getEntity().getContent(), StandardCharsets.UTF_8));
assertThat(data, containsString("You Know, for Search")); assertThat(data, containsString("You Know, for Search"));
} }
} }

View File

@ -18,6 +18,8 @@ import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.TransportService; import org.elasticsearch.transport.TransportService;
import org.elasticsearch.watcher.license.LicenseService; import org.elasticsearch.watcher.license.LicenseService;
import java.util.function.Supplier;
/** /**
* *
*/ */
@ -27,7 +29,7 @@ public abstract class WatcherTransportAction<Request extends MasterNodeRequest<R
public WatcherTransportAction(Settings settings, String actionName, TransportService transportService, public WatcherTransportAction(Settings settings, String actionName, TransportService transportService,
ClusterService clusterService, ThreadPool threadPool, ActionFilters actionFilters, ClusterService clusterService, ThreadPool threadPool, ActionFilters actionFilters,
IndexNameExpressionResolver indexNameExpressionResolver, LicenseService licenseService, Class<Request> request) { IndexNameExpressionResolver indexNameExpressionResolver, LicenseService licenseService, Supplier<Request> request) {
super(settings, actionName, transportService, clusterService, threadPool, actionFilters, indexNameExpressionResolver, request); super(settings, actionName, transportService, clusterService, threadPool, actionFilters, indexNameExpressionResolver, request);
this.licenseService = licenseService; this.licenseService = licenseService;
} }

View File

@ -34,7 +34,7 @@ public class TransportAckWatchAction extends WatcherTransportAction<AckWatchRequ
public TransportAckWatchAction(Settings settings, TransportService transportService, ClusterService clusterService, public TransportAckWatchAction(Settings settings, TransportService transportService, ClusterService clusterService,
ThreadPool threadPool, ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver, ThreadPool threadPool, ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver,
WatcherService watcherService, LicenseService licenseService) { WatcherService watcherService, LicenseService licenseService) {
super(settings, AckWatchAction.NAME, transportService, clusterService, threadPool, actionFilters, indexNameExpressionResolver, licenseService, AckWatchRequest.class); super(settings, AckWatchAction.NAME, transportService, clusterService, threadPool, actionFilters, indexNameExpressionResolver, licenseService, AckWatchRequest::new);
this.watcherService = watcherService; this.watcherService = watcherService;
} }

View File

@ -34,7 +34,7 @@ public class TransportActivateWatchAction extends WatcherTransportAction<Activat
public TransportActivateWatchAction(Settings settings, TransportService transportService, ClusterService clusterService, public TransportActivateWatchAction(Settings settings, TransportService transportService, ClusterService clusterService,
ThreadPool threadPool, ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver, ThreadPool threadPool, ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver,
WatcherService watcherService, LicenseService licenseService) { WatcherService watcherService, LicenseService licenseService) {
super(settings, ActivateWatchAction.NAME, transportService, clusterService, threadPool, actionFilters, indexNameExpressionResolver, licenseService, ActivateWatchRequest.class); super(settings, ActivateWatchAction.NAME, transportService, clusterService, threadPool, actionFilters, indexNameExpressionResolver, licenseService, ActivateWatchRequest::new);
this.watcherService = watcherService; this.watcherService = watcherService;
} }

View File

@ -34,7 +34,7 @@ public class TransportDeleteWatchAction extends WatcherTransportAction<DeleteWat
public TransportDeleteWatchAction(Settings settings, TransportService transportService, ClusterService clusterService, public TransportDeleteWatchAction(Settings settings, TransportService transportService, ClusterService clusterService,
ThreadPool threadPool, ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver, ThreadPool threadPool, ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver,
WatcherService watcherService, LicenseService licenseService) { WatcherService watcherService, LicenseService licenseService) {
super(settings, DeleteWatchAction.NAME, transportService, clusterService, threadPool, actionFilters, indexNameExpressionResolver, licenseService, DeleteWatchRequest.class); super(settings, DeleteWatchAction.NAME, transportService, clusterService, threadPool, actionFilters, indexNameExpressionResolver, licenseService, DeleteWatchRequest::new);
this.watcherService = watcherService; this.watcherService = watcherService;
} }

View File

@ -59,7 +59,7 @@ public class TransportExecuteWatchAction extends WatcherTransportAction<ExecuteW
ThreadPool threadPool, ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver, ExecutionService executionService, ThreadPool threadPool, ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver, ExecutionService executionService,
Clock clock, LicenseService licenseService, WatchStore watchStore, TriggerService triggerService, Clock clock, LicenseService licenseService, WatchStore watchStore, TriggerService triggerService,
Watch.Parser watchParser) { Watch.Parser watchParser) {
super(settings, ExecuteWatchAction.NAME, transportService, clusterService, threadPool, actionFilters, indexNameExpressionResolver, licenseService, ExecuteWatchRequest.class); super(settings, ExecuteWatchAction.NAME, transportService, clusterService, threadPool, actionFilters, indexNameExpressionResolver, licenseService, ExecuteWatchRequest::new);
this.executionService = executionService; this.executionService = executionService;
this.watchStore = watchStore; this.watchStore = watchStore;
this.clock = clock; this.clock = clock;

View File

@ -42,7 +42,7 @@ public class TransportGetWatchAction extends WatcherTransportAction<GetWatchRequ
public TransportGetWatchAction(Settings settings, TransportService transportService, ClusterService clusterService, public TransportGetWatchAction(Settings settings, TransportService transportService, ClusterService clusterService,
ThreadPool threadPool, ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver, ThreadPool threadPool, ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver,
WatcherService watcherService, LicenseService licenseService) { WatcherService watcherService, LicenseService licenseService) {
super(settings, GetWatchAction.NAME, transportService, clusterService, threadPool, actionFilters, indexNameExpressionResolver, licenseService, GetWatchRequest.class); super(settings, GetWatchAction.NAME, transportService, clusterService, threadPool, actionFilters, indexNameExpressionResolver, licenseService, GetWatchRequest::new);
this.watcherService = watcherService; this.watcherService = watcherService;
} }

View File

@ -33,7 +33,7 @@ public class TransportPutWatchAction extends WatcherTransportAction<PutWatchRequ
public TransportPutWatchAction(Settings settings, TransportService transportService, ClusterService clusterService, public TransportPutWatchAction(Settings settings, TransportService transportService, ClusterService clusterService,
ThreadPool threadPool, ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver, ThreadPool threadPool, ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver,
WatcherService watcherService, LicenseService licenseService) { WatcherService watcherService, LicenseService licenseService) {
super(settings, PutWatchAction.NAME, transportService, clusterService, threadPool, actionFilters, indexNameExpressionResolver, licenseService, PutWatchRequest.class); super(settings, PutWatchAction.NAME, transportService, clusterService, threadPool, actionFilters, indexNameExpressionResolver, licenseService, PutWatchRequest::new);
this.watcherService = watcherService; this.watcherService = watcherService;
} }

View File

@ -31,7 +31,7 @@ public class TransportWatcherServiceAction extends WatcherTransportAction<Watche
public TransportWatcherServiceAction(Settings settings, TransportService transportService, ClusterService clusterService, public TransportWatcherServiceAction(Settings settings, TransportService transportService, ClusterService clusterService,
ThreadPool threadPool, ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver, ThreadPool threadPool, ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver,
WatcherLifeCycleService lifeCycleService, LicenseService licenseService) { WatcherLifeCycleService lifeCycleService, LicenseService licenseService) {
super(settings, WatcherServiceAction.NAME, transportService, clusterService, threadPool, actionFilters, indexNameExpressionResolver, licenseService, WatcherServiceRequest.class); super(settings, WatcherServiceAction.NAME, transportService, clusterService, threadPool, actionFilters, indexNameExpressionResolver, licenseService, WatcherServiceRequest::new);
this.lifeCycleService = lifeCycleService; this.lifeCycleService = lifeCycleService;
} }

View File

@ -37,7 +37,7 @@ public class TransportWatcherStatsAction extends WatcherTransportAction<WatcherS
public TransportWatcherStatsAction(Settings settings, TransportService transportService, ClusterService clusterService, public TransportWatcherStatsAction(Settings settings, TransportService transportService, ClusterService clusterService,
ThreadPool threadPool, ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver, WatcherService watcherService, ThreadPool threadPool, ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver, WatcherService watcherService,
ExecutionService executionService, LicenseService licenseService, WatcherLifeCycleService lifeCycleService) { ExecutionService executionService, LicenseService licenseService, WatcherLifeCycleService lifeCycleService) {
super(settings, WatcherStatsAction.NAME, transportService, clusterService, threadPool, actionFilters, indexNameExpressionResolver, licenseService, WatcherStatsRequest.class); super(settings, WatcherStatsAction.NAME, transportService, clusterService, threadPool, actionFilters, indexNameExpressionResolver, licenseService, WatcherStatsRequest::new);
this.watcherService = watcherService; this.watcherService = watcherService;
this.executionService = executionService; this.executionService = executionService;
this.lifeCycleService = lifeCycleService; this.lifeCycleService = lifeCycleService;