-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Enhancement] (nereids)implement DropUserCommand in nereids
- Loading branch information
Showing
7 changed files
with
136 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/DropUserCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// 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.doris.nereids.trees.plans.commands; | ||
|
||
import org.apache.doris.analysis.UserIdentity; | ||
import org.apache.doris.catalog.Env; | ||
import org.apache.doris.common.AnalysisException; | ||
import org.apache.doris.common.Config; | ||
import org.apache.doris.common.ErrorCode; | ||
import org.apache.doris.common.ErrorReport; | ||
import org.apache.doris.mysql.authenticate.AuthenticateType; | ||
import org.apache.doris.mysql.privilege.PrivPredicate; | ||
import org.apache.doris.nereids.trees.plans.PlanType; | ||
import org.apache.doris.nereids.trees.plans.visitor.PlanVisitor; | ||
import org.apache.doris.qe.ConnectContext; | ||
import org.apache.doris.qe.StmtExecutor; | ||
|
||
/** | ||
* drop user command | ||
*/ | ||
public class DropUserCommand extends DropCommand { | ||
private final boolean ifExists; | ||
private final UserIdentity userIdent; | ||
|
||
/** | ||
* constructor | ||
*/ | ||
public DropUserCommand(UserIdentity userIdent, boolean ifExists) { | ||
super(PlanType.DROP_USER_COMMAND); | ||
this.userIdent = userIdent; | ||
this.ifExists = ifExists; | ||
} | ||
|
||
@Override | ||
public void doRun(ConnectContext ctx, StmtExecutor executor) throws Exception { | ||
if (Config.access_controller_type.equalsIgnoreCase("ranger-doris") | ||
&& AuthenticateType.getAuthTypeConfig() == AuthenticateType.LDAP) { | ||
throw new AnalysisException("Drop user is prohibited when Ranger and LDAP are enabled at same time."); | ||
} | ||
|
||
userIdent.analyze(); | ||
|
||
if (userIdent.isRootUser()) { | ||
ErrorReport.reportAnalysisException(ErrorCode.ERR_COMMON_ERROR, "Can not drop root user"); | ||
} | ||
|
||
// only user with GLOBAL level's GRANT_PRIV can drop user. | ||
if (!Env.getCurrentEnv().getAccessManager().checkGlobalPriv(ConnectContext.get(), PrivPredicate.GRANT)) { | ||
ErrorReport.reportAnalysisException(ErrorCode.ERR_SPECIFIC_ACCESS_DENIED_ERROR, "DROP USER"); | ||
} | ||
Env.getCurrentEnv().getAuth().dropUser(userIdent, ifExists); | ||
} | ||
|
||
@Override | ||
public <R, C> R accept(PlanVisitor<R, C> visitor, C context) { | ||
return visitor.visitDropUserCommand(this, context); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
regression-test/suites/account_p0/test_nereids_account.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// 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_nereids_account") { | ||
// test comment | ||
def user = "ttest_nereids_account_comment_user"; | ||
sql """drop user if exists ${user}""" | ||
// create user with comment | ||
sql """create user ${user} comment 'ttest_nereids_account_comment_user_comment_create'""" | ||
def user_create = sql "show grants for ${user}" | ||
logger.info("user_create: " + user_create.toString()) | ||
assertTrue(user_create.toString().contains("ttest_nereids_account_comment_user_comment_create")) | ||
// alter user comment | ||
sql """alter user ${user} comment 'ttest_nereids_account_comment_user_comment_alter'""" | ||
def user_alter = sql "show grants for ${user}" | ||
logger.info("user_alter: " + user_alter.toString()) | ||
assertTrue(user_alter.toString().contains("ttest_nereids_account_comment_user_comment_alter")) | ||
// drop user | ||
checkNereidsExecute("""drop user ${user}""") | ||
checkNereidsExecute("""drop user if exists ${user}""") | ||
try { | ||
sql "show grants for ${user}" | ||
fail() | ||
} catch (Exception e) { | ||
log.info(e.getMessage()) | ||
assertTrue(e.getMessage().contains('not exist')) | ||
} | ||
} |