Skip to content

Commit fbba099

Browse files
committed
process the read permission white list for root user
1 parent 10e6eaf commit fbba099

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

client/src/main/java/com/vesoft/nebula/client/storage/StorageClient.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import com.vesoft.nebula.storage.ScanEdgeRequest;
2626
import com.vesoft.nebula.storage.ScanVertexRequest;
2727
import com.vesoft.nebula.storage.VertexProp;
28+
2829
import java.io.Serializable;
2930
import java.io.UnsupportedEncodingException;
3031
import java.util.ArrayList;
@@ -34,6 +35,7 @@
3435
import java.util.List;
3536
import java.util.Map;
3637
import java.util.Set;
38+
3739
import org.slf4j.Logger;
3840
import org.slf4j.LoggerFactory;
3941

@@ -57,7 +59,7 @@ public class StorageClient implements Serializable {
5759
private String graphAddress = null;
5860

5961
// the write list for users with read permission
60-
private Map<String, List<String>> spaceLabelWriteList = new HashMap<>();
62+
private Map<String, List<String>> spaceLabelWriteList = null;
6163
private String version = null;
6264

6365
/**
@@ -1211,6 +1213,12 @@ private void authUser() throws AuthFailedException, IOErrorException,
12111213
version);
12121214
AuthResult authResult = graphConnection.authenticate(user, password);
12131215
long sessionId = authResult.getSessionId();
1216+
1217+
if (user.equals("root")) {
1218+
return;
1219+
}
1220+
1221+
spaceLabelWriteList = new HashMap<>();
12141222
ResultSet resultSet = new ResultSet(
12151223
graphConnection.execute(sessionId, "DESC USER " + user),
12161224
authResult.getTimezoneOffset());
@@ -1266,6 +1274,9 @@ private void authUser() throws AuthFailedException, IOErrorException,
12661274
* @return true if spaceName and label in the WriteList
12671275
*/
12681276
private boolean checkWriteList(String spaceName, String label) {
1277+
if (spaceLabelWriteList == null) {
1278+
return true;
1279+
}
12691280
if (!spaceLabelWriteList.containsKey(spaceName)) {
12701281
return false;
12711282
}

client/src/test/java/com/vesoft/nebula/client/storage/StorageClientTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@
1818
import com.vesoft.nebula.client.storage.scan.ScanVertexResult;
1919
import com.vesoft.nebula.client.storage.scan.ScanVertexResultIterator;
2020
import com.vesoft.nebula.client.util.ProcessUtil;
21+
2122
import java.io.IOException;
2223
import java.io.UnsupportedEncodingException;
2324
import java.util.Arrays;
2425
import java.util.List;
26+
2527
import org.junit.After;
2628
import org.junit.Assert;
2729
import org.junit.Before;
@@ -60,6 +62,9 @@ public void testStorageClientWithVersionInWhiteList() {
6062
List<HostAddress> address = Arrays.asList(new HostAddress(ip, 9559));
6163
StorageClient storageClient = new StorageClient(address);
6264
try {
65+
storageClient.setGraphAddress("127.0.0.1:9669");
66+
storageClient.setUser("root");
67+
storageClient.setPassword("nebula");
6368
storageClient.setVersion("3.0.0");
6469
assert (storageClient.connect());
6570

@@ -76,6 +81,9 @@ public void testStorageClientWithVersionNotInWhiteList() {
7681
List<HostAddress> address = Arrays.asList(new HostAddress(ip, 9559));
7782
StorageClient storageClient = new StorageClient(address);
7883
try {
84+
storageClient.setGraphAddress("127.0.0.1:9669");
85+
storageClient.setUser("root");
86+
storageClient.setPassword("nebula");
7987
storageClient.setVersion("INVALID_VERSION");
8088
storageClient.connect();
8189
assert false;

0 commit comments

Comments
 (0)