Merge pull request elastic/elasticsearch#1280 from jasontedor/thread-local-random-be-gone

Remove use of j.u.c.ThreadLocalRandom

Relates elastic/elasticsearchelastic/elasticsearch#15862

Original commit: elastic/x-pack-elasticsearch@c2453e0155
This commit is contained in:
Jason Tedor 2016-01-08 12:59:17 -05:00
commit 338e292d2f
2 changed files with 6 additions and 6 deletions

View File

@ -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))];

View File

@ -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);