caolijun1166 closed pull request #297: KYLIN-3597 Use SecureRandom instead of
Random
URL: https://github.com/apache/kylin/pull/297
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/core-cube/src/main/java/org/apache/kylin/cube/CubeManager.java
b/core-cube/src/main/java/org/apache/kylin/cube/CubeManager.java
index dbd19559fe..8b1a978f93 100755
--- a/core-cube/src/main/java/org/apache/kylin/cube/CubeManager.java
+++ b/core-cube/src/main/java/org/apache/kylin/cube/CubeManager.java
@@ -19,6 +19,8 @@
package org.apache.kylin.cube;
import java.io.IOException;
+import java.security.NoSuchAlgorithmException;
+import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -514,18 +516,22 @@ private String getSnapshotResPath(CubeSegment
cubeSegment, String tableName, Sna
String namePrefix = config.getHBaseTableNamePrefix();
String namespace = config.getHBaseStorageNameSpace();
String tableName = "";
- Random ran = new Random();
- do {
- StringBuffer sb = new StringBuffer();
- if ((namespace.equals("default") || namespace.equals("")) ==
false) {
- sb.append(namespace).append(":");
- }
- sb.append(namePrefix);
- for (int i = 0; i < HBASE_TABLE_LENGTH; i++) {
- sb.append(ALPHA_NUM.charAt(ran.nextInt(ALPHA_NUM.length())));
- }
- tableName = sb.toString();
- } while (this.usedStorageLocation.containsValue(tableName));
+ try {
+ Random ran = SecureRandom.getInstanceStrong();
+ do {
+ StringBuffer sb = new StringBuffer();
+ if ((namespace.equals("default") || namespace.equals("")) ==
false) {
+ sb.append(namespace).append(":");
+ }
+ sb.append(namePrefix);
+ for (int i = 0; i < HBASE_TABLE_LENGTH; i++) {
+
sb.append(ALPHA_NUM.charAt(ran.nextInt(ALPHA_NUM.length())));
+ }
+ tableName = sb.toString();
+ } while (this.usedStorageLocation.containsValue(tableName));
+ } catch (NoSuchAlgorithmException e) {
+ throw new RuntimeException("SecureRandom.getInstanceStrong() can't
get such algorithm.");
+ }
return tableName;
}
diff --git
a/storage-hbase/src/main/java/org/apache/kylin/storage/hbase/util/GridTableHBaseBenchmark.java
b/storage-hbase/src/main/java/org/apache/kylin/storage/hbase/util/GridTableHBaseBenchmark.java
index 6dd16fe494..4938f5f009 100644
---
a/storage-hbase/src/main/java/org/apache/kylin/storage/hbase/util/GridTableHBaseBenchmark.java
+++
b/storage-hbase/src/main/java/org/apache/kylin/storage/hbase/util/GridTableHBaseBenchmark.java
@@ -20,6 +20,8 @@
import java.io.IOException;
import java.nio.charset.StandardCharsets;
+import java.security.NoSuchAlgorithmException;
+import java.security.SecureRandom;
import java.util.List;
import java.util.Random;
@@ -258,8 +260,12 @@ private static void dot(int i, int nRows) {
private static byte[] randomBytes() {
byte[] bytes = new byte[CELL_SIZE];
- Random rand = new Random();
- rand.nextBytes(bytes);
+ try {
+ Random rand = SecureRandom.getInstanceStrong();
+ rand.nextBytes(bytes);
+ } catch (NoSuchAlgorithmException e) {
+ throw new RuntimeException("SecureRandom.getInstanceStrong() can't
get such algorithm.");
+ }
return bytes;
}
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services