From 2b5c28242d291312365e0a4b05beb5347a09e4a8 Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Fri, 8 Jan 2016 12:21:30 -0500 Subject: [PATCH] Remove use of j.u.c.ThreadLocalRandom This commit removes all uses of java.util.concurrent.ThreadLocalRandom across the codebase. Original commit: elastic/x-pack-elasticsearch@eca37013579799c019d0b9b97f8c1e2deb1d6511 --- .../org/elasticsearch/shield/authc/support/Hasher.java | 4 ++-- .../java/org/elasticsearch/bench/HasherBenchmark.java | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/authc/support/Hasher.java b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/authc/support/Hasher.java index 2a905460893..f7639a1a53b 100644 --- a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/authc/support/Hasher.java +++ b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/authc/support/Hasher.java @@ -6,13 +6,13 @@ package org.elasticsearch.shield.authc.support; import org.elasticsearch.common.Base64; +import org.elasticsearch.common.Randomness; import java.nio.charset.StandardCharsets; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.Locale; import java.util.Random; -import java.util.concurrent.ThreadLocalRandom; /** * @@ -347,7 +347,7 @@ public enum Hasher { }; public static char[] salt(int length) { - Random random = ThreadLocalRandom.current(); + Random random = Randomness.get(); char[] salt = new char[length]; for (int i = 0; i < length; i++) { salt[i] = ALPHABET[(random.nextInt(ALPHABET.length))]; diff --git a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/bench/HasherBenchmark.java b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/bench/HasherBenchmark.java index 4b9977211f2..13940993f5f 100644 --- a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/bench/HasherBenchmark.java +++ b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/bench/HasherBenchmark.java @@ -5,14 +5,14 @@ */ package org.elasticsearch.bench; +import org.elasticsearch.common.Randomness; + import com.carrotsearch.randomizedtesting.generators.RandomStrings; import org.elasticsearch.common.metrics.MeanMetric; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.shield.authc.support.Hasher; import org.elasticsearch.shield.authc.support.SecuredString; -import java.util.concurrent.ThreadLocalRandom; - public class HasherBenchmark { private static final int WARMING_ITERS = 1000; @@ -33,7 +33,7 @@ public class HasherBenchmark { System.out.print("warming up [" + hasher.name() + "]..."); for (int i = 0; i < WARMING_ITERS; i++) { - SecuredString str = new SecuredString(RandomStrings.randomAsciiOfLength(ThreadLocalRandom.current(), 8).toCharArray()); + SecuredString str = new SecuredString(RandomStrings.randomAsciiOfLength(Randomness.get(), 8).toCharArray()); char[] hash = hasher.hash(str); hasher.verify(str, hash); } @@ -44,7 +44,7 @@ public class HasherBenchmark { long start; for (int i = 0; i < BENCH_ITERS; i++) { - SecuredString str = new SecuredString(RandomStrings.randomAsciiOfLength(ThreadLocalRandom.current(), 8).toCharArray()); + SecuredString str = new SecuredString(RandomStrings.randomAsciiOfLength(Randomness.get(), 8).toCharArray()); start = System.nanoTime(); char[] hash = hasher.hash(str);