You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@iotdb.apache.org by GitBox <gi...@apache.org> on 2020/09/11 01:20:42 UTC

[GitHub] [incubator-iotdb] jt2594838 commented on a change in pull request #1698: [IoTDB-850] check list user/role privilege

jt2594838 commented on a change in pull request #1698:
URL: https://github.com/apache/incubator-iotdb/pull/1698#discussion_r486717381



##########
File path: server/src/main/java/org/apache/iotdb/db/qp/executor/PlanExecutor.java
##########
@@ -1116,14 +1125,26 @@ private ListDataSet executeListRole() {
     return dataSet;
   }
 
-  private ListDataSet executeListUser() {
-    List<String> userList = authorizer.listAllUsers();
+  private ListDataSet executeListUser(AuthorPlan plan) throws AuthException {
+    List<PartialPath> paths = new ArrayList<>();
+    paths.add(plan.getNodeName());
+    // check if current user is granted list_user privilege

Review comment:
       Better replaced with `Collections.singletonList()`

##########
File path: server/src/main/java/org/apache/iotdb/db/qp/executor/PlanExecutor.java
##########
@@ -1116,14 +1125,26 @@ private ListDataSet executeListRole() {
     return dataSet;
   }
 
-  private ListDataSet executeListUser() {
-    List<String> userList = authorizer.listAllUsers();
+  private ListDataSet executeListUser(AuthorPlan plan) throws AuthException {
+    List<PartialPath> paths = new ArrayList<>();
+    paths.add(plan.getNodeName());
+    // check if current user is granted list_user privilege
+    boolean hasListUserPrivilege = AuthorityChecker
+        .check(plan.getLoginUserName(), paths, plan.getOperatorType(), plan.getLoginUserName());
+
     List<PartialPath> headerList = new ArrayList<>();
     List<TSDataType> typeList = new ArrayList<>();
     headerList.add(new PartialPath(COLUMN_USER, false));
     typeList.add(TSDataType.TEXT);
-    int index = 0;
     ListDataSet dataSet = new ListDataSet(headerList, typeList);
+
+    if (!hasListUserPrivilege) {
+      return dataSet;
+    }
+
+    List<String> userList = authorizer.listAllUsers();
+    int index = 0;

Review comment:
       What is this index for?

##########
File path: server/src/main/java/org/apache/iotdb/db/qp/physical/sys/AuthorPlan.java
##########
@@ -39,12 +39,13 @@
 public class AuthorPlan extends PhysicalPlan {
 
   private AuthorOperator.AuthorType authorType;
-  private String userName;
   private String roleName;
   private String password;
   private String newPassword;
   private Set<Integer> permissions;
   private PartialPath nodeName;
+  private String userName;
+  private String loginUserName;

Review comment:
       I think maybe we can push loginUserName down to PhysicalPlan. It is often meaningful to know who issued this plan.

##########
File path: server/src/main/java/org/apache/iotdb/db/qp/executor/PlanExecutor.java
##########
@@ -1098,13 +1099,21 @@ protected QueryDataSet processAuthorQuery(AuthorPlan plan)
     return dataSet;
   }
 
-  private ListDataSet executeListRole() {
+  private ListDataSet executeListRole(AuthorPlan plan) throws AuthException {
     int index = 0;
     List<PartialPath> headerList = new ArrayList<>();
     List<TSDataType> typeList = new ArrayList<>();
     headerList.add(new PartialPath(COLUMN_ROLE, false));
     typeList.add(TSDataType.TEXT);
     ListDataSet dataSet = new ListDataSet(headerList, typeList);
+
+    boolean hasListRolePrivilege = AuthorityChecker
+        .check(plan.getLoginUserName(), new ArrayList<>(), plan.getOperatorType(), plan.getLoginUserName());

Review comment:
       Better replaced with `Collections.emptyList()`.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org