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 2022/03/04 07:21:35 UTC
[iotdb] branch master updated: [IOTDB-2520] list user privilege root returns empty (#5167)
This is an automated email from the ASF dual-hosted git repository.
rong pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/master by this push:
new edd4d5c [IOTDB-2520] list user privilege root returns empty (#5167)
edd4d5c is described below
commit edd4d5cef93463851334f4606ac4bb9b64536fac
Author: 任宇华 <79...@users.noreply.github.com>
AuthorDate: Fri Mar 4 15:20:58 2022 +0800
[IOTDB-2520] list user privilege root returns empty (#5167)
Co-authored-by: renyuhua <ry...@163.com>
---
.../apache/iotdb/db/qp/executor/PlanExecutor.java | 56 ++++++++++++++--------
.../java/org/apache/iotdb/db/qp/PlannerTest.java | 22 +++++++++
2 files changed, 58 insertions(+), 20 deletions(-)
diff --git a/server/src/main/java/org/apache/iotdb/db/qp/executor/PlanExecutor.java b/server/src/main/java/org/apache/iotdb/db/qp/executor/PlanExecutor.java
index ea825ca..3ed5854 100644
--- a/server/src/main/java/org/apache/iotdb/db/qp/executor/PlanExecutor.java
+++ b/server/src/main/java/org/apache/iotdb/db/qp/executor/PlanExecutor.java
@@ -23,6 +23,7 @@ import org.apache.iotdb.db.auth.AuthorityChecker;
import org.apache.iotdb.db.auth.authorizer.BasicAuthorizer;
import org.apache.iotdb.db.auth.authorizer.IAuthorizer;
import org.apache.iotdb.db.auth.entity.PathPrivilege;
+import org.apache.iotdb.db.auth.entity.PrivilegeType;
import org.apache.iotdb.db.auth.entity.Role;
import org.apache.iotdb.db.auth.entity.User;
import org.apache.iotdb.db.concurrent.IoTDBThreadPoolFactory;
@@ -2182,34 +2183,30 @@ public class PlanExecutor implements IPlanExecutor {
}
List<PartialPath> headerList = new ArrayList<>();
List<TSDataType> typeList = new ArrayList<>();
- headerList.add(new PartialPath(COLUMN_ROLE, false));
- headerList.add(new PartialPath(COLUMN_PRIVILEGE, false));
- typeList.add(TSDataType.TEXT);
- typeList.add(TSDataType.TEXT);
- ListDataSet dataSet = new ListDataSet(headerList, typeList);
int index = 0;
- for (PathPrivilege pathPrivilege : user.getPrivilegeList()) {
- if (path == null || AuthUtils.pathBelongsTo(path.getFullPath(), pathPrivilege.getPath())) {
+ if (IoTDBDescriptor.getInstance().getConfig().getAdminName().equals(userName)) {
+ headerList.add(new PartialPath(COLUMN_PRIVILEGE, false));
+ typeList.add(TSDataType.TEXT);
+ ListDataSet dataSet = new ListDataSet(headerList, typeList);
+ for (PrivilegeType privilegeType : PrivilegeType.values()) {
RowRecord record = new RowRecord(index++);
- Field roleF = new Field(TSDataType.TEXT);
- roleF.setBinaryV(new Binary(""));
- record.addField(roleF);
Field privilegeF = new Field(TSDataType.TEXT);
- privilegeF.setBinaryV(new Binary(pathPrivilege.toString()));
+ privilegeF.setBinaryV(new Binary(privilegeType.toString()));
record.addField(privilegeF);
dataSet.putRecord(record);
}
- }
- for (String roleN : user.getRoleList()) {
- Role role = authorizer.getRole(roleN);
- if (role == null) {
- continue;
- }
- for (PathPrivilege pathPrivilege : role.getPrivilegeList()) {
+ return dataSet;
+ } else {
+ headerList.add(new PartialPath(COLUMN_ROLE, false));
+ headerList.add(new PartialPath(COLUMN_PRIVILEGE, false));
+ typeList.add(TSDataType.TEXT);
+ typeList.add(TSDataType.TEXT);
+ ListDataSet dataSet = new ListDataSet(headerList, typeList);
+ for (PathPrivilege pathPrivilege : user.getPrivilegeList()) {
if (path == null || AuthUtils.pathBelongsTo(path.getFullPath(), pathPrivilege.getPath())) {
RowRecord record = new RowRecord(index++);
Field roleF = new Field(TSDataType.TEXT);
- roleF.setBinaryV(new Binary(roleN));
+ roleF.setBinaryV(new Binary(""));
record.addField(roleF);
Field privilegeF = new Field(TSDataType.TEXT);
privilegeF.setBinaryV(new Binary(pathPrivilege.toString()));
@@ -2217,8 +2214,27 @@ public class PlanExecutor implements IPlanExecutor {
dataSet.putRecord(record);
}
}
+ for (String roleN : user.getRoleList()) {
+ Role role = authorizer.getRole(roleN);
+ if (role == null) {
+ continue;
+ }
+ for (PathPrivilege pathPrivilege : role.getPrivilegeList()) {
+ if (path == null
+ || AuthUtils.pathBelongsTo(path.getFullPath(), pathPrivilege.getPath())) {
+ RowRecord record = new RowRecord(index++);
+ Field roleF = new Field(TSDataType.TEXT);
+ roleF.setBinaryV(new Binary(roleN));
+ record.addField(roleF);
+ Field privilegeF = new Field(TSDataType.TEXT);
+ privilegeF.setBinaryV(new Binary(pathPrivilege.toString()));
+ record.addField(privilegeF);
+ dataSet.putRecord(record);
+ }
+ }
+ }
+ return dataSet;
}
- return dataSet;
}
@SuppressWarnings("unused") // for the distributed version
diff --git a/server/src/test/java/org/apache/iotdb/db/qp/PlannerTest.java b/server/src/test/java/org/apache/iotdb/db/qp/PlannerTest.java
index 3100fe1..a5d824d 100644
--- a/server/src/test/java/org/apache/iotdb/db/qp/PlannerTest.java
+++ b/server/src/test/java/org/apache/iotdb/db/qp/PlannerTest.java
@@ -18,12 +18,16 @@
*/
package org.apache.iotdb.db.qp;
+import org.apache.iotdb.db.auth.entity.PrivilegeType;
import org.apache.iotdb.db.conf.IoTDBConstant;
+import org.apache.iotdb.db.exception.StorageEngineException;
import org.apache.iotdb.db.exception.metadata.IllegalPathException;
+import org.apache.iotdb.db.exception.metadata.MetadataException;
import org.apache.iotdb.db.exception.query.QueryProcessException;
import org.apache.iotdb.db.exception.runtime.SQLParserException;
import org.apache.iotdb.db.metadata.MManager;
import org.apache.iotdb.db.metadata.path.PartialPath;
+import org.apache.iotdb.db.qp.executor.PlanExecutor;
import org.apache.iotdb.db.qp.logical.Operator.OperatorType;
import org.apache.iotdb.db.qp.physical.PhysicalPlan;
import org.apache.iotdb.db.qp.physical.crud.InsertRowPlan;
@@ -32,15 +36,18 @@ import org.apache.iotdb.db.utils.EnvironmentUtils;
import org.apache.iotdb.service.rpc.thrift.TSLastDataQueryReq;
import org.apache.iotdb.service.rpc.thrift.TSRawDataQueryReq;
import org.apache.iotdb.tsfile.common.conf.TSFileDescriptor;
+import org.apache.iotdb.tsfile.exception.filter.QueryFilterOptimizationException;
import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+import org.apache.iotdb.tsfile.read.query.dataset.QueryDataSet;
import org.antlr.v4.runtime.misc.ParseCancellationException;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import java.io.IOException;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.Collections;
@@ -273,4 +280,19 @@ public class PlannerTest {
assertEquals(OperatorType.LAST, physicalPlan.getOperatorType());
assertEquals(paths.get(0), physicalPlan.getPaths().get(0).getFullPath());
}
+
+ @Test
+ public void testRootPrivilege()
+ throws QueryProcessException, StorageEngineException, IOException, InterruptedException,
+ QueryFilterOptimizationException, MetadataException {
+ String listRootPrivilegeStatement = "list user privileges root";
+ PhysicalPlan physicalPlan = processor.parseSQLToPhysicalPlan(listRootPrivilegeStatement);
+ PlanExecutor executor = new PlanExecutor();
+ QueryDataSet queryDataSet = executor.processQuery(physicalPlan, null);
+ for (PrivilegeType privilegeType : PrivilegeType.values()) {
+ if (queryDataSet.hasNext()) {
+ assertEquals(String.valueOf(queryDataSet.next().getFields()), "[" + privilegeType + "]");
+ }
+ }
+ }
}