You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ro...@apache.org on 2021/11/04 08:20:33 UTC

[iotdb] 02/02: fix issue-4308

This is an automated email from the ASF dual-hosted git repository.

rong pushed a commit to branch issue-4308-0.12
in repository https://gitbox.apache.org/repos/asf/iotdb.git

commit f4ca8654b3a764dbd3d7a634147dc50d9c3ab409
Author: Steve Yurong Su <ro...@apache.org>
AuthorDate: Thu Nov 4 16:18:34 2021 +0800

    fix issue-4308
---
 .../apache/iotdb/db/qp/physical/PhysicalPlan.java    |  7 +++++++
 .../apache/iotdb/db/qp/physical/crud/UDTFPlan.java   | 20 ++++++++++++++++++++
 .../org/apache/iotdb/db/service/TSServiceImpl.java   |  2 +-
 3 files changed, 28 insertions(+), 1 deletion(-)

diff --git a/server/src/main/java/org/apache/iotdb/db/qp/physical/PhysicalPlan.java b/server/src/main/java/org/apache/iotdb/db/qp/physical/PhysicalPlan.java
index 2ce5b7b..f87cc05 100644
--- a/server/src/main/java/org/apache/iotdb/db/qp/physical/PhysicalPlan.java
+++ b/server/src/main/java/org/apache/iotdb/db/qp/physical/PhysicalPlan.java
@@ -217,6 +217,13 @@ public abstract class PhysicalPlan {
     this.loginUserName = loginUserName;
   }
 
+  /**
+   * Used to check whether a user has operation permissions to execute the plan under these paths.
+   */
+  public List<PartialPath> getAuthPaths() {
+    return getPaths();
+  }
+
   public static class Factory {
 
     private Factory() {
diff --git a/server/src/main/java/org/apache/iotdb/db/qp/physical/crud/UDTFPlan.java b/server/src/main/java/org/apache/iotdb/db/qp/physical/crud/UDTFPlan.java
index 5192bbc..b50c4a7 100644
--- a/server/src/main/java/org/apache/iotdb/db/qp/physical/crud/UDTFPlan.java
+++ b/server/src/main/java/org/apache/iotdb/db/qp/physical/crud/UDTFPlan.java
@@ -20,6 +20,7 @@
 package org.apache.iotdb.db.qp.physical.crud;
 
 import org.apache.iotdb.db.exception.query.QueryProcessException;
+import org.apache.iotdb.db.metadata.PartialPath;
 import org.apache.iotdb.db.qp.logical.Operator;
 import org.apache.iotdb.db.query.udf.core.context.UDFContext;
 import org.apache.iotdb.db.query.udf.core.executor.UDTFExecutor;
@@ -30,8 +31,10 @@ import java.time.ZoneId;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 public class UDTFPlan extends RawDataQueryPlan implements UDFPlan {
 
@@ -138,4 +141,21 @@ public class UDTFPlan extends RawDataQueryPlan implements UDFPlan {
     }
     return columnForReader;
   }
+
+  @Override
+  public List<PartialPath> getAuthPaths() {
+    Set<PartialPath> authPathsSet = new HashSet<>();
+
+    for (PartialPath rawQueryPath : getPaths()) {
+      if (rawQueryPath != null) {
+        authPathsSet.add(rawQueryPath);
+      }
+    }
+
+    for (UDTFExecutor executor : columnName2Executor.values()) {
+      authPathsSet.addAll(executor.getContext().getPaths());
+    }
+
+    return new ArrayList<>(authPathsSet);
+  }
 }
diff --git a/server/src/main/java/org/apache/iotdb/db/service/TSServiceImpl.java b/server/src/main/java/org/apache/iotdb/db/service/TSServiceImpl.java
index 1b370de..b36a5ee 100644
--- a/server/src/main/java/org/apache/iotdb/db/service/TSServiceImpl.java
+++ b/server/src/main/java/org/apache/iotdb/db/service/TSServiceImpl.java
@@ -830,7 +830,7 @@ public class TSServiceImpl implements TSIService.Iface {
     List<String> columnsTypes = new ArrayList<>();
 
     // check permissions
-    if (!checkAuthorization(physicalPlan.getPaths(), physicalPlan, username)) {
+    if (!checkAuthorization(physicalPlan.getAuthPaths(), physicalPlan, username)) {
       return RpcUtils.getTSExecuteStatementResp(
           RpcUtils.getStatus(
               TSStatusCode.NO_PERMISSION_ERROR,