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 2022/04/12 11:44:11 UTC

[GitHub] [iotdb] RYH61 opened a new pull request, #5492: [IOTDB-2892] add PermissionInfoDataSet and test

RYH61 opened a new pull request, #5492:
URL: https://github.com/apache/iotdb/pull/5492

   add PermissionInfoDataSet and PermissionQuery 
   add operations on operatorPermission and queryPermission in confignode
   


-- 
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.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

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


[GitHub] [iotdb] jt2594838 commented on a diff in pull request #5492: [IOTDB-2892] add PermissionInfoDataSet and test

Posted by GitBox <gi...@apache.org>.
jt2594838 commented on code in PR #5492:
URL: https://github.com/apache/iotdb/pull/5492#discussion_r851022924


##########
server/src/main/java/org/apache/iotdb/db/mpp/execution/config/AuthorizerConfigTask.java:
##########
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.db.mpp.execution.config;
+
+import org.apache.iotdb.common.rpc.thrift.TSStatus;
+import org.apache.iotdb.commons.exception.BadNodeUrlException;
+import org.apache.iotdb.confignode.rpc.thrift.TAuthorizerReq;
+import org.apache.iotdb.db.auth.AuthException;
+import org.apache.iotdb.db.client.ConfigNodeClient;
+import org.apache.iotdb.db.mpp.sql.planner.plan.node.metedata.write.AuthorNode;
+import org.apache.iotdb.db.mpp.sql.statement.sys.AuthorStatement;
+import org.apache.iotdb.rpc.IoTDBConnectionException;
+import org.apache.iotdb.rpc.StatementExecutionException;
+import org.apache.iotdb.rpc.TSStatusCode;
+
+import com.google.common.util.concurrent.ListenableFuture;
+import com.google.common.util.concurrent.SettableFuture;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Locale;
+
+public class AuthorizerConfigTask implements IConfigTask {
+
+  private static final Logger LOGGER = LoggerFactory.getLogger(AuthorizerConfigTask.class);
+
+  private AuthorStatement authorStatement;
+
+  public AuthorizerConfigTask(AuthorStatement authorStatement) {
+    this.authorStatement = authorStatement;
+  }
+
+  @Override
+  public ListenableFuture<Void> execute() {
+    SettableFuture<Void> future = SettableFuture.create();
+    ConfigNodeClient configNodeClient = null;
+    try {
+      // Construct request using statement
+      TAuthorizerReq req =
+          new TAuthorizerReq(
+              authorStatement.getAuthorType().ordinal(),
+              authorStatement.getUserName() == null ? "" : authorStatement.getUserName(),
+              authorStatement.getRoleName() == null ? "" : authorStatement.getRoleName(),
+              authorStatement.getPassWord() == null ? "" : authorStatement.getPassWord(),
+              authorStatement.getNewPassword() == null ? "" : authorStatement.getNewPassword(),
+              AuthorNode.strToPermissions(authorStatement.getPrivilegeList()),
+              authorStatement.getNodeName() == null
+                  ? ""
+                  : authorStatement.getNodeName().getFullPath());
+      configNodeClient = new ConfigNodeClient();
+      // Send request to some API server
+      TSStatus tsStatus = configNodeClient.operatePermission(req);

Review Comment:
   Yes, but where is the `TSStatus tsStatus = configNodeClient.operatePermission(req);`  returned to the client?



-- 
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.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

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


[GitHub] [iotdb] RYH61 commented on a diff in pull request #5492: [IOTDB-2892] add PermissionInfoDataSet and test

Posted by GitBox <gi...@apache.org>.
RYH61 commented on code in PR #5492:
URL: https://github.com/apache/iotdb/pull/5492#discussion_r851023872


##########
confignode/src/main/java/org/apache/iotdb/confignode/physical/sys/AuthorPlan.java:
##########
@@ -228,6 +228,53 @@ private int getPlanTypeOrdinal(PhysicalPlanType physicalPlanType) {
     return type;
   }
 
+  /**
+   * A mapping between AuthorType and PhysicalPlanType
+   *
+   * @param i
+   * @return
+   */
+  public static PhysicalPlanType convert(int i) {
+    switch (i) {
+      case 0:
+        return PhysicalPlanType.CREATE_USER;
+      case 1:
+        return PhysicalPlanType.CREATE_ROLE;
+      case 2:
+        return PhysicalPlanType.DROP_USER;
+      case 3:
+        return PhysicalPlanType.DROP_ROLE;
+      case 4:
+        return PhysicalPlanType.GRANT_ROLE;
+      case 5:
+        return PhysicalPlanType.GRANT_USER;
+      case 6:
+        return PhysicalPlanType.GRANT_ROLE_TO_USER;
+      case 7:
+        return PhysicalPlanType.REVOKE_USER;
+      case 8:
+        return PhysicalPlanType.REVOKE_ROLE;
+      case 9:
+        return PhysicalPlanType.REVOKE_ROLE_FROM_USER;
+      case 10:
+        return PhysicalPlanType.UPDATE_USER;
+      case 11:
+        return PhysicalPlanType.LIST_USER;
+      case 12:
+        return PhysicalPlanType.LIST_ROLE;
+      case 13:
+        return PhysicalPlanType.LIST_USER_PRIVILEGE;
+      case 14:
+        return PhysicalPlanType.LIST_ROLE_PRIVILEGE;
+      case 15:
+        return PhysicalPlanType.LIST_USER_ROLES;
+      case 16:
+        return PhysicalPlanType.LIST_ROLE_USERS;
+      default:
+        return null;
+    }
+  }
+

Review Comment:
   Because the type index in PhysicalPlanType is not consistent with the AuthorType type index passed from datanode, a conversion is required instead of using PhysicalPlanType.values()[i]



-- 
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.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

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


[GitHub] [iotdb] RYH61 commented on a diff in pull request #5492: [IOTDB-2892] add PermissionInfoDataSet and test

Posted by GitBox <gi...@apache.org>.
RYH61 commented on code in PR #5492:
URL: https://github.com/apache/iotdb/pull/5492#discussion_r850206997


##########
confignode/src/main/java/org/apache/iotdb/confignode/conf/ConfigNodeConstant.java:
##########
@@ -43,6 +43,10 @@ public class ConfigNodeConstant {
   public static final String CONF_DIR = "conf";
   public static final String CONSENSUS_FOLDER = "consensus";
 
+  public static final String COLUMN_ROLE = "role";

Review Comment:
   ok



-- 
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.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

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


[GitHub] [iotdb] RYH61 commented on a diff in pull request #5492: [IOTDB-2892] add PermissionInfoDataSet and test

Posted by GitBox <gi...@apache.org>.
RYH61 commented on code in PR #5492:
URL: https://github.com/apache/iotdb/pull/5492#discussion_r851023028


##########
confignode/src/main/java/org/apache/iotdb/confignode/service/thrift/server/ConfigNodeRPCServerProcessor.java:
##########
@@ -186,14 +187,15 @@ public TDataPartitionResp getOrCreateDataPartition(TDataPartitionReq req) throws
 
   @Override
   public TSStatus operatePermission(TAuthorizerReq req) throws TException {
-    if (req.getAuthorType() < 0 || req.getAuthorType() >= PhysicalPlanType.values().length) {
-      throw new IndexOutOfBoundsException("Invalid ordinal");
+    if (req.getAuthorType() < 0
+        || req.getAuthorType() >= AuthorOperator.AuthorType.values().length) {
+      throw new IndexOutOfBoundsException("Invalid Author Type ordinal");
     }
     AuthorPlan plan = null;
     try {
       plan =
           new AuthorPlan(
-              PhysicalPlanType.values()[req.getAuthorType()],
+              AuthorPlan.convert(req.getAuthorType()),

Review Comment:
   The authorization operation type passed from the client is the index of the passed AuthorType. If the PhysicalPlanType is used here to obtain the corresponding type or cause the wrong order



-- 
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.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

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


[GitHub] [iotdb] mychaow commented on pull request #5492: [IOTDB-2892] add PermissionInfoDataSet and test

Posted by GitBox <gi...@apache.org>.
mychaow commented on PR #5492:
URL: https://github.com/apache/iotdb/pull/5492#issuecomment-1101105967

   LGTM


-- 
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.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

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


[GitHub] [iotdb] RYH61 commented on a diff in pull request #5492: [IOTDB-2892] add PermissionInfoDataSet and test

Posted by GitBox <gi...@apache.org>.
RYH61 commented on code in PR #5492:
URL: https://github.com/apache/iotdb/pull/5492#discussion_r851027382


##########
confignode/src/main/java/org/apache/iotdb/confignode/physical/sys/AuthorPlan.java:
##########
@@ -228,6 +228,53 @@ private int getPlanTypeOrdinal(PhysicalPlanType physicalPlanType) {
     return type;
   }
 
+  /**
+   * A mapping between AuthorType and PhysicalPlanType
+   *
+   * @param i
+   * @return
+   */
+  public static PhysicalPlanType convert(int i) {
+    switch (i) {
+      case 0:
+        return PhysicalPlanType.CREATE_USER;
+      case 1:
+        return PhysicalPlanType.CREATE_ROLE;
+      case 2:
+        return PhysicalPlanType.DROP_USER;
+      case 3:
+        return PhysicalPlanType.DROP_ROLE;
+      case 4:
+        return PhysicalPlanType.GRANT_ROLE;
+      case 5:
+        return PhysicalPlanType.GRANT_USER;
+      case 6:
+        return PhysicalPlanType.GRANT_ROLE_TO_USER;
+      case 7:
+        return PhysicalPlanType.REVOKE_USER;
+      case 8:
+        return PhysicalPlanType.REVOKE_ROLE;
+      case 9:
+        return PhysicalPlanType.REVOKE_ROLE_FROM_USER;
+      case 10:
+        return PhysicalPlanType.UPDATE_USER;
+      case 11:
+        return PhysicalPlanType.LIST_USER;
+      case 12:
+        return PhysicalPlanType.LIST_ROLE;
+      case 13:
+        return PhysicalPlanType.LIST_USER_PRIVILEGE;
+      case 14:
+        return PhysicalPlanType.LIST_ROLE_PRIVILEGE;
+      case 15:
+        return PhysicalPlanType.LIST_USER_ROLES;
+      case 16:
+        return PhysicalPlanType.LIST_ROLE_USERS;
+      default:
+        return null;
+    }
+  }
+

Review Comment:
   ok, i've made the edits



-- 
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.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

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


[GitHub] [iotdb] jt2594838 commented on a diff in pull request #5492: [IOTDB-2892] add PermissionInfoDataSet and test

Posted by GitBox <gi...@apache.org>.
jt2594838 commented on code in PR #5492:
URL: https://github.com/apache/iotdb/pull/5492#discussion_r851019174


##########
confignode/src/main/java/org/apache/iotdb/confignode/physical/sys/AuthorPlan.java:
##########
@@ -228,6 +228,53 @@ private int getPlanTypeOrdinal(PhysicalPlanType physicalPlanType) {
     return type;
   }
 
+  /**
+   * A mapping between AuthorType and PhysicalPlanType
+   *
+   * @param i
+   * @return
+   */
+  public static PhysicalPlanType convert(int i) {
+    switch (i) {
+      case 0:
+        return PhysicalPlanType.CREATE_USER;
+      case 1:
+        return PhysicalPlanType.CREATE_ROLE;
+      case 2:
+        return PhysicalPlanType.DROP_USER;
+      case 3:
+        return PhysicalPlanType.DROP_ROLE;
+      case 4:
+        return PhysicalPlanType.GRANT_ROLE;
+      case 5:
+        return PhysicalPlanType.GRANT_USER;
+      case 6:
+        return PhysicalPlanType.GRANT_ROLE_TO_USER;
+      case 7:
+        return PhysicalPlanType.REVOKE_USER;
+      case 8:
+        return PhysicalPlanType.REVOKE_ROLE;
+      case 9:
+        return PhysicalPlanType.REVOKE_ROLE_FROM_USER;
+      case 10:
+        return PhysicalPlanType.UPDATE_USER;
+      case 11:
+        return PhysicalPlanType.LIST_USER;
+      case 12:
+        return PhysicalPlanType.LIST_ROLE;
+      case 13:
+        return PhysicalPlanType.LIST_USER_PRIVILEGE;
+      case 14:
+        return PhysicalPlanType.LIST_ROLE_PRIVILEGE;
+      case 15:
+        return PhysicalPlanType.LIST_USER_ROLES;
+      case 16:
+        return PhysicalPlanType.LIST_ROLE_USERS;
+      default:
+        return null;
+    }
+  }
+

Review Comment:
   The method above uses ordinal to convert a type to an integer. For consistency, better to use `PhysicalPlanType.values[i]` instead, which is also simpler.



##########
confignode/src/main/java/org/apache/iotdb/confignode/service/thrift/server/ConfigNodeRPCServerProcessor.java:
##########
@@ -186,14 +187,15 @@ public TDataPartitionResp getOrCreateDataPartition(TDataPartitionReq req) throws
 
   @Override
   public TSStatus operatePermission(TAuthorizerReq req) throws TException {
-    if (req.getAuthorType() < 0 || req.getAuthorType() >= PhysicalPlanType.values().length) {
-      throw new IndexOutOfBoundsException("Invalid ordinal");
+    if (req.getAuthorType() < 0
+        || req.getAuthorType() >= AuthorOperator.AuthorType.values().length) {
+      throw new IndexOutOfBoundsException("Invalid Author Type ordinal");
     }
     AuthorPlan plan = null;
     try {
       plan =
           new AuthorPlan(
-              PhysicalPlanType.values()[req.getAuthorType()],
+              AuthorPlan.convert(req.getAuthorType()),

Review Comment:
   Could you please explain the change?



-- 
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.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

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


[GitHub] [iotdb] jt2594838 commented on a diff in pull request #5492: [IOTDB-2892] add PermissionInfoDataSet and test

Posted by GitBox <gi...@apache.org>.
jt2594838 commented on code in PR #5492:
URL: https://github.com/apache/iotdb/pull/5492#discussion_r851014750


##########
confignode/src/main/java/org/apache/iotdb/confignode/manager/Manager.java:
##########
@@ -132,4 +132,12 @@ public interface Manager {
    * @return
    */
   TSStatus operatePermission(PhysicalPlan physicalPlan);
+
+  /**
+   * query Permission
+   *
+   * @param physicalPlan
+   * @return
+   */
+  DataSet queryPermission(PhysicalPlan physicalPlan);

Review Comment:
   Is there anywhere that the return value is used as a DataSet? If not, change the return type to PermissionInfoDataSet directly.
   
   Always add explanations to the code, not just the PR.



-- 
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.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

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


[GitHub] [iotdb] jt2594838 commented on a diff in pull request #5492: [IOTDB-2892] add PermissionInfoDataSet and test

Posted by GitBox <gi...@apache.org>.
jt2594838 commented on code in PR #5492:
URL: https://github.com/apache/iotdb/pull/5492#discussion_r850218947


##########
confignode/src/main/java/org/apache/iotdb/confignode/manager/Manager.java:
##########
@@ -132,4 +132,12 @@ public interface Manager {
    * @return
    */
   TSStatus operatePermission(PhysicalPlan physicalPlan);
+
+  /**
+   * query Permission
+   *
+   * @param physicalPlan
+   * @return
+   */
+  DataSet queryPermission(PhysicalPlan physicalPlan);

Review Comment:
   Add to comment "What is the requirement of the parameter? In what form is the DataSet returned?"



##########
confignode/src/main/java/org/apache/iotdb/confignode/manager/ConfigManager.java:
##########
@@ -292,4 +292,12 @@ public TSStatus operatePermission(PhysicalPlan physicalPlan) {
     }
     return ERROR_TSSTATUS;
   }
+
+  @Override
+  public DataSet queryPermission(PhysicalPlan physicalPlan) {
+    if (physicalPlan instanceof AuthorPlan) {
+      return permissionManager.queryPermission((AuthorPlan) physicalPlan);
+    }
+    return new DataPartitionDataSet();

Review Comment:
   Throw an exception if the type mismatches or change the argument type to AuthorPlan.



##########
thrift-confignode/src/main/thrift/confignode.thrift:
##########
@@ -117,6 +117,11 @@ struct TAuthorizerReq {
   7: required string nodeName
 }
 
+struct TAuthorizerResp {
+    1: required common.TSStatus status
+    2: required map<string, list<string>> authorizerInfo
+}
+

Review Comment:
   I suggest using a dataset definition that is more common. Better to discuss with the query guys.



##########
confignode/src/main/java/org/apache/iotdb/confignode/consensus/response/PermissionInfoDataSet.java:
##########
@@ -19,8 +19,37 @@
 
 package org.apache.iotdb.confignode.consensus.response;
 
+import org.apache.iotdb.common.rpc.thrift.TSStatus;
 import org.apache.iotdb.consensus.common.DataSet;
 
+import java.util.List;
+import java.util.Map;
+
 public class PermissionInfoDataSet implements DataSet {

Review Comment:
   What is the point of `implements DataSet`?



##########
confignode/src/main/java/org/apache/iotdb/confignode/manager/ConfigManager.java:
##########
@@ -292,4 +293,12 @@ public TSStatus operatePermission(PhysicalPlan physicalPlan) {
     }
     return ERROR_TSSTATUS;
   }
+
+  @Override
+  public DataSet queryPermission(PhysicalPlan physicalPlan) {
+    if (physicalPlan instanceof AuthorPlan) {
+      return permissionManager.queryPermission((AuthorPlan) physicalPlan);
+    }
+    return new PermissionInfoDataSet();

Review Comment:
   Throw an exception or change the argument type to AuthorPlan.



##########
server/src/main/java/org/apache/iotdb/db/mpp/execution/config/AuthorizerConfigTask.java:
##########
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.db.mpp.execution.config;
+
+import org.apache.iotdb.common.rpc.thrift.TSStatus;
+import org.apache.iotdb.commons.exception.BadNodeUrlException;
+import org.apache.iotdb.confignode.rpc.thrift.TAuthorizerReq;
+import org.apache.iotdb.db.auth.AuthException;
+import org.apache.iotdb.db.client.ConfigNodeClient;
+import org.apache.iotdb.db.mpp.sql.planner.plan.node.metedata.write.AuthorNode;
+import org.apache.iotdb.db.mpp.sql.statement.sys.AuthorStatement;
+import org.apache.iotdb.rpc.IoTDBConnectionException;
+import org.apache.iotdb.rpc.StatementExecutionException;
+import org.apache.iotdb.rpc.TSStatusCode;
+
+import com.google.common.util.concurrent.ListenableFuture;
+import com.google.common.util.concurrent.SettableFuture;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Locale;
+
+public class AuthorizerConfigTask implements IConfigTask {
+
+  private static final Logger LOGGER = LoggerFactory.getLogger(AuthorizerConfigTask.class);
+
+  private AuthorStatement authorStatement;
+
+  public AuthorizerConfigTask(AuthorStatement authorStatement) {
+    this.authorStatement = authorStatement;
+  }
+
+  @Override
+  public ListenableFuture<Void> execute() {
+    SettableFuture<Void> future = SettableFuture.create();
+    ConfigNodeClient configNodeClient = null;
+    try {
+      // Construct request using statement
+      TAuthorizerReq req =
+          new TAuthorizerReq(
+              authorStatement.getAuthorType().ordinal(),
+              authorStatement.getUserName() == null ? "" : authorStatement.getUserName(),
+              authorStatement.getRoleName() == null ? "" : authorStatement.getRoleName(),
+              authorStatement.getPassWord() == null ? "" : authorStatement.getPassWord(),
+              authorStatement.getNewPassword() == null ? "" : authorStatement.getNewPassword(),
+              AuthorNode.strToPermissions(authorStatement.getPrivilegeList()),
+              authorStatement.getNodeName() == null
+                  ? ""
+                  : authorStatement.getNodeName().getFullPath());
+      configNodeClient = new ConfigNodeClient();
+      // Send request to some API server
+      TSStatus tsStatus = configNodeClient.operatePermission(req);

Review Comment:
   If the status contains an additional message, how can the user retrieve it?



##########
server/src/main/java/org/apache/iotdb/db/mpp/execution/config/AuthorizerConfigTask.java:
##########
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.db.mpp.execution.config;
+
+import org.apache.iotdb.common.rpc.thrift.TSStatus;
+import org.apache.iotdb.commons.exception.BadNodeUrlException;
+import org.apache.iotdb.confignode.rpc.thrift.TAuthorizerReq;
+import org.apache.iotdb.db.auth.AuthException;
+import org.apache.iotdb.db.client.ConfigNodeClient;
+import org.apache.iotdb.db.mpp.sql.planner.plan.node.metedata.write.AuthorNode;
+import org.apache.iotdb.db.mpp.sql.statement.sys.AuthorStatement;
+import org.apache.iotdb.rpc.IoTDBConnectionException;
+import org.apache.iotdb.rpc.StatementExecutionException;
+import org.apache.iotdb.rpc.TSStatusCode;
+
+import com.google.common.util.concurrent.ListenableFuture;
+import com.google.common.util.concurrent.SettableFuture;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Locale;
+
+public class AuthorizerConfigTask implements IConfigTask {
+
+  private static final Logger LOGGER = LoggerFactory.getLogger(AuthorizerConfigTask.class);
+
+  private AuthorStatement authorStatement;
+
+  public AuthorizerConfigTask(AuthorStatement authorStatement) {
+    this.authorStatement = authorStatement;
+  }
+
+  @Override
+  public ListenableFuture<Void> execute() {
+    SettableFuture<Void> future = SettableFuture.create();
+    ConfigNodeClient configNodeClient = null;
+    try {
+      // Construct request using statement
+      TAuthorizerReq req =
+          new TAuthorizerReq(
+              authorStatement.getAuthorType().ordinal(),
+              authorStatement.getUserName() == null ? "" : authorStatement.getUserName(),
+              authorStatement.getRoleName() == null ? "" : authorStatement.getRoleName(),
+              authorStatement.getPassWord() == null ? "" : authorStatement.getPassWord(),
+              authorStatement.getNewPassword() == null ? "" : authorStatement.getNewPassword(),
+              AuthorNode.strToPermissions(authorStatement.getPrivilegeList()),
+              authorStatement.getNodeName() == null
+                  ? ""
+                  : authorStatement.getNodeName().getFullPath());
+      configNodeClient = new ConfigNodeClient();

Review Comment:
   Is the client properly released?



-- 
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.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

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


[GitHub] [iotdb] RYH61 commented on a diff in pull request #5492: [IOTDB-2892] add PermissionInfoDataSet and test

Posted by GitBox <gi...@apache.org>.
RYH61 commented on code in PR #5492:
URL: https://github.com/apache/iotdb/pull/5492#discussion_r850271984


##########
confignode/src/main/java/org/apache/iotdb/confignode/manager/Manager.java:
##########
@@ -132,4 +132,12 @@ public interface Manager {
    * @return
    */
   TSStatus operatePermission(PhysicalPlan physicalPlan);
+
+  /**
+   * query Permission
+   *
+   * @param physicalPlan
+   * @return
+   */
+  DataSet queryPermission(PhysicalPlan physicalPlan);

Review Comment:
   Parameters contain different information depending on the type of operation



-- 
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.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

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


[GitHub] [iotdb] RYH61 commented on a diff in pull request #5492: [IOTDB-2892] add PermissionInfoDataSet and test

Posted by GitBox <gi...@apache.org>.
RYH61 commented on code in PR #5492:
URL: https://github.com/apache/iotdb/pull/5492#discussion_r850270887


##########
confignode/src/main/java/org/apache/iotdb/confignode/manager/Manager.java:
##########
@@ -132,4 +132,12 @@ public interface Manager {
    * @return
    */
   TSStatus operatePermission(PhysicalPlan physicalPlan);
+
+  /**
+   * query Permission
+   *
+   * @param physicalPlan
+   * @return
+   */
+  DataSet queryPermission(PhysicalPlan physicalPlan);

Review Comment:
   The final return type is PermissionInfoDataSet



-- 
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.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

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


[GitHub] [iotdb] qiaojialin commented on a diff in pull request #5492: [IOTDB-2892] add PermissionInfoDataSet and test

Posted by GitBox <gi...@apache.org>.
qiaojialin commented on code in PR #5492:
URL: https://github.com/apache/iotdb/pull/5492#discussion_r850339878


##########
confignode/src/main/java/org/apache/iotdb/confignode/consensus/response/PermissionInfoDataSet.java:
##########
@@ -19,8 +19,37 @@
 
 package org.apache.iotdb.confignode.consensus.response;
 
+import org.apache.iotdb.common.rpc.thrift.TSStatus;
 import org.apache.iotdb.consensus.common.DataSet;
 
+import java.util.List;
+import java.util.Map;
+
 public class PermissionInfoDataSet implements DataSet {

Review Comment:
   DataSet is defined in the read interface of IStateMachine



-- 
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.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

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


[GitHub] [iotdb] RYH61 commented on a diff in pull request #5492: [IOTDB-2892] add PermissionInfoDataSet and test

Posted by GitBox <gi...@apache.org>.
RYH61 commented on code in PR #5492:
URL: https://github.com/apache/iotdb/pull/5492#discussion_r851061242


##########
server/src/main/java/org/apache/iotdb/db/mpp/execution/config/AuthorizerConfigTask.java:
##########
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.db.mpp.execution.config;
+
+import org.apache.iotdb.common.rpc.thrift.TSStatus;
+import org.apache.iotdb.commons.exception.BadNodeUrlException;
+import org.apache.iotdb.confignode.rpc.thrift.TAuthorizerReq;
+import org.apache.iotdb.db.auth.AuthException;
+import org.apache.iotdb.db.client.ConfigNodeClient;
+import org.apache.iotdb.db.mpp.sql.planner.plan.node.metedata.write.AuthorNode;
+import org.apache.iotdb.db.mpp.sql.statement.sys.AuthorStatement;
+import org.apache.iotdb.rpc.IoTDBConnectionException;
+import org.apache.iotdb.rpc.StatementExecutionException;
+import org.apache.iotdb.rpc.TSStatusCode;
+
+import com.google.common.util.concurrent.ListenableFuture;
+import com.google.common.util.concurrent.SettableFuture;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Locale;
+
+public class AuthorizerConfigTask implements IConfigTask {
+
+  private static final Logger LOGGER = LoggerFactory.getLogger(AuthorizerConfigTask.class);
+
+  private AuthorStatement authorStatement;
+
+  public AuthorizerConfigTask(AuthorStatement authorStatement) {
+    this.authorStatement = authorStatement;
+  }
+
+  @Override
+  public ListenableFuture<Void> execute() {
+    SettableFuture<Void> future = SettableFuture.create();
+    ConfigNodeClient configNodeClient = null;
+    try {
+      // Construct request using statement
+      TAuthorizerReq req =
+          new TAuthorizerReq(
+              authorStatement.getAuthorType().ordinal(),
+              authorStatement.getUserName() == null ? "" : authorStatement.getUserName(),
+              authorStatement.getRoleName() == null ? "" : authorStatement.getRoleName(),
+              authorStatement.getPassWord() == null ? "" : authorStatement.getPassWord(),
+              authorStatement.getNewPassword() == null ? "" : authorStatement.getNewPassword(),
+              AuthorNode.strToPermissions(authorStatement.getPrivilegeList()),
+              authorStatement.getNodeName() == null
+                  ? ""
+                  : authorStatement.getNodeName().getFullPath());
+      configNodeClient = new ConfigNodeClient();
+      // Send request to some API server
+      TSStatus tsStatus = configNodeClient.operatePermission(req);

Review Comment:
   The information returned by status here is only successful, and after the operation fails, the error information will be thrown in the exception



-- 
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.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

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


[GitHub] [iotdb] mychaow merged pull request #5492: [IOTDB-2892] add PermissionInfoDataSet and test

Posted by GitBox <gi...@apache.org>.
mychaow merged PR #5492:
URL: https://github.com/apache/iotdb/pull/5492


-- 
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.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

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


[GitHub] [iotdb] RYH61 commented on a diff in pull request #5492: [IOTDB-2892] add PermissionInfoDataSet and test

Posted by GitBox <gi...@apache.org>.
RYH61 commented on code in PR #5492:
URL: https://github.com/apache/iotdb/pull/5492#discussion_r850206366


##########
server/src/main/java/org/apache/iotdb/db/mpp/execution/config/AuthorizerConfigTask.java:
##########
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.db.mpp.execution.config;
+
+import org.apache.iotdb.common.rpc.thrift.TSStatus;
+import org.apache.iotdb.commons.exception.BadNodeUrlException;
+import org.apache.iotdb.confignode.rpc.thrift.TAuthorizerReq;
+import org.apache.iotdb.db.auth.AuthException;
+import org.apache.iotdb.db.client.ConfigNodeClient;
+import org.apache.iotdb.db.mpp.sql.planner.plan.node.metedata.write.AuthorNode;
+import org.apache.iotdb.db.mpp.sql.statement.sys.AuthorStatement;
+import org.apache.iotdb.rpc.IoTDBConnectionException;
+import org.apache.iotdb.rpc.StatementExecutionException;
+import org.apache.iotdb.rpc.TSStatusCode;
+
+import com.google.common.util.concurrent.ListenableFuture;
+import com.google.common.util.concurrent.SettableFuture;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Locale;
+
+public class AuthorizerConfigTask implements IConfigTask {
+
+  private static final Logger LOGGER = LoggerFactory.getLogger(AuthorizerConfigTask.class);
+
+  private AuthorStatement authorStatement;
+
+  public AuthorizerConfigTask(AuthorStatement authorStatement) {
+    this.authorStatement = authorStatement;
+  }
+
+  @Override
+  public ListenableFuture<Void> execute() {
+    SettableFuture<Void> future = SettableFuture.create();
+    ConfigNodeClient configNodeClient = null;
+    try {
+      // Construct request using statement
+      TAuthorizerReq req =
+          new TAuthorizerReq(
+              authorStatement.getAuthorType().ordinal(),
+              authorStatement.getUserName() == null ? "" : authorStatement.getUserName(),
+              authorStatement.getRoleName() == null ? "" : authorStatement.getRoleName(),
+              authorStatement.getPassWord() == null ? "" : authorStatement.getPassWord(),
+              authorStatement.getNewPassword() == null ? "" : authorStatement.getNewPassword(),
+              AuthorNode.strToPermissions(authorStatement.getPrivilegeList()),
+              authorStatement.getNodeName() == null
+                  ? ""
+                  : authorStatement.getNodeName().getFullPath());
+      configNodeClient = new ConfigNodeClient();
+      // Send request to some API server
+      TSStatus tsStatus = configNodeClient.operatePermission(req);
+      // Get response or throw exception
+      if (TSStatusCode.SUCCESS_STATUS.getStatusCode() != tsStatus.getCode()) {
+        LOGGER.error(
+            "Failed to execute {} in config node, status is {}.",
+            authorStatement.getAuthorType().toString().toLowerCase(Locale.ROOT),
+            tsStatus);
+        future.setException(new StatementExecutionException(tsStatus));
+      } else {
+        future.set(null);
+      }
+    } catch (IoTDBConnectionException | BadNodeUrlException e) {
+      LOGGER.error("Failed to connect to config node.");
+      future.setException(e);
+    } catch (AuthException e) {
+      LOGGER.error("No such privilege." + authorStatement.getAuthorType());

Review Comment:
   ok



-- 
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.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

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


[GitHub] [iotdb] RYH61 commented on a diff in pull request #5492: [IOTDB-2892] add PermissionInfoDataSet and test

Posted by GitBox <gi...@apache.org>.
RYH61 commented on code in PR #5492:
URL: https://github.com/apache/iotdb/pull/5492#discussion_r850286286


##########
server/src/main/java/org/apache/iotdb/db/mpp/execution/config/AuthorizerConfigTask.java:
##########
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.db.mpp.execution.config;
+
+import org.apache.iotdb.common.rpc.thrift.TSStatus;
+import org.apache.iotdb.commons.exception.BadNodeUrlException;
+import org.apache.iotdb.confignode.rpc.thrift.TAuthorizerReq;
+import org.apache.iotdb.db.auth.AuthException;
+import org.apache.iotdb.db.client.ConfigNodeClient;
+import org.apache.iotdb.db.mpp.sql.planner.plan.node.metedata.write.AuthorNode;
+import org.apache.iotdb.db.mpp.sql.statement.sys.AuthorStatement;
+import org.apache.iotdb.rpc.IoTDBConnectionException;
+import org.apache.iotdb.rpc.StatementExecutionException;
+import org.apache.iotdb.rpc.TSStatusCode;
+
+import com.google.common.util.concurrent.ListenableFuture;
+import com.google.common.util.concurrent.SettableFuture;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Locale;
+
+public class AuthorizerConfigTask implements IConfigTask {
+
+  private static final Logger LOGGER = LoggerFactory.getLogger(AuthorizerConfigTask.class);
+
+  private AuthorStatement authorStatement;
+
+  public AuthorizerConfigTask(AuthorStatement authorStatement) {
+    this.authorStatement = authorStatement;
+  }
+
+  @Override
+  public ListenableFuture<Void> execute() {
+    SettableFuture<Void> future = SettableFuture.create();
+    ConfigNodeClient configNodeClient = null;
+    try {
+      // Construct request using statement
+      TAuthorizerReq req =
+          new TAuthorizerReq(
+              authorStatement.getAuthorType().ordinal(),
+              authorStatement.getUserName() == null ? "" : authorStatement.getUserName(),
+              authorStatement.getRoleName() == null ? "" : authorStatement.getRoleName(),
+              authorStatement.getPassWord() == null ? "" : authorStatement.getPassWord(),
+              authorStatement.getNewPassword() == null ? "" : authorStatement.getNewPassword(),
+              AuthorNode.strToPermissions(authorStatement.getPrivilegeList()),
+              authorStatement.getNodeName() == null
+                  ? ""
+                  : authorStatement.getNodeName().getFullPath());
+      configNodeClient = new ConfigNodeClient();

Review Comment:
   I have added close



-- 
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.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

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


[GitHub] [iotdb] RYH61 commented on a diff in pull request #5492: [IOTDB-2892] add PermissionInfoDataSet and test

Posted by GitBox <gi...@apache.org>.
RYH61 commented on code in PR #5492:
URL: https://github.com/apache/iotdb/pull/5492#discussion_r850222187


##########
confignode/src/main/java/org/apache/iotdb/confignode/manager/ConfigManager.java:
##########
@@ -292,4 +292,12 @@ public TSStatus operatePermission(PhysicalPlan physicalPlan) {
     }
     return ERROR_TSSTATUS;
   }
+
+  @Override
+  public DataSet queryPermission(PhysicalPlan physicalPlan) {
+    if (physicalPlan instanceof AuthorPlan) {
+      return permissionManager.queryPermission((AuthorPlan) physicalPlan);
+    }
+    return new DataPartitionDataSet();

Review Comment:
   ok



-- 
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.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

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


[GitHub] [iotdb] RYH61 commented on a diff in pull request #5492: [IOTDB-2892] add PermissionInfoDataSet and test

Posted by GitBox <gi...@apache.org>.
RYH61 commented on code in PR #5492:
URL: https://github.com/apache/iotdb/pull/5492#discussion_r850210150


##########
confignode/src/test/java/org/apache/iotdb/confignode/service/thrift/server/ConfigNodeRPCServerProcessorTest.java:
##########
@@ -489,4 +496,353 @@ public void getAndCreateDataPartitionTest() throws TException {
         timePartitionSlotNum,
         dataPartitionResp.getDataPartitionMap());
   }
+
+  @Test
+  public void permissionTest() throws TException {
+    TSStatus status;
+
+    // register DataNodes
+    TDataNodeRegisterReq registerReq0 = new TDataNodeRegisterReq(new EndPoint("0.0.0.0", 6667));
+    TDataNodeRegisterReq registerReq1 = new TDataNodeRegisterReq(new EndPoint("0.0.0.0", 6668));
+    TDataNodeRegisterReq registerReq2 = new TDataNodeRegisterReq(new EndPoint("0.0.0.0", 6669));
+    status = processor.registerDataNode(registerReq0).getStatus();
+    Assert.assertEquals(TSStatusCode.SUCCESS_STATUS.getStatusCode(), status.getCode());
+    status = processor.registerDataNode(registerReq1).getStatus();
+    Assert.assertEquals(TSStatusCode.SUCCESS_STATUS.getStatusCode(), status.getCode());
+    status = processor.registerDataNode(registerReq2).getStatus();
+    Assert.assertEquals(TSStatusCode.SUCCESS_STATUS.getStatusCode(), status.getCode());

Review Comment:
   ok



##########
confignode/src/main/java/org/apache/iotdb/confignode/conf/ConfigNodeConf.java:
##########
@@ -97,6 +97,8 @@ public class ConfigNodeConf {
   /** The number of DataRegions of each StorageGroup */
   private int dataRegionCount = 1;
 
+  private String adminName = "root";

Review Comment:
   ok



-- 
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.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

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


[GitHub] [iotdb] RYH61 commented on a diff in pull request #5492: [IOTDB-2892] add PermissionInfoDataSet and test

Posted by GitBox <gi...@apache.org>.
RYH61 commented on code in PR #5492:
URL: https://github.com/apache/iotdb/pull/5492#discussion_r850205394


##########
confignode/src/test/java/org/apache/iotdb/confignode/auth/AuthorTest.java:
##########
@@ -41,4 +52,21 @@ public void tearDown() throws Exception {
   }
 
   // TODO: ADD TEST
+  @Test
+  public void test() {
+    ConfigIService.Client clients;
+    try {
+      TTransport transport = RpcTransportFactory.INSTANCE.getTransport("0.0.0.0", 22277, 2000);

Review Comment:
   This test is currently removed and will be re-added later



##########
confignode/src/test/java/org/apache/iotdb/confignode/auth/AuthorTest.java:
##########
@@ -41,4 +52,21 @@ public void tearDown() throws Exception {
   }
 
   // TODO: ADD TEST
+  @Test
+  public void test() {
+    ConfigIService.Client clients;
+    try {
+      TTransport transport = RpcTransportFactory.INSTANCE.getTransport("0.0.0.0", 22277, 2000);
+      transport.open();
+      clients = new ConfigIService.Client(new TBinaryProtocol(transport));
+      TAuthorizerReq tAuthorizerReq;
+      tAuthorizerReq = new TAuthorizerReq(1, "renrne", "", "renren", "", new HashSet<>(), "");
+      TSStatus tsStatus = clients.operatePermission(tAuthorizerReq);
+      System.out.println(tsStatus.getCode());
+    } catch (TTransportException e) {
+      e.printStackTrace();

Review Comment:
   This test is currently removed and will be re-added later



-- 
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.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

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


[GitHub] [iotdb] RYH61 commented on a diff in pull request #5492: [IOTDB-2892] add PermissionInfoDataSet and test

Posted by GitBox <gi...@apache.org>.
RYH61 commented on code in PR #5492:
URL: https://github.com/apache/iotdb/pull/5492#discussion_r851037963


##########
confignode/src/main/java/org/apache/iotdb/confignode/consensus/response/PermissionInfoDataSet.java:
##########
@@ -19,8 +19,37 @@
 
 package org.apache.iotdb.confignode.consensus.response;
 
+import org.apache.iotdb.common.rpc.thrift.TSStatus;
 import org.apache.iotdb.consensus.common.DataSet;
 
+import java.util.List;
+import java.util.Map;
+
 public class PermissionInfoDataSet implements DataSet {

Review Comment:
   In the process of subsequent reading, DataSet is used



-- 
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.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

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


[GitHub] [iotdb] RYH61 commented on a diff in pull request #5492: [IOTDB-2892] add PermissionInfoDataSet and test

Posted by GitBox <gi...@apache.org>.
RYH61 commented on code in PR #5492:
URL: https://github.com/apache/iotdb/pull/5492#discussion_r851037731


##########
confignode/src/main/java/org/apache/iotdb/confignode/manager/Manager.java:
##########
@@ -132,4 +132,12 @@ public interface Manager {
    * @return
    */
   TSStatus operatePermission(PhysicalPlan physicalPlan);
+
+  /**
+   * query Permission
+   *
+   * @param physicalPlan
+   * @return
+   */
+  DataSet queryPermission(PhysicalPlan physicalPlan);

Review Comment:
   I have added explanation



-- 
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.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

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


[GitHub] [iotdb] jt2594838 commented on a diff in pull request #5492: [IOTDB-2892] add PermissionInfoDataSet and test

Posted by GitBox <gi...@apache.org>.
jt2594838 commented on code in PR #5492:
URL: https://github.com/apache/iotdb/pull/5492#discussion_r851024928


##########
confignode/src/main/java/org/apache/iotdb/confignode/physical/sys/AuthorPlan.java:
##########
@@ -228,6 +228,53 @@ private int getPlanTypeOrdinal(PhysicalPlanType physicalPlanType) {
     return type;
   }
 
+  /**
+   * A mapping between AuthorType and PhysicalPlanType
+   *
+   * @param i
+   * @return
+   */
+  public static PhysicalPlanType convert(int i) {
+    switch (i) {
+      case 0:
+        return PhysicalPlanType.CREATE_USER;
+      case 1:
+        return PhysicalPlanType.CREATE_ROLE;
+      case 2:
+        return PhysicalPlanType.DROP_USER;
+      case 3:
+        return PhysicalPlanType.DROP_ROLE;
+      case 4:
+        return PhysicalPlanType.GRANT_ROLE;
+      case 5:
+        return PhysicalPlanType.GRANT_USER;
+      case 6:
+        return PhysicalPlanType.GRANT_ROLE_TO_USER;
+      case 7:
+        return PhysicalPlanType.REVOKE_USER;
+      case 8:
+        return PhysicalPlanType.REVOKE_ROLE;
+      case 9:
+        return PhysicalPlanType.REVOKE_ROLE_FROM_USER;
+      case 10:
+        return PhysicalPlanType.UPDATE_USER;
+      case 11:
+        return PhysicalPlanType.LIST_USER;
+      case 12:
+        return PhysicalPlanType.LIST_ROLE;
+      case 13:
+        return PhysicalPlanType.LIST_USER_PRIVILEGE;
+      case 14:
+        return PhysicalPlanType.LIST_ROLE_PRIVILEGE;
+      case 15:
+        return PhysicalPlanType.LIST_USER_ROLES;
+      case 16:
+        return PhysicalPlanType.LIST_ROLE_USERS;
+      default:
+        return null;
+    }
+  }
+

Review Comment:
   I see, but you may simplify it with PhysicalPlanType.values()[i + AUTHOR_OPERATOR_OFFSET].



-- 
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.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

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


[GitHub] [iotdb] RYH61 commented on a diff in pull request #5492: [IOTDB-2892] add PermissionInfoDataSet and test

Posted by GitBox <gi...@apache.org>.
RYH61 commented on code in PR #5492:
URL: https://github.com/apache/iotdb/pull/5492#discussion_r851069313


##########
thrift-confignode/src/main/thrift/confignode.thrift:
##########
@@ -117,6 +117,11 @@ struct TAuthorizerReq {
   7: required string nodeName
 }
 
+struct TAuthorizerResp {
+    1: required common.TSStatus status
+    2: required map<string, list<string>> authorizerInfo
+}
+

Review Comment:
   But currently everyone is using a separate structure



-- 
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.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

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


[GitHub] [iotdb] RYH61 commented on a diff in pull request #5492: [IOTDB-2892] add PermissionInfoDataSet and test

Posted by GitBox <gi...@apache.org>.
RYH61 commented on code in PR #5492:
URL: https://github.com/apache/iotdb/pull/5492#discussion_r851058917


##########
confignode/src/main/java/org/apache/iotdb/confignode/manager/Manager.java:
##########
@@ -128,16 +128,16 @@ public interface Manager {
   /**
    * operate permission
    *
-   * @param physicalPlan
-   * @return
+   * @param physicalPlan AuthorPlan
+   * @return PermissionInfoDataSet

Review Comment:
   ok, i have modified it



-- 
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.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

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


[GitHub] [iotdb] RYH61 commented on a diff in pull request #5492: [IOTDB-2892] add PermissionInfoDataSet and test

Posted by GitBox <gi...@apache.org>.
RYH61 commented on code in PR #5492:
URL: https://github.com/apache/iotdb/pull/5492#discussion_r850278041


##########
confignode/src/main/java/org/apache/iotdb/confignode/manager/ConfigManager.java:
##########
@@ -292,4 +293,12 @@ public TSStatus operatePermission(PhysicalPlan physicalPlan) {
     }
     return ERROR_TSSTATUS;
   }
+
+  @Override
+  public DataSet queryPermission(PhysicalPlan physicalPlan) {
+    if (physicalPlan instanceof AuthorPlan) {
+      return permissionManager.queryPermission((AuthorPlan) physicalPlan);
+    }
+    return new PermissionInfoDataSet();

Review Comment:
   I modified this part of the code



-- 
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.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

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


[GitHub] [iotdb] RYH61 commented on a diff in pull request #5492: [IOTDB-2892] add PermissionInfoDataSet and test

Posted by GitBox <gi...@apache.org>.
RYH61 commented on code in PR #5492:
URL: https://github.com/apache/iotdb/pull/5492#discussion_r850207656


##########
confignode/src/main/java/org/apache/iotdb/confignode/conf/ConfigNodeConf.java:
##########
@@ -97,6 +97,8 @@ public class ConfigNodeConf {
   /** The number of DataRegions of each StorageGroup */
   private int dataRegionCount = 1;
 
+  private String adminName = "root";

Review Comment:
   ok



##########
confignode/src/main/java/org/apache/iotdb/confignode/service/thrift/server/ConfigNodeRPCServerProcessor.java:
##########
@@ -203,6 +205,29 @@ public TSStatus operatePermission(TAuthorizerReq req) throws TException {
     return configManager.operatePermission(plan);
   }
 
+  @Override
+  public TAuthorizerResp queryPermission(TAuthorizerReq req) throws TException {
+    if (req.getAuthorType() < 0 || req.getAuthorType() >= PhysicalPlanType.values().length) {
+      throw new IndexOutOfBoundsException("Invalid ordinal");

Review Comment:
   ok



-- 
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.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

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


[GitHub] [iotdb] RYH61 commented on a diff in pull request #5492: [IOTDB-2892] add PermissionInfoDataSet and test

Posted by GitBox <gi...@apache.org>.
RYH61 commented on code in PR #5492:
URL: https://github.com/apache/iotdb/pull/5492#discussion_r850270887


##########
confignode/src/main/java/org/apache/iotdb/confignode/manager/Manager.java:
##########
@@ -132,4 +132,12 @@ public interface Manager {
    * @return
    */
   TSStatus operatePermission(PhysicalPlan physicalPlan);
+
+  /**
+   * query Permission
+   *
+   * @param physicalPlan
+   * @return
+   */
+  DataSet queryPermission(PhysicalPlan physicalPlan);

Review Comment:
   The final return type is Permission Info Data Set



-- 
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.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

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


[GitHub] [iotdb] RYH61 commented on a diff in pull request #5492: [IOTDB-2892] add PermissionInfoDataSet and test

Posted by GitBox <gi...@apache.org>.
RYH61 commented on code in PR #5492:
URL: https://github.com/apache/iotdb/pull/5492#discussion_r851120562


##########
thrift-confignode/src/main/thrift/confignode.thrift:
##########
@@ -117,6 +117,11 @@ struct TAuthorizerReq {
   7: required string nodeName
 }
 
+struct TAuthorizerResp {
+    1: required common.TSStatus status
+    2: required map<string, list<string>> authorizerInfo
+}
+

Review Comment:
   I asked here, it doesn't matter if it is not unified, because after finally reaching the Coordinator, when the Coordinator returns to the client, it will be converted into a unified structure



-- 
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.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

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


[GitHub] [iotdb] RYH61 commented on a diff in pull request #5492: [IOTDB-2892] add PermissionInfoDataSet and test

Posted by GitBox <gi...@apache.org>.
RYH61 commented on code in PR #5492:
URL: https://github.com/apache/iotdb/pull/5492#discussion_r850976266


##########
server/src/main/java/org/apache/iotdb/db/mpp/execution/config/AuthorizerConfigTask.java:
##########
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.db.mpp.execution.config;
+
+import org.apache.iotdb.common.rpc.thrift.TSStatus;
+import org.apache.iotdb.commons.exception.BadNodeUrlException;
+import org.apache.iotdb.confignode.rpc.thrift.TAuthorizerReq;
+import org.apache.iotdb.db.auth.AuthException;
+import org.apache.iotdb.db.client.ConfigNodeClient;
+import org.apache.iotdb.db.mpp.sql.planner.plan.node.metedata.write.AuthorNode;
+import org.apache.iotdb.db.mpp.sql.statement.sys.AuthorStatement;
+import org.apache.iotdb.rpc.IoTDBConnectionException;
+import org.apache.iotdb.rpc.StatementExecutionException;
+import org.apache.iotdb.rpc.TSStatusCode;
+
+import com.google.common.util.concurrent.ListenableFuture;
+import com.google.common.util.concurrent.SettableFuture;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Locale;
+
+public class AuthorizerConfigTask implements IConfigTask {
+
+  private static final Logger LOGGER = LoggerFactory.getLogger(AuthorizerConfigTask.class);
+
+  private AuthorStatement authorStatement;
+
+  public AuthorizerConfigTask(AuthorStatement authorStatement) {
+    this.authorStatement = authorStatement;
+  }
+
+  @Override
+  public ListenableFuture<Void> execute() {
+    SettableFuture<Void> future = SettableFuture.create();
+    ConfigNodeClient configNodeClient = null;
+    try {
+      // Construct request using statement
+      TAuthorizerReq req =
+          new TAuthorizerReq(
+              authorStatement.getAuthorType().ordinal(),
+              authorStatement.getUserName() == null ? "" : authorStatement.getUserName(),
+              authorStatement.getRoleName() == null ? "" : authorStatement.getRoleName(),
+              authorStatement.getPassWord() == null ? "" : authorStatement.getPassWord(),
+              authorStatement.getNewPassword() == null ? "" : authorStatement.getNewPassword(),
+              AuthorNode.strToPermissions(authorStatement.getPrivilegeList()),
+              authorStatement.getNodeName() == null
+                  ? ""
+                  : authorStatement.getNodeName().getFullPath());
+      configNodeClient = new ConfigNodeClient();
+      // Send request to some API server
+      TSStatus tsStatus = configNodeClient.operatePermission(req);

Review Comment:
   TSStatus can be used to carry additional information



-- 
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.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

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


[GitHub] [iotdb] RYH61 commented on a diff in pull request #5492: [IOTDB-2892] add PermissionInfoDataSet and test

Posted by GitBox <gi...@apache.org>.
RYH61 commented on code in PR #5492:
URL: https://github.com/apache/iotdb/pull/5492#discussion_r850975691


##########
thrift-confignode/src/main/thrift/confignode.thrift:
##########
@@ -117,6 +117,11 @@ struct TAuthorizerReq {
   7: required string nodeName
 }
 
+struct TAuthorizerResp {
+    1: required common.TSStatus status
+    2: required map<string, list<string>> authorizerInfo
+}
+

Review Comment:
   Here I have used PermissionInfoDataSet to store the found information



-- 
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.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

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


[GitHub] [iotdb] RYH61 commented on a diff in pull request #5492: [IOTDB-2892] add PermissionInfoDataSet and test

Posted by GitBox <gi...@apache.org>.
RYH61 commented on code in PR #5492:
URL: https://github.com/apache/iotdb/pull/5492#discussion_r851112096


##########
thrift-confignode/src/main/thrift/confignode.thrift:
##########
@@ -117,6 +117,11 @@ struct TAuthorizerReq {
   7: required string nodeName
 }
 
+struct TAuthorizerResp {
+    1: required common.TSStatus status
+    2: required map<string, list<string>> authorizerInfo
+}
+

Review Comment:
   Here is the result of the query returned from confignode to datanode, this structure should be ok



-- 
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.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

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


[GitHub] [iotdb] RYH61 commented on a diff in pull request #5492: [IOTDB-2892] add PermissionInfoDataSet and test

Posted by GitBox <gi...@apache.org>.
RYH61 commented on code in PR #5492:
URL: https://github.com/apache/iotdb/pull/5492#discussion_r851023872


##########
confignode/src/main/java/org/apache/iotdb/confignode/physical/sys/AuthorPlan.java:
##########
@@ -228,6 +228,53 @@ private int getPlanTypeOrdinal(PhysicalPlanType physicalPlanType) {
     return type;
   }
 
+  /**
+   * A mapping between AuthorType and PhysicalPlanType
+   *
+   * @param i
+   * @return
+   */
+  public static PhysicalPlanType convert(int i) {
+    switch (i) {
+      case 0:
+        return PhysicalPlanType.CREATE_USER;
+      case 1:
+        return PhysicalPlanType.CREATE_ROLE;
+      case 2:
+        return PhysicalPlanType.DROP_USER;
+      case 3:
+        return PhysicalPlanType.DROP_ROLE;
+      case 4:
+        return PhysicalPlanType.GRANT_ROLE;
+      case 5:
+        return PhysicalPlanType.GRANT_USER;
+      case 6:
+        return PhysicalPlanType.GRANT_ROLE_TO_USER;
+      case 7:
+        return PhysicalPlanType.REVOKE_USER;
+      case 8:
+        return PhysicalPlanType.REVOKE_ROLE;
+      case 9:
+        return PhysicalPlanType.REVOKE_ROLE_FROM_USER;
+      case 10:
+        return PhysicalPlanType.UPDATE_USER;
+      case 11:
+        return PhysicalPlanType.LIST_USER;
+      case 12:
+        return PhysicalPlanType.LIST_ROLE;
+      case 13:
+        return PhysicalPlanType.LIST_USER_PRIVILEGE;
+      case 14:
+        return PhysicalPlanType.LIST_ROLE_PRIVILEGE;
+      case 15:
+        return PhysicalPlanType.LIST_USER_ROLES;
+      case 16:
+        return PhysicalPlanType.LIST_ROLE_USERS;
+      default:
+        return null;
+    }
+  }
+

Review Comment:
   Because the type index in Physical Plan Type is not consistent with the AuthorType type index passed from datanode, a conversion is required instead of using PhysicalPlanType.values()[i]



-- 
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.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

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


[GitHub] [iotdb] qiaojialin commented on a diff in pull request #5492: [IOTDB-2892] add PermissionInfoDataSet and test

Posted by GitBox <gi...@apache.org>.
qiaojialin commented on code in PR #5492:
URL: https://github.com/apache/iotdb/pull/5492#discussion_r850173503


##########
confignode/src/main/java/org/apache/iotdb/confignode/conf/ConfigNodeConstant.java:
##########
@@ -43,6 +43,10 @@ public class ConfigNodeConstant {
   public static final String CONF_DIR = "conf";
   public static final String CONSENSUS_FOLDER = "consensus";
 
+  public static final String COLUMN_ROLE = "role";

Review Comment:
   We have these in IoTDBConstant in node-commons module



##########
confignode/src/main/java/org/apache/iotdb/confignode/manager/ConfigManager.java:
##########
@@ -292,4 +292,12 @@ public TSStatus operatePermission(PhysicalPlan physicalPlan) {
     }
     return ERROR_TSSTATUS;
   }
+
+  @Override
+  public DataSet queryPermission(PhysicalPlan physicalPlan) {
+    if (physicalPlan instanceof AuthorPlan) {
+      return permissionManager.queryPermission((AuthorPlan) physicalPlan);
+    }
+    return new DataPartitionDataSet();

Review Comment:
   PermissionInfoDataSet?



##########
confignode/src/main/java/org/apache/iotdb/confignode/conf/ConfigNodeConf.java:
##########
@@ -97,6 +97,8 @@ public class ConfigNodeConf {
   /** The number of DataRegions of each StorageGroup */
   private int dataRegionCount = 1;
 
+  private String adminName = "root";

Review Comment:
   We have this in IoTDBConfig, this could be moved to node-commons



##########
confignode/src/main/java/org/apache/iotdb/confignode/service/thrift/server/ConfigNodeRPCServerProcessor.java:
##########
@@ -203,6 +205,29 @@ public TSStatus operatePermission(TAuthorizerReq req) throws TException {
     return configManager.operatePermission(plan);
   }
 
+  @Override
+  public TAuthorizerResp queryPermission(TAuthorizerReq req) throws TException {
+    if (req.getAuthorType() < 0 || req.getAuthorType() >= PhysicalPlanType.values().length) {
+      throw new IndexOutOfBoundsException("Invalid ordinal");

Review Comment:
   ```suggestion
         throw new IndexOutOfBoundsException("Invalid Author Type ordinal");
   ```



##########
confignode/src/test/java/org/apache/iotdb/confignode/service/thrift/server/ConfigNodeRPCServerProcessorTest.java:
##########
@@ -489,4 +496,353 @@ public void getAndCreateDataPartitionTest() throws TException {
         timePartitionSlotNum,
         dataPartitionResp.getDataPartitionMap());
   }
+
+  @Test
+  public void permissionTest() throws TException {
+    TSStatus status;
+
+    // register DataNodes
+    TDataNodeRegisterReq registerReq0 = new TDataNodeRegisterReq(new EndPoint("0.0.0.0", 6667));
+    TDataNodeRegisterReq registerReq1 = new TDataNodeRegisterReq(new EndPoint("0.0.0.0", 6668));
+    TDataNodeRegisterReq registerReq2 = new TDataNodeRegisterReq(new EndPoint("0.0.0.0", 6669));
+    status = processor.registerDataNode(registerReq0).getStatus();
+    Assert.assertEquals(TSStatusCode.SUCCESS_STATUS.getStatusCode(), status.getCode());
+    status = processor.registerDataNode(registerReq1).getStatus();
+    Assert.assertEquals(TSStatusCode.SUCCESS_STATUS.getStatusCode(), status.getCode());
+    status = processor.registerDataNode(registerReq2).getStatus();
+    Assert.assertEquals(TSStatusCode.SUCCESS_STATUS.getStatusCode(), status.getCode());

Review Comment:
   There is no need to register datanodes



-- 
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.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

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


[GitHub] [iotdb] jt2594838 commented on a diff in pull request #5492: [IOTDB-2892] add PermissionInfoDataSet and test

Posted by GitBox <gi...@apache.org>.
jt2594838 commented on code in PR #5492:
URL: https://github.com/apache/iotdb/pull/5492#discussion_r851022131


##########
thrift-confignode/src/main/thrift/confignode.thrift:
##########
@@ -117,6 +117,11 @@ struct TAuthorizerReq {
   7: required string nodeName
 }
 
+struct TAuthorizerResp {
+    1: required common.TSStatus status
+    2: required map<string, list<string>> authorizerInfo
+}
+

Review Comment:
   I see, but since the permission queries are shown to clients in a very similar way as data queries, I doubt is it necessary to use a separate structure.



-- 
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.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

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


[GitHub] [iotdb] jt2594838 commented on a diff in pull request #5492: [IOTDB-2892] add PermissionInfoDataSet and test

Posted by GitBox <gi...@apache.org>.
jt2594838 commented on code in PR #5492:
URL: https://github.com/apache/iotdb/pull/5492#discussion_r851015054


##########
confignode/src/main/java/org/apache/iotdb/confignode/consensus/response/PermissionInfoDataSet.java:
##########
@@ -19,8 +19,37 @@
 
 package org.apache.iotdb.confignode.consensus.response;
 
+import org.apache.iotdb.common.rpc.thrift.TSStatus;
 import org.apache.iotdb.consensus.common.DataSet;
 
+import java.util.List;
+import java.util.Map;
+
 public class PermissionInfoDataSet implements DataSet {

Review Comment:
   Where is it used as a DataSet?



-- 
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.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

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


[GitHub] [iotdb] jt2594838 commented on a diff in pull request #5492: [IOTDB-2892] add PermissionInfoDataSet and test

Posted by GitBox <gi...@apache.org>.
jt2594838 commented on code in PR #5492:
URL: https://github.com/apache/iotdb/pull/5492#discussion_r851056609


##########
confignode/src/main/java/org/apache/iotdb/confignode/manager/Manager.java:
##########
@@ -128,16 +128,16 @@ public interface Manager {
   /**
    * operate permission
    *
-   * @param physicalPlan
-   * @return
+   * @param physicalPlan AuthorPlan
+   * @return PermissionInfoDataSet

Review Comment:
   It seems incorrect.



-- 
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.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

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


[GitHub] [iotdb] RYH61 commented on a diff in pull request #5492: [IOTDB-2892] add PermissionInfoDataSet and test

Posted by GitBox <gi...@apache.org>.
RYH61 commented on code in PR #5492:
URL: https://github.com/apache/iotdb/pull/5492#discussion_r851036351


##########
confignode/src/main/java/org/apache/iotdb/confignode/manager/Manager.java:
##########
@@ -132,4 +132,12 @@ public interface Manager {
    * @return
    */
   TSStatus operatePermission(PhysicalPlan physicalPlan);
+
+  /**
+   * query Permission
+   *
+   * @param physicalPlan
+   * @return
+   */
+  DataSet queryPermission(PhysicalPlan physicalPlan);

Review Comment:
   In the process of subsequent reading, DataSet is used



-- 
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.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

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


[GitHub] [iotdb] wangchao316 commented on a diff in pull request #5492: [IOTDB-2892] add PermissionInfoDataSet and test

Posted by GitBox <gi...@apache.org>.
wangchao316 commented on code in PR #5492:
URL: https://github.com/apache/iotdb/pull/5492#discussion_r850174816


##########
confignode/src/test/java/org/apache/iotdb/confignode/auth/AuthorTest.java:
##########
@@ -41,4 +52,21 @@ public void tearDown() throws Exception {
   }
 
   // TODO: ADD TEST
+  @Test
+  public void test() {
+    ConfigIService.Client clients;
+    try {
+      TTransport transport = RpcTransportFactory.INSTANCE.getTransport("0.0.0.0", 22277, 2000);
+      transport.open();
+      clients = new ConfigIService.Client(new TBinaryProtocol(transport));
+      TAuthorizerReq tAuthorizerReq;
+      tAuthorizerReq = new TAuthorizerReq(1, "renrne", "", "renren", "", new HashSet<>(), "");
+      TSStatus tsStatus = clients.operatePermission(tAuthorizerReq);
+      System.out.println(tsStatus.getCode());
+    } catch (TTransportException e) {
+      e.printStackTrace();

Review Comment:
   add  Assert.fail();



##########
confignode/src/test/java/org/apache/iotdb/confignode/auth/AuthorTest.java:
##########
@@ -41,4 +52,21 @@ public void tearDown() throws Exception {
   }
 
   // TODO: ADD TEST
+  @Test
+  public void test() {
+    ConfigIService.Client clients;
+    try {
+      TTransport transport = RpcTransportFactory.INSTANCE.getTransport("0.0.0.0", 22277, 2000);

Review Comment:
   rename testCreateUser ....



##########
server/src/main/java/org/apache/iotdb/db/mpp/execution/config/AuthorizerConfigTask.java:
##########
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.db.mpp.execution.config;
+
+import org.apache.iotdb.common.rpc.thrift.TSStatus;
+import org.apache.iotdb.commons.exception.BadNodeUrlException;
+import org.apache.iotdb.confignode.rpc.thrift.TAuthorizerReq;
+import org.apache.iotdb.db.auth.AuthException;
+import org.apache.iotdb.db.client.ConfigNodeClient;
+import org.apache.iotdb.db.mpp.sql.planner.plan.node.metedata.write.AuthorNode;
+import org.apache.iotdb.db.mpp.sql.statement.sys.AuthorStatement;
+import org.apache.iotdb.rpc.IoTDBConnectionException;
+import org.apache.iotdb.rpc.StatementExecutionException;
+import org.apache.iotdb.rpc.TSStatusCode;
+
+import com.google.common.util.concurrent.ListenableFuture;
+import com.google.common.util.concurrent.SettableFuture;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Locale;
+
+public class AuthorizerConfigTask implements IConfigTask {
+
+  private static final Logger LOGGER = LoggerFactory.getLogger(AuthorizerConfigTask.class);
+
+  private AuthorStatement authorStatement;
+
+  public AuthorizerConfigTask(AuthorStatement authorStatement) {
+    this.authorStatement = authorStatement;
+  }
+
+  @Override
+  public ListenableFuture<Void> execute() {
+    SettableFuture<Void> future = SettableFuture.create();
+    ConfigNodeClient configNodeClient = null;
+    try {
+      // Construct request using statement
+      TAuthorizerReq req =
+          new TAuthorizerReq(
+              authorStatement.getAuthorType().ordinal(),
+              authorStatement.getUserName() == null ? "" : authorStatement.getUserName(),
+              authorStatement.getRoleName() == null ? "" : authorStatement.getRoleName(),
+              authorStatement.getPassWord() == null ? "" : authorStatement.getPassWord(),
+              authorStatement.getNewPassword() == null ? "" : authorStatement.getNewPassword(),
+              AuthorNode.strToPermissions(authorStatement.getPrivilegeList()),
+              authorStatement.getNodeName() == null
+                  ? ""
+                  : authorStatement.getNodeName().getFullPath());
+      configNodeClient = new ConfigNodeClient();
+      // Send request to some API server
+      TSStatus tsStatus = configNodeClient.operatePermission(req);
+      // Get response or throw exception
+      if (TSStatusCode.SUCCESS_STATUS.getStatusCode() != tsStatus.getCode()) {
+        LOGGER.error(
+            "Failed to execute {} in config node, status is {}.",
+            authorStatement.getAuthorType().toString().toLowerCase(Locale.ROOT),
+            tsStatus);
+        future.setException(new StatementExecutionException(tsStatus));
+      } else {
+        future.set(null);
+      }
+    } catch (IoTDBConnectionException | BadNodeUrlException e) {
+      LOGGER.error("Failed to connect to config node.");
+      future.setException(e);
+    } catch (AuthException e) {
+      LOGGER.error("No such privilege." + authorStatement.getAuthorType());

Review Comment:
   use {}



-- 
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.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

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


[GitHub] [iotdb] jt2594838 commented on a diff in pull request #5492: [IOTDB-2892] add PermissionInfoDataSet and test

Posted by GitBox <gi...@apache.org>.
jt2594838 commented on code in PR #5492:
URL: https://github.com/apache/iotdb/pull/5492#discussion_r851024928


##########
confignode/src/main/java/org/apache/iotdb/confignode/physical/sys/AuthorPlan.java:
##########
@@ -228,6 +228,53 @@ private int getPlanTypeOrdinal(PhysicalPlanType physicalPlanType) {
     return type;
   }
 
+  /**
+   * A mapping between AuthorType and PhysicalPlanType
+   *
+   * @param i
+   * @return
+   */
+  public static PhysicalPlanType convert(int i) {
+    switch (i) {
+      case 0:
+        return PhysicalPlanType.CREATE_USER;
+      case 1:
+        return PhysicalPlanType.CREATE_ROLE;
+      case 2:
+        return PhysicalPlanType.DROP_USER;
+      case 3:
+        return PhysicalPlanType.DROP_ROLE;
+      case 4:
+        return PhysicalPlanType.GRANT_ROLE;
+      case 5:
+        return PhysicalPlanType.GRANT_USER;
+      case 6:
+        return PhysicalPlanType.GRANT_ROLE_TO_USER;
+      case 7:
+        return PhysicalPlanType.REVOKE_USER;
+      case 8:
+        return PhysicalPlanType.REVOKE_ROLE;
+      case 9:
+        return PhysicalPlanType.REVOKE_ROLE_FROM_USER;
+      case 10:
+        return PhysicalPlanType.UPDATE_USER;
+      case 11:
+        return PhysicalPlanType.LIST_USER;
+      case 12:
+        return PhysicalPlanType.LIST_ROLE;
+      case 13:
+        return PhysicalPlanType.LIST_USER_PRIVILEGE;
+      case 14:
+        return PhysicalPlanType.LIST_ROLE_PRIVILEGE;
+      case 15:
+        return PhysicalPlanType.LIST_USER_ROLES;
+      case 16:
+        return PhysicalPlanType.LIST_ROLE_USERS;
+      default:
+        return null;
+    }
+  }
+

Review Comment:
   I see, but you may simplify it with PhysicalPlanType.values()[i + AUTHOR_OPERATOR_OFFSET].
   
   Well, never mind. It also has some drawbacks, maybe the types need a larger refactor.



-- 
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.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

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