From 6fb4f7817c328e1e02e3264d3621cbe4223c572f Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Mon, 14 Sep 2015 10:07:35 +0200 Subject: [PATCH] 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@67f602abd17a4bad359ded18371d68980d19ae3e --- .../renderer/cluster/ClusterInfoRenderer.java | 4 +-- .../cache/TransportClearRealmCacheAction.java | 2 +- .../authc/esusers/FileUserPasswdStore.java | 4 +-- .../authc/esusers/FileUserRolesStore.java | 4 +-- .../shield/authc/support/CharArrays.java | 7 ++--- .../shield/authc/support/Hasher.java | 4 +-- .../shield/authz/store/FileRolesStore.java | 4 +-- .../shield/crypto/InternalCryptoService.java | 6 ++-- .../shield/support/ShieldFiles.java | 4 +-- .../ShieldServerTransportService.java | 10 ++----- .../shield/authc/AnonymousUserTests.java | 4 +-- .../esusers/FileUserPasswdStoreTests.java | 16 +++++----- .../esusers/FileUserRolesStoreTests.java | 16 +++++----- .../authc/esusers/tool/ESUsersToolTests.java | 30 +++++++++---------- .../authc/support/DnRoleMapperTests.java | 12 ++++---- .../support/UsernamePasswordTokenTests.java | 7 +++-- .../authz/store/FileRolesStoreTests.java | 6 ++-- .../transport/TransportFilterTests.java | 4 +-- .../transport/ssl/SslIntegrationTests.java | 4 +-- .../actions/WatcherTransportAction.java | 4 ++- .../actions/ack/TransportAckWatchAction.java | 2 +- .../TransportActivateWatchAction.java | 2 +- .../delete/TransportDeleteWatchAction.java | 2 +- .../execute/TransportExecuteWatchAction.java | 2 +- .../actions/get/TransportGetWatchAction.java | 2 +- .../actions/put/TransportPutWatchAction.java | 2 +- .../TransportWatcherServiceAction.java | 2 +- .../stats/TransportWatcherStatsAction.java | 2 +- 28 files changed, 82 insertions(+), 86 deletions(-) diff --git a/marvel/src/main/java/org/elasticsearch/marvel/agent/renderer/cluster/ClusterInfoRenderer.java b/marvel/src/main/java/org/elasticsearch/marvel/agent/renderer/cluster/ClusterInfoRenderer.java index 31ece553fea..33b842a8040 100644 --- a/marvel/src/main/java/org/elasticsearch/marvel/agent/renderer/cluster/ClusterInfoRenderer.java +++ b/marvel/src/main/java/org/elasticsearch/marvel/agent/renderer/cluster/ClusterInfoRenderer.java @@ -5,7 +5,6 @@ */ package org.elasticsearch.marvel.agent.renderer.cluster; -import com.google.common.base.Charsets; import com.google.common.hash.Hashing; import org.elasticsearch.action.admin.cluster.stats.ClusterStatsResponse; 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 java.io.IOException; +import java.nio.charset.StandardCharsets; import java.util.List; public class ClusterInfoRenderer extends AbstractRenderer { @@ -64,7 +64,7 @@ public class ClusterInfoRenderer extends AbstractRenderer public static String hash(String licenseStatus, String licenseUid, String licenseType, String licenseExpiryDate, String 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 { diff --git a/shield/src/main/java/org/elasticsearch/shield/action/authc/cache/TransportClearRealmCacheAction.java b/shield/src/main/java/org/elasticsearch/shield/action/authc/cache/TransportClearRealmCacheAction.java index dd146f64bff..a9427870962 100644 --- a/shield/src/main/java/org/elasticsearch/shield/action/authc/cache/TransportClearRealmCacheAction.java +++ b/shield/src/main/java/org/elasticsearch/shield/action/authc/cache/TransportClearRealmCacheAction.java @@ -36,7 +36,7 @@ public class TransportClearRealmCacheAction extends TransportNodesAction lines; try { - lines = Files.readAllLines(path, Charsets.UTF_8); + lines = Files.readAllLines(path, StandardCharsets.UTF_8); } catch (IOException ioe) { throw new IllegalStateException("could not read users file [" + path.toAbsolutePath() + "]", ioe); } diff --git a/shield/src/main/java/org/elasticsearch/shield/authc/esusers/FileUserRolesStore.java b/shield/src/main/java/org/elasticsearch/shield/authc/esusers/FileUserRolesStore.java index 455f4fb3e9d..6f942a68a79 100644 --- a/shield/src/main/java/org/elasticsearch/shield/authc/esusers/FileUserRolesStore.java +++ b/shield/src/main/java/org/elasticsearch/shield/authc/esusers/FileUserRolesStore.java @@ -5,7 +5,6 @@ */ package org.elasticsearch.shield.authc.esusers; -import com.google.common.base.Charsets; import com.google.common.collect.ImmutableMap; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.common.Strings; @@ -24,6 +23,7 @@ import org.elasticsearch.watcher.ResourceWatcherService; import java.io.IOException; import java.io.PrintWriter; +import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.util.*; @@ -122,7 +122,7 @@ public class FileUserRolesStore { List lines; try { - lines = Files.readAllLines(path, Charsets.UTF_8); + lines = Files.readAllLines(path, StandardCharsets.UTF_8); } catch (IOException ioe) { throw new ElasticsearchException("could not read users file [" + path.toAbsolutePath() + "]", ioe); } diff --git a/shield/src/main/java/org/elasticsearch/shield/authc/support/CharArrays.java b/shield/src/main/java/org/elasticsearch/shield/authc/support/CharArrays.java index 2b3f580be3d..8f3a8c53792 100644 --- a/shield/src/main/java/org/elasticsearch/shield/authc/support/CharArrays.java +++ b/shield/src/main/java/org/elasticsearch/shield/authc/support/CharArrays.java @@ -5,10 +5,9 @@ */ package org.elasticsearch.shield.authc.support; -import com.google.common.base.Charsets; - import java.nio.ByteBuffer; import java.nio.CharBuffer; +import java.nio.charset.StandardCharsets; import java.util.Arrays; /** @@ -18,7 +17,7 @@ public class CharArrays { public static char[] utf8BytesToChars(byte[] 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()); byteBuffer.clear(); charBuffer.clear(); @@ -39,7 +38,7 @@ public class CharArrays { public static byte[] toUtf8Bytes(char[] 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()); Arrays.fill(byteBuffer.array(), (byte) 0); // clear sensitive data return bytes; diff --git a/shield/src/main/java/org/elasticsearch/shield/authc/support/Hasher.java b/shield/src/main/java/org/elasticsearch/shield/authc/support/Hasher.java index ade6bd0aabf..2a905460893 100644 --- a/shield/src/main/java/org/elasticsearch/shield/authc/support/Hasher.java +++ b/shield/src/main/java/org/elasticsearch/shield/authc/support/Hasher.java @@ -5,9 +5,9 @@ */ package org.elasticsearch.shield.authc.support; -import com.google.common.base.Charsets; import org.elasticsearch.common.Base64; +import java.nio.charset.StandardCharsets; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.Locale; @@ -211,7 +211,7 @@ public enum Hasher { char[] saltAndHash = hashStr.toCharArray(); MessageDigest md = SHA256Provider.sha256(); 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()); return SecuredString.constantTimeEquals(computedHash, new String(saltAndHash, 8, saltAndHash.length - 8)); } diff --git a/shield/src/main/java/org/elasticsearch/shield/authz/store/FileRolesStore.java b/shield/src/main/java/org/elasticsearch/shield/authz/store/FileRolesStore.java index 9bfbc0ccddb..9333af4be60 100644 --- a/shield/src/main/java/org/elasticsearch/shield/authz/store/FileRolesStore.java +++ b/shield/src/main/java/org/elasticsearch/shield/authz/store/FileRolesStore.java @@ -6,7 +6,6 @@ package org.elasticsearch.shield.authz.store; 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.ImmutableSet; import org.elasticsearch.ElasticsearchException; @@ -35,6 +34,7 @@ import org.elasticsearch.watcher.FileWatcher; import org.elasticsearch.watcher.ResourceWatcherService; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.util.*; @@ -370,7 +370,7 @@ public class FileRolesStore extends AbstractLifecycleComponent imple private static List roleSegments(Path path) throws IOException { List segments = new ArrayList<>(); 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 (IN_SEGMENT_LINE.matcher(line).matches()) { if (builder != null) { diff --git a/shield/src/main/java/org/elasticsearch/shield/crypto/InternalCryptoService.java b/shield/src/main/java/org/elasticsearch/shield/crypto/InternalCryptoService.java index f05e154db46..c0eb28d0232 100644 --- a/shield/src/main/java/org/elasticsearch/shield/crypto/InternalCryptoService.java +++ b/shield/src/main/java/org/elasticsearch/shield/crypto/InternalCryptoService.java @@ -5,7 +5,6 @@ */ package org.elasticsearch.shield.crypto; -import com.google.common.base.Charsets; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.common.Base64; import org.elasticsearch.common.component.AbstractLifecycleComponent; @@ -22,6 +21,7 @@ import javax.crypto.*; import javax.crypto.spec.IvParameterSpec; import javax.crypto.spec.SecretKeySpec; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.security.MessageDigest; @@ -49,7 +49,7 @@ public class InternalCryptoService extends AbstractLifecycleComponent void registerRequestHandler(String action, Class request, String executor, boolean forceExecution, TransportRequestHandler handler) { - TransportRequestHandler wrappedHandler = new ProfileSecuredRequestHandler<>(action, handler, profileFilters); - super.registerRequestHandler(action, request, executor, forceExecution, wrappedHandler); - } - - @Override - public void registerRequestHandler(String action, Callable requestFactory, String executor, TransportRequestHandler handler) { + public void registerRequestHandler(String action, Supplier requestFactory, String executor, TransportRequestHandler handler) { TransportRequestHandler wrappedHandler = new ProfileSecuredRequestHandler<>(action, handler, profileFilters); super.registerRequestHandler(action, requestFactory, executor, wrappedHandler); } diff --git a/shield/src/test/java/org/elasticsearch/shield/authc/AnonymousUserTests.java b/shield/src/test/java/org/elasticsearch/shield/authc/AnonymousUserTests.java index 5f2aeda16aa..3bafddac63c 100644 --- a/shield/src/test/java/org/elasticsearch/shield/authc/AnonymousUserTests.java +++ b/shield/src/test/java/org/elasticsearch/shield/authc/AnonymousUserTests.java @@ -5,7 +5,6 @@ */ package org.elasticsearch.shield.authc; -import com.google.common.base.Charsets; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.CloseableHttpClient; @@ -20,6 +19,7 @@ import org.elasticsearch.test.ShieldIntegTestCase; import org.junit.Test; import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; import java.util.Locale; import static org.hamcrest.Matchers.*; @@ -56,7 +56,7 @@ public class AnonymousUserTests extends ShieldIntegTestCase { try (CloseableHttpClient client = HttpClients.createDefault(); CloseableHttpResponse response = client.execute(new HttpGet(getNodeUrl() + "_nodes"))) { 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) { assertThat(statusCode, is(403)); assertThat(response.getFirstHeader("WWW-Authenticate"), nullValue()); diff --git a/shield/src/test/java/org/elasticsearch/shield/authc/esusers/FileUserPasswdStoreTests.java b/shield/src/test/java/org/elasticsearch/shield/authc/esusers/FileUserPasswdStoreTests.java index cb769040072..26597f39938 100644 --- a/shield/src/test/java/org/elasticsearch/shield/authc/esusers/FileUserPasswdStoreTests.java +++ b/shield/src/test/java/org/elasticsearch/shield/authc/esusers/FileUserPasswdStoreTests.java @@ -5,7 +5,6 @@ */ package org.elasticsearch.shield.authc.esusers; -import com.google.common.base.Charsets; import com.google.common.collect.ImmutableMap; import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.logging.ESLoggerFactory; @@ -24,6 +23,7 @@ import org.junit.Before; import org.junit.Test; import java.io.BufferedWriter; +import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.StandardCopyOption; @@ -69,7 +69,7 @@ public class FileUserPasswdStoreTests extends ESTestCase { Path file = createTempFile(); // 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() .put("files.users", file.toAbsolutePath()) @@ -108,7 +108,7 @@ public class FileUserPasswdStoreTests extends ESTestCase { 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.append("foobar:").append(new String(Hasher.BCRYPT.hash(SecuredStringTests.build("barfoo")))); } @@ -148,7 +148,7 @@ public class FileUserPasswdStoreTests extends ESTestCase { watcherService.start(); // 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)) { 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 { Path file = createTempFile(); // 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); try { FileUserPasswdStore.parseFile(file, logger); @@ -213,7 +213,7 @@ public class FileUserPasswdStoreTests extends ESTestCase { @Test public void testParseFile_InvalidLineDoesNotResultInLoggerNPE() throws Exception { 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 users = FileUserPasswdStore.parseFile(file, null); assertThat(users, notNullValue()); assertThat(users.keySet(), hasSize(1)); @@ -223,7 +223,7 @@ public class FileUserPasswdStoreTests extends ESTestCase { public void testParseFileLenient_WhenCannotReadFile() throws Exception { Path file = createTempFile(); // 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); Map users = FileUserPasswdStore.parseFileLenient(file, logger); assertThat(users, notNullValue()); @@ -236,7 +236,7 @@ public class FileUserPasswdStoreTests extends ESTestCase { @Test public void testParseFileWithLineWithEmptyPasswordAndWhitespace() throws Exception { Path file = createTempFile(); - Files.write(file, Collections.singletonList("user: "), Charsets.UTF_8); + Files.write(file, Collections.singletonList("user: "), StandardCharsets.UTF_8); Map users = FileUserPasswdStore.parseFile(file, null); assertThat(users, notNullValue()); assertThat(users.keySet(), is(empty())); diff --git a/shield/src/test/java/org/elasticsearch/shield/authc/esusers/FileUserRolesStoreTests.java b/shield/src/test/java/org/elasticsearch/shield/authc/esusers/FileUserRolesStoreTests.java index e780683f63c..d971c5b2718 100644 --- a/shield/src/test/java/org/elasticsearch/shield/authc/esusers/FileUserRolesStoreTests.java +++ b/shield/src/test/java/org/elasticsearch/shield/authc/esusers/FileUserRolesStoreTests.java @@ -5,7 +5,6 @@ */ package org.elasticsearch.shield.authc.esusers; -import com.google.common.base.Charsets; import org.elasticsearch.common.Strings; import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.logging.ESLoggerFactory; @@ -22,6 +21,7 @@ import org.junit.Before; import org.junit.Test; import java.io.BufferedWriter; +import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.StandardCopyOption; @@ -66,7 +66,7 @@ public class FileUserRolesStoreTests extends ESTestCase { lines.add("aldlfkjldjdflkjd"); // 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() .put("files.users_roles", file.toAbsolutePath()) @@ -107,7 +107,7 @@ public class FileUserRolesStoreTests extends ESTestCase { 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.append("role4:user4\nrole5:user4\n"); } @@ -152,7 +152,7 @@ public class FileUserRolesStoreTests extends ESTestCase { watcherService.start(); // 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)) { fail("Waited too long for the updated file to be picked up"); @@ -205,7 +205,7 @@ public class FileUserRolesStoreTests extends ESTestCase { lines.add("aldlfkjldjdflkjd"); // 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); try { FileUserRolesStore.parseFile(file, logger); @@ -267,7 +267,7 @@ public class FileUserRolesStoreTests extends ESTestCase { lines.add("aldlfkjldjdflkjd"); // 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); Map usersRoles = FileUserRolesStore.parseFileLenient(file, logger); assertThat(usersRoles, notNullValue()); @@ -279,13 +279,13 @@ public class FileUserRolesStoreTests extends ESTestCase { private Path writeUsersRoles(String input) throws Exception { Path file = createTempFile(); - Files.write(file, input.getBytes(Charsets.UTF_8)); + Files.write(file, input.getBytes(StandardCharsets.UTF_8)); return file; } private void assertInvalidInputIsSilentlyIgnored(String input) throws Exception { Path file = createTempFile(); - Files.write(file, input.getBytes(Charsets.UTF_8)); + Files.write(file, input.getBytes(StandardCharsets.UTF_8)); Map usersRoles = FileUserRolesStore.parseFile(file, null); assertThat(String.format(Locale.ROOT, "Expected userRoles to be empty, but was %s", usersRoles.keySet()), usersRoles.keySet(), hasSize(0)); } diff --git a/shield/src/test/java/org/elasticsearch/shield/authc/esusers/tool/ESUsersToolTests.java b/shield/src/test/java/org/elasticsearch/shield/authc/esusers/tool/ESUsersToolTests.java index 5b3ff35d544..cea89bc0d60 100644 --- a/shield/src/test/java/org/elasticsearch/shield/authc/esusers/tool/ESUsersToolTests.java +++ b/shield/src/test/java/org/elasticsearch/shield/authc/esusers/tool/ESUsersToolTests.java @@ -5,7 +5,6 @@ */ package org.elasticsearch.shield.authc.esusers.tool; -import com.google.common.base.Charsets; import org.elasticsearch.common.Strings; import org.elasticsearch.common.cli.CliTool; import org.elasticsearch.common.cli.CliToolTestCase; @@ -18,6 +17,7 @@ import org.elasticsearch.shield.authc.support.SecuredStringTests; import org.junit.Test; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.util.List; @@ -122,7 +122,7 @@ public class ESUsersToolTests extends CliToolTestCase { assertThat(status, is(CliTool.ExitStatus.OK)); assertFileExists(userFile); - List lines = Files.readAllLines(userFile, Charsets.UTF_8); + List lines = Files.readAllLines(userFile, StandardCharsets.UTF_8); 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 // 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)); assertFileExists(userRolesFile); - lines = Files.readAllLines(userRolesFile, Charsets.UTF_8); + lines = Files.readAllLines(userRolesFile, StandardCharsets.UTF_8); assertThat(lines, hasSize(2)); assertThat(lines, containsInAnyOrder("r1:user1", "r2:user1")); } @@ -154,7 +154,7 @@ public class ESUsersToolTests extends CliToolTestCase { assertThat(status, is(CliTool.ExitStatus.OK)); assertFileExists(userFile); - List lines = Files.readAllLines(userFile, Charsets.UTF_8); + List lines = Files.readAllLines(userFile, StandardCharsets.UTF_8); assertThat(lines, hasSize(2)); assertThat(lines, hasItem("user2:hash2")); assertThat(lines, hasItem(startsWith("user1:"))); @@ -169,7 +169,7 @@ public class ESUsersToolTests extends CliToolTestCase { } assertFileExists(userRolesFile); - lines = Files.readAllLines(userRolesFile, Charsets.UTF_8); + lines = Files.readAllLines(userRolesFile, StandardCharsets.UTF_8); assertThat(lines, hasSize(4)); 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)); assertFileExists(userRolesFile); - List lines = Files.readAllLines(userRolesFile, Charsets.UTF_8); + List lines = Files.readAllLines(userRolesFile, StandardCharsets.UTF_8); assertThat(lines, hasSize(2)); assertThat(lines, not(hasItem(containsString("user1")))); } @@ -303,11 +303,11 @@ public class ESUsersToolTests extends CliToolTestCase { assertThat(status, is(CliTool.ExitStatus.OK)); assertFileExists(userFile); - List lines = Files.readAllLines(userFile, Charsets.UTF_8); + List lines = Files.readAllLines(userFile, StandardCharsets.UTF_8); assertThat(lines.size(), is(0)); assertFileExists(userRolesFile); - lines = Files.readAllLines(userRolesFile, Charsets.UTF_8); + lines = Files.readAllLines(userRolesFile, StandardCharsets.UTF_8); assertThat(lines.size(), is(0)); } @@ -333,11 +333,11 @@ public class ESUsersToolTests extends CliToolTestCase { assertThat(output, hasItem(startsWith("User [user2] doesn't exist"))); assertFileExists(userFile); - List lines = Files.readAllLines(userFile, Charsets.UTF_8); + List lines = Files.readAllLines(userFile, StandardCharsets.UTF_8); assertThat(lines.size(), is(1)); assertFileExists(userRolesFile); - lines = Files.readAllLines(userRolesFile, Charsets.UTF_8); + lines = Files.readAllLines(userRolesFile, StandardCharsets.UTF_8); assertThat(lines, hasSize(2)); } @@ -422,7 +422,7 @@ public class ESUsersToolTests extends CliToolTestCase { CliTool.ExitStatus status = execute(cmd, settings); assertThat(status, is(CliTool.ExitStatus.OK)); - List lines = Files.readAllLines(userFile, Charsets.UTF_8); + List lines = Files.readAllLines(userFile, StandardCharsets.UTF_8); 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 // 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)); - List usersRoleFileLines = Files.readAllLines(usersRoleFile, Charsets.UTF_8); + List usersRoleFileLines = Files.readAllLines(usersRoleFile, StandardCharsets.UTF_8); assertThat(usersRoleFileLines, not(hasItem(containsString("user")))); } @@ -866,7 +866,7 @@ public class ESUsersToolTests extends CliToolTestCase { assertThat(status, is(CliTool.ExitStatus.OK)); assertFileExists(userFile); - List lines = Files.readAllLines(userFile, Charsets.UTF_8); + List lines = Files.readAllLines(userFile, StandardCharsets.UTF_8); 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 // 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)); assertFileExists(userRolesFile); - lines = Files.readAllLines(userRolesFile, Charsets.UTF_8); + lines = Files.readAllLines(userRolesFile, StandardCharsets.UTF_8); assertThat(lines, hasSize(3)); 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 { Path file = createTempFile(); - Files.write(file, content.getBytes(Charsets.UTF_8)); + Files.write(file, content.getBytes(StandardCharsets.UTF_8)); return file; } diff --git a/shield/src/test/java/org/elasticsearch/shield/authc/support/DnRoleMapperTests.java b/shield/src/test/java/org/elasticsearch/shield/authc/support/DnRoleMapperTests.java index 1acacbe114a..6147138333b 100644 --- a/shield/src/test/java/org/elasticsearch/shield/authc/support/DnRoleMapperTests.java +++ b/shield/src/test/java/org/elasticsearch/shield/authc/support/DnRoleMapperTests.java @@ -5,7 +5,6 @@ */ package org.elasticsearch.shield.authc.support; -import com.google.common.base.Charsets; import com.google.common.collect.ImmutableMap; import com.unboundid.ldap.sdk.DN; import org.elasticsearch.common.settings.Settings; @@ -22,6 +21,7 @@ import org.junit.Before; import org.junit.Test; import java.io.BufferedWriter; +import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.StandardCopyOption; @@ -74,7 +74,7 @@ public class DnRoleMapperTests extends ESTestCase { public void testMapper_ConfiguredWithUnreadableFile() throws Exception { Path file = createTempFile(); // 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); DnRoleMapper mapper = createMapper(file, watcherService); @@ -105,7 +105,7 @@ public class DnRoleMapperTests extends ESTestCase { 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.append("fantastic_four:\n") .append(" - \"cn=fantastic_four,ou=marvel,o=superheros\""); @@ -146,7 +146,7 @@ public class DnRoleMapperTests extends ESTestCase { watcherService.start(); // 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)) { 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 { Path file = createTempFile(); // 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); try { DnRoleMapper.parseFile(file, logger, "_type", "_name"); @@ -224,7 +224,7 @@ public class DnRoleMapperTests extends ESTestCase { public void testParseFileLenient_WhenCannotReadFile() throws Exception { Path file = createTempFile(); // 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); ImmutableMap> mappings = DnRoleMapper.parseFileLenient(file, logger, "_type", "_name"); assertThat(mappings, notNullValue()); diff --git a/shield/src/test/java/org/elasticsearch/shield/authc/support/UsernamePasswordTokenTests.java b/shield/src/test/java/org/elasticsearch/shield/authc/support/UsernamePasswordTokenTests.java index fb39e36b7b0..cdcb9b74368 100644 --- a/shield/src/test/java/org/elasticsearch/shield/authc/support/UsernamePasswordTokenTests.java +++ b/shield/src/test/java/org/elasticsearch/shield/authc/support/UsernamePasswordTokenTests.java @@ -5,7 +5,6 @@ */ package org.elasticsearch.shield.authc.support; -import com.google.common.base.Charsets; import org.elasticsearch.ElasticsearchSecurityException; import org.elasticsearch.common.Base64; import org.elasticsearch.rest.RestRequest; @@ -15,6 +14,8 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; +import java.nio.charset.StandardCharsets; + import static org.elasticsearch.test.ShieldTestsUtils.assertAuthenticationException; import static org.hamcrest.Matchers.*; import static org.mockito.Mockito.mock; @@ -36,7 +37,7 @@ public class UsernamePasswordTokenTests extends ESTestCase { assertThat(header, notNullValue()); assertTrue(header.startsWith("Basic ")); 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(":"); assertTrue(i > 0); String username = token.substring(0, i); @@ -48,7 +49,7 @@ public class UsernamePasswordTokenTests extends ESTestCase { @Test public void testExtractToken() throws Exception { 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); UsernamePasswordToken token = UsernamePasswordToken.extractToken(request, null); assertThat(token, notNullValue()); diff --git a/shield/src/test/java/org/elasticsearch/shield/authz/store/FileRolesStoreTests.java b/shield/src/test/java/org/elasticsearch/shield/authz/store/FileRolesStoreTests.java index 8f375f0b9be..dab08360dad 100644 --- a/shield/src/test/java/org/elasticsearch/shield/authz/store/FileRolesStoreTests.java +++ b/shield/src/test/java/org/elasticsearch/shield/authz/store/FileRolesStoreTests.java @@ -5,7 +5,6 @@ */ package org.elasticsearch.shield.authz.store; -import com.google.common.base.Charsets; import com.google.common.collect.ImmutableSet; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.env.Environment; @@ -20,6 +19,7 @@ import org.junit.Test; import java.io.BufferedWriter; import java.io.OutputStream; +import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.StandardOpenOption; @@ -192,7 +192,7 @@ public class FileRolesStoreTests extends ESTestCase { 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(); @@ -221,7 +221,7 @@ public class FileRolesStoreTests extends ESTestCase { @Test public void testThatEmptyFileDoesNotResultInLoop() throws Exception { Path file = createTempFile(); - Files.write(file, Collections.singletonList("#"), Charsets.UTF_8); + Files.write(file, Collections.singletonList("#"), StandardCharsets.UTF_8); Map roles = FileRolesStore.parseFile(file, Collections.emptySet(), logger); assertThat(roles.keySet(), is(empty())); } diff --git a/shield/src/test/java/org/elasticsearch/shield/transport/TransportFilterTests.java b/shield/src/test/java/org/elasticsearch/shield/transport/TransportFilterTests.java index ae82b652085..74d1e1752a7 100644 --- a/shield/src/test/java/org/elasticsearch/shield/transport/TransportFilterTests.java +++ b/shield/src/test/java/org/elasticsearch/shield/transport/TransportFilterTests.java @@ -79,12 +79,12 @@ public class TransportFilterTests extends ESIntegTestCase { TransportService targetService = internalCluster().getInstance(TransportService.class, target); 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)); await(latch); 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)); await(latch); diff --git a/shield/src/test/java/org/elasticsearch/shield/transport/ssl/SslIntegrationTests.java b/shield/src/test/java/org/elasticsearch/shield/transport/ssl/SslIntegrationTests.java index 5cc3a8039c7..1cd2f058edb 100644 --- a/shield/src/test/java/org/elasticsearch/shield/transport/ssl/SslIntegrationTests.java +++ b/shield/src/test/java/org/elasticsearch/shield/transport/ssl/SslIntegrationTests.java @@ -5,7 +5,6 @@ */ package org.elasticsearch.shield.transport.ssl; -import com.google.common.base.Charsets; import org.apache.http.auth.AuthScope; import org.apache.http.auth.UsernamePasswordCredentials; import org.apache.http.client.CredentialsProvider; @@ -34,6 +33,7 @@ import javax.net.ssl.SSLContext; import javax.net.ssl.SSLHandshakeException; import javax.net.ssl.TrustManagerFactory; import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; import java.security.KeyStore; import java.security.SecureRandom; import java.util.Locale; @@ -99,7 +99,7 @@ public class SslIntegrationTests extends ShieldIntegTestCase { try (CloseableHttpClient client = HttpClients.custom().setSslcontext(service.sslContext()).setDefaultCredentialsProvider(provider).build(); CloseableHttpResponse response = client.execute(new HttpGet(getNodeUrl()))) { 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")); } } diff --git a/watcher/src/main/java/org/elasticsearch/watcher/transport/actions/WatcherTransportAction.java b/watcher/src/main/java/org/elasticsearch/watcher/transport/actions/WatcherTransportAction.java index e38e901290b..684f5833b17 100644 --- a/watcher/src/main/java/org/elasticsearch/watcher/transport/actions/WatcherTransportAction.java +++ b/watcher/src/main/java/org/elasticsearch/watcher/transport/actions/WatcherTransportAction.java @@ -18,6 +18,8 @@ import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; import org.elasticsearch.watcher.license.LicenseService; +import java.util.function.Supplier; + /** * */ @@ -27,7 +29,7 @@ public abstract class WatcherTransportAction request) { + IndexNameExpressionResolver indexNameExpressionResolver, LicenseService licenseService, Supplier request) { super(settings, actionName, transportService, clusterService, threadPool, actionFilters, indexNameExpressionResolver, request); this.licenseService = licenseService; } diff --git a/watcher/src/main/java/org/elasticsearch/watcher/transport/actions/ack/TransportAckWatchAction.java b/watcher/src/main/java/org/elasticsearch/watcher/transport/actions/ack/TransportAckWatchAction.java index be75a453d94..d15163b380d 100644 --- a/watcher/src/main/java/org/elasticsearch/watcher/transport/actions/ack/TransportAckWatchAction.java +++ b/watcher/src/main/java/org/elasticsearch/watcher/transport/actions/ack/TransportAckWatchAction.java @@ -34,7 +34,7 @@ public class TransportAckWatchAction extends WatcherTransportAction