Skip to content

Commit

Permalink
process the read permission white list for root user
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicole00 committed Dec 29, 2023
1 parent 10e6eaf commit fbba099
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.vesoft.nebula.storage.ScanEdgeRequest;
import com.vesoft.nebula.storage.ScanVertexRequest;
import com.vesoft.nebula.storage.VertexProp;

import java.io.Serializable;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
Expand All @@ -34,6 +35,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

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

// the write list for users with read permission
private Map<String, List<String>> spaceLabelWriteList = new HashMap<>();
private Map<String, List<String>> spaceLabelWriteList = null;
private String version = null;

/**
Expand Down Expand Up @@ -1211,6 +1213,12 @@ private void authUser() throws AuthFailedException, IOErrorException,
version);
AuthResult authResult = graphConnection.authenticate(user, password);
long sessionId = authResult.getSessionId();

if (user.equals("root")) {
return;
}

spaceLabelWriteList = new HashMap<>();
ResultSet resultSet = new ResultSet(
graphConnection.execute(sessionId, "DESC USER " + user),
authResult.getTimezoneOffset());
Expand Down Expand Up @@ -1266,6 +1274,9 @@ private void authUser() throws AuthFailedException, IOErrorException,
* @return true if spaceName and label in the WriteList
*/
private boolean checkWriteList(String spaceName, String label) {
if (spaceLabelWriteList == null) {
return true;
}
if (!spaceLabelWriteList.containsKey(spaceName)) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@
import com.vesoft.nebula.client.storage.scan.ScanVertexResult;
import com.vesoft.nebula.client.storage.scan.ScanVertexResultIterator;
import com.vesoft.nebula.client.util.ProcessUtil;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.Arrays;
import java.util.List;

import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
Expand Down Expand Up @@ -60,6 +62,9 @@ public void testStorageClientWithVersionInWhiteList() {
List<HostAddress> address = Arrays.asList(new HostAddress(ip, 9559));
StorageClient storageClient = new StorageClient(address);
try {
storageClient.setGraphAddress("127.0.0.1:9669");
storageClient.setUser("root");
storageClient.setPassword("nebula");
storageClient.setVersion("3.0.0");
assert (storageClient.connect());

Expand All @@ -76,6 +81,9 @@ public void testStorageClientWithVersionNotInWhiteList() {
List<HostAddress> address = Arrays.asList(new HostAddress(ip, 9559));
StorageClient storageClient = new StorageClient(address);
try {
storageClient.setGraphAddress("127.0.0.1:9669");
storageClient.setUser("root");
storageClient.setPassword("nebula");
storageClient.setVersion("INVALID_VERSION");
storageClient.connect();
assert false;
Expand Down

0 comments on commit fbba099

Please sign in to comment.