From 086ec1424af89964d867b6d82afce7ef74f3c05f Mon Sep 17 00:00:00 2001 From: zhangdong Date: Thu, 28 Nov 2024 20:03:02 +0800 Subject: [PATCH 1/4] resolve conflict --- .../main/java/org/apache/doris/analysis/CreateUserStmt.java | 4 ++-- .../src/main/java/org/apache/doris/analysis/DropUserStmt.java | 4 ++-- .../src/main/java/org/apache/doris/analysis/UserIdentity.java | 4 ++++ .../doris/nereids/trees/plans/commands/DropUserCommand.java | 4 ++-- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/CreateUserStmt.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/CreateUserStmt.java index 74ca252779e61f..db27c7106506a8 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/CreateUserStmt.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/CreateUserStmt.java @@ -153,8 +153,8 @@ public void analyze(Analyzer analyzer) throws UserException { userIdent.analyze(); - if (userIdent.isRootUser()) { - ErrorReport.reportAnalysisException(ErrorCode.ERR_COMMON_ERROR, "Can not create root user"); + if (userIdent.isSystemUser()) { + ErrorReport.reportAnalysisException(ErrorCode.ERR_COMMON_ERROR, "Can not create system user"); } // convert plain password to hashed password diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/DropUserStmt.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/DropUserStmt.java index f9bb218744fc85..5f9872e42ad7cc 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/DropUserStmt.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/DropUserStmt.java @@ -63,8 +63,8 @@ public void analyze(Analyzer analyzer) throws AnalysisException, UserException { userIdent.analyze(); - if (userIdent.isRootUser()) { - ErrorReport.reportAnalysisException(ErrorCode.ERR_COMMON_ERROR, "Can not drop root user"); + if (userIdent.isSystemUser()) { + ErrorReport.reportAnalysisException(ErrorCode.ERR_COMMON_ERROR, "Can not drop system user"); } // only user with GLOBAL level's GRANT_PRIV can drop user. diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/UserIdentity.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/UserIdentity.java index 122f28ca45092b..6898915dab73ce 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/UserIdentity.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/UserIdentity.java @@ -189,6 +189,10 @@ public boolean isAdminUser() { return user.equals(Auth.ADMIN_USER); } + public boolean isSystemUser() { + return isRootUser() || isAdminUser(); + } + public TUserIdentity toThrift() { Preconditions.checkState(isAnalyzed); TUserIdentity tUserIdent = new TUserIdentity(); diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/DropUserCommand.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/DropUserCommand.java index 094ce06c36143e..5c4fb407e40213 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/DropUserCommand.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/DropUserCommand.java @@ -55,8 +55,8 @@ public void doRun(ConnectContext ctx, StmtExecutor executor) throws Exception { userIdent.analyze(); - if (userIdent.isRootUser()) { - ErrorReport.reportAnalysisException(ErrorCode.ERR_COMMON_ERROR, "Can not drop root user"); + if (userIdent.isSystemUser()) { + ErrorReport.reportAnalysisException(ErrorCode.ERR_COMMON_ERROR, "Can not drop system user"); } // only user with GLOBAL level's GRANT_PRIV can drop user. From 93d4ae8dab18ae28aa931e646fd329adc5cefab0 Mon Sep 17 00:00:00 2001 From: zhangdong Date: Thu, 28 Nov 2024 20:05:40 +0800 Subject: [PATCH 2/4] 1 --- .../suites/account_p0/test_system_user.groovy | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 regression-test/suites/account_p0/test_system_user.groovy diff --git a/regression-test/suites/account_p0/test_system_user.groovy b/regression-test/suites/account_p0/test_system_user.groovy new file mode 100644 index 00000000000000..a7dd28b26ad1c2 --- /dev/null +++ b/regression-test/suites/account_p0/test_system_user.groovy @@ -0,0 +1,45 @@ +// 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. + +import org.junit.Assert; + +suite("test_system_user") { + test { + sql """ + create user root; + """ + exception "system" + } + test { + sql """ + create user admin; + """ + exception "system" + } + test { + sql """ + drop user root; + """ + exception "system" + } + test { + sql """ + drop user admin; + """ + exception "system" + } +} From 6be9f2e448a5123aae6715b686fbbf989d73927b Mon Sep 17 00:00:00 2001 From: zhangdong Date: Thu, 28 Nov 2024 20:13:08 +0800 Subject: [PATCH 3/4] 1 --- regression-test/suites/account_p0/test_system_user.groovy | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/regression-test/suites/account_p0/test_system_user.groovy b/regression-test/suites/account_p0/test_system_user.groovy index a7dd28b26ad1c2..db906c5c4abf4e 100644 --- a/regression-test/suites/account_p0/test_system_user.groovy +++ b/regression-test/suites/account_p0/test_system_user.groovy @@ -20,25 +20,25 @@ import org.junit.Assert; suite("test_system_user") { test { sql """ - create user root; + create user `root`; """ exception "system" } test { sql """ - create user admin; + create user `admin`; """ exception "system" } test { sql """ - drop user root; + drop user `root`; """ exception "system" } test { sql """ - drop user admin; + drop user `admin`; """ exception "system" } From b517f8bba8e6ced309bb230ebf21b35bebf33afd Mon Sep 17 00:00:00 2001 From: zhangdong Date: Thu, 28 Nov 2024 22:40:12 +0800 Subject: [PATCH 4/4] 1 --- .../java/org/apache/doris/analysis/CreateUserStmt.java | 4 ++-- regression-test/suites/account_p0/test_system_user.groovy | 8 +------- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/CreateUserStmt.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/CreateUserStmt.java index db27c7106506a8..74ca252779e61f 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/CreateUserStmt.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/CreateUserStmt.java @@ -153,8 +153,8 @@ public void analyze(Analyzer analyzer) throws UserException { userIdent.analyze(); - if (userIdent.isSystemUser()) { - ErrorReport.reportAnalysisException(ErrorCode.ERR_COMMON_ERROR, "Can not create system user"); + if (userIdent.isRootUser()) { + ErrorReport.reportAnalysisException(ErrorCode.ERR_COMMON_ERROR, "Can not create root user"); } // convert plain password to hashed password diff --git a/regression-test/suites/account_p0/test_system_user.groovy b/regression-test/suites/account_p0/test_system_user.groovy index db906c5c4abf4e..1805f1669ea570 100644 --- a/regression-test/suites/account_p0/test_system_user.groovy +++ b/regression-test/suites/account_p0/test_system_user.groovy @@ -22,13 +22,7 @@ suite("test_system_user") { sql """ create user `root`; """ - exception "system" - } - test { - sql """ - create user `admin`; - """ - exception "system" + exception "root" } test { sql """