You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ji...@apache.org on 2024/12/06 03:00:18 UTC
(iotdb) branch insertion_authentication created (now ecd205e81bc)
This is an automated email from the ASF dual-hosted git repository.
jiangtian pushed a change to branch insertion_authentication
in repository https://gitbox.apache.org/repos/asf/iotdb.git
at ecd205e81bc temp save
This branch includes the following new commits:
new ecd205e81bc temp save
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
(iotdb) 01/01: temp save
Posted by ji...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
jiangtian pushed a commit to branch insertion_authentication
in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit ecd205e81bcbbd161289ed243cdc16e21d32a747
Author: Tian Jiang <jt...@163.com>
AuthorDate: Thu Dec 5 18:59:27 2024 +0800
temp save
---
.../iotdb/it/env/cluster/env/AbstractEnv.java | 12 ++++
.../iotdb/it/env/remote/env/RemoteServerEnv.java | 10 ++++
.../java/org/apache/iotdb/itbase/env/BaseEnv.java | 2 +
.../relational/it/db/it/IoTDBAuthenticationIT.java | 64 ++++++++++++++++++++++
.../relational/analyzer/StatementAnalyzer.java | 4 ++
5 files changed, 92 insertions(+)
diff --git a/integration-test/src/main/java/org/apache/iotdb/it/env/cluster/env/AbstractEnv.java b/integration-test/src/main/java/org/apache/iotdb/it/env/cluster/env/AbstractEnv.java
index 9881585bfbd..8bc189c0d1b 100644
--- a/integration-test/src/main/java/org/apache/iotdb/it/env/cluster/env/AbstractEnv.java
+++ b/integration-test/src/main/java/org/apache/iotdb/it/env/cluster/env/AbstractEnv.java
@@ -533,6 +533,18 @@ public abstract class AbstractEnv implements BaseEnv {
.build();
}
+ @Override
+ public ITableSession getTableSessionConnection(String userName, String password)
+ throws IoTDBConnectionException {
+ final DataNodeWrapper dataNode =
+ this.dataNodeWrapperList.get(rand.nextInt(this.dataNodeWrapperList.size()));
+ return new TableSessionBuilder()
+ .nodeUrls(Collections.singletonList(dataNode.getIpAndPortString()))
+ .username(userName)
+ .password(password)
+ .build();
+ }
+
@Override
public ITableSession getTableSessionConnectionWithDB(final String database)
throws IoTDBConnectionException {
diff --git a/integration-test/src/main/java/org/apache/iotdb/it/env/remote/env/RemoteServerEnv.java b/integration-test/src/main/java/org/apache/iotdb/it/env/remote/env/RemoteServerEnv.java
index 8fe6aac4fa8..3c125a5a9c7 100644
--- a/integration-test/src/main/java/org/apache/iotdb/it/env/remote/env/RemoteServerEnv.java
+++ b/integration-test/src/main/java/org/apache/iotdb/it/env/remote/env/RemoteServerEnv.java
@@ -304,6 +304,16 @@ public class RemoteServerEnv implements BaseEnv {
.build();
}
+ @Override
+ public ITableSession getTableSessionConnection(String userName, String password)
+ throws IoTDBConnectionException {
+ return new TableSessionBuilder()
+ .nodeUrls(Collections.singletonList(ip_addr + ":" + port))
+ .username(userName)
+ .password(password)
+ .build();
+ }
+
@Override
public ISession getSessionConnection(String userName, String password)
throws IoTDBConnectionException {
diff --git a/integration-test/src/main/java/org/apache/iotdb/itbase/env/BaseEnv.java b/integration-test/src/main/java/org/apache/iotdb/itbase/env/BaseEnv.java
index c0f058d3fc9..1879e8e72ed 100644
--- a/integration-test/src/main/java/org/apache/iotdb/itbase/env/BaseEnv.java
+++ b/integration-test/src/main/java/org/apache/iotdb/itbase/env/BaseEnv.java
@@ -203,6 +203,8 @@ public interface BaseEnv {
ITableSession getTableSessionConnection(List<String> nodeUrls) throws IoTDBConnectionException;
+ ITableSession getTableSessionConnection(String userName, String password) throws IoTDBConnectionException;
+
/**
* Get the index of the first dataNode with a SchemaRegion leader.
*
diff --git a/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBAuthenticationIT.java b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBAuthenticationIT.java
new file mode 100644
index 00000000000..dd534e56b42
--- /dev/null
+++ b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBAuthenticationIT.java
@@ -0,0 +1,64 @@
+/*
+ * Licensed 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.relational.it.db.it;
+
+import java.util.Arrays;
+import java.util.Locale;
+import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.Table;
+import org.apache.iotdb.isession.ITableSession;
+import org.apache.iotdb.it.env.EnvFactory;
+import org.apache.iotdb.rpc.IoTDBConnectionException;
+import org.apache.iotdb.rpc.StatementExecutionException;
+import org.apache.tsfile.enums.TSDataType;
+import org.apache.tsfile.write.record.Tablet;
+import org.apache.tsfile.write.record.Tablet.ColumnCategory;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class IoTDBAuthenticationIT {
+ @BeforeClass
+ public static void setUp() throws Exception {
+ Locale.setDefault(Locale.ENGLISH);
+ EnvFactory.getEnv().initClusterEnvironment();
+ }
+
+ @AfterClass
+ public static void tearDown() throws Exception {
+ EnvFactory.getEnv().cleanClusterEnvironment();
+ }
+
+ @Test
+ public void testInsert() throws IoTDBConnectionException, StatementExecutionException {
+ // insert by root
+ try (ITableSession session = EnvFactory.getEnv().getTableSessionConnection()) {
+ session.executeNonQueryStatement("CREATE DATABASE test");
+ session.executeNonQueryStatement("USE test");
+
+ Tablet tablet = new Tablet("table1",
+ Arrays.asList("id", "attr", "measurement"),
+ Arrays.asList(TSDataType.STRING, TSDataType.STRING, TSDataType.DOUBLE),
+ Arrays.asList(ColumnCategory.ID, ColumnCategory.ATTRIBUTE, ColumnCategory.MEASUREMENT));
+ tablet.addTimestamp(0, 0);
+ tablet.addValue(0, 0, "id1");
+ tablet.addValue(0, 1, "attr1");
+ tablet.addValue(0, 0, 0.1);
+
+ session.insert(tablet);
+
+ session.executeNonQueryStatement("INSERT INTO table1 (time, id, attr, measurement) VALUES (1, 'id2', 'attr2', 0.2)");
+ }
+ }
+}
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/analyzer/StatementAnalyzer.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/analyzer/StatementAnalyzer.java
index fdf9c032742..433f60eb28c 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/analyzer/StatementAnalyzer.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/analyzer/StatementAnalyzer.java
@@ -187,6 +187,7 @@ import static java.util.Locale.ENGLISH;
import static java.util.Objects.requireNonNull;
import static org.apache.iotdb.commons.schema.table.TsTable.TABLE_ALLOWED_PROPERTIES;
import static org.apache.iotdb.commons.schema.table.TsTable.TIME_COLUMN_NAME;
+import static org.apache.iotdb.commons.utils.PathUtils.unQualifyDatabaseName;
import static org.apache.iotdb.db.queryengine.execution.warnings.StandardWarningCode.REDUNDANT_ORDER_BY;
import static org.apache.iotdb.db.queryengine.plan.relational.analyzer.AggregationAnalyzer.verifyOrderByAggregations;
import static org.apache.iotdb.db.queryengine.plan.relational.analyzer.AggregationAnalyzer.verifySourceAggregations;
@@ -532,6 +533,8 @@ public class StatementAnalyzer {
insert.setInnerTreeStatement(innerInsert);
analysis.setScope(insert, ret);
+ accessControl.checkCanInsertIntoTable(sessionContext.getUserName(), new QualifiedObjectName(unQualifyDatabaseName(insert.getDatabase()), insert.getTableName()));
+
return ret;
}
@@ -543,6 +546,7 @@ public class StatementAnalyzer {
final Scope ret = Scope.create();
AnalyzeUtils.analyzeDelete(node, queryContext);
analysis.setScope(node, ret);
+ accessControl.checkCanDeleteFromTable(sessionContext.getUserName(), new QualifiedObjectName(unQualifyDatabaseName(node.getDatabaseName()), node.getTable().getName().getSuffix()));
return ret;
}