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:
commit
338e292d2f
|
@ -6,13 +6,13 @@
|
||||||
package org.elasticsearch.shield.authc.support;
|
package org.elasticsearch.shield.authc.support;
|
||||||
|
|
||||||
import org.elasticsearch.common.Base64;
|
import org.elasticsearch.common.Base64;
|
||||||
|
import org.elasticsearch.common.Randomness;
|
||||||
|
|
||||||
import java.nio.charset.StandardCharsets;
|
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;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.concurrent.ThreadLocalRandom;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -347,7 +347,7 @@ public enum Hasher {
|
||||||
};
|
};
|
||||||
|
|
||||||
public static char[] salt(int length) {
|
public static char[] salt(int length) {
|
||||||
Random random = ThreadLocalRandom.current();
|
Random random = Randomness.get();
|
||||||
char[] salt = new char[length];
|
char[] salt = new char[length];
|
||||||
for (int i = 0; i < length; i++) {
|
for (int i = 0; i < length; i++) {
|
||||||
salt[i] = ALPHABET[(random.nextInt(ALPHABET.length))];
|
salt[i] = ALPHABET[(random.nextInt(ALPHABET.length))];
|
||||||
|
|
|
@ -5,14 +5,14 @@
|
||||||
*/
|
*/
|
||||||
package org.elasticsearch.bench;
|
package org.elasticsearch.bench;
|
||||||
|
|
||||||
|
import org.elasticsearch.common.Randomness;
|
||||||
|
|
||||||
import com.carrotsearch.randomizedtesting.generators.RandomStrings;
|
import com.carrotsearch.randomizedtesting.generators.RandomStrings;
|
||||||
import org.elasticsearch.common.metrics.MeanMetric;
|
import org.elasticsearch.common.metrics.MeanMetric;
|
||||||
import org.elasticsearch.common.unit.TimeValue;
|
import org.elasticsearch.common.unit.TimeValue;
|
||||||
import org.elasticsearch.shield.authc.support.Hasher;
|
import org.elasticsearch.shield.authc.support.Hasher;
|
||||||
import org.elasticsearch.shield.authc.support.SecuredString;
|
import org.elasticsearch.shield.authc.support.SecuredString;
|
||||||
|
|
||||||
import java.util.concurrent.ThreadLocalRandom;
|
|
||||||
|
|
||||||
public class HasherBenchmark {
|
public class HasherBenchmark {
|
||||||
|
|
||||||
private static final int WARMING_ITERS = 1000;
|
private static final int WARMING_ITERS = 1000;
|
||||||
|
@ -33,7 +33,7 @@ public class HasherBenchmark {
|
||||||
System.out.print("warming up [" + hasher.name() + "]...");
|
System.out.print("warming up [" + hasher.name() + "]...");
|
||||||
|
|
||||||
for (int i = 0; i < WARMING_ITERS; i++) {
|
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);
|
char[] hash = hasher.hash(str);
|
||||||
hasher.verify(str, hash);
|
hasher.verify(str, hash);
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,7 @@ public class HasherBenchmark {
|
||||||
long start;
|
long start;
|
||||||
|
|
||||||
for (int i = 0; i < BENCH_ITERS; i++) {
|
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();
|
start = System.nanoTime();
|
||||||
char[] hash = hasher.hash(str);
|
char[] hash = hasher.hash(str);
|
||||||
|
|
Loading…
Reference in New Issue