Caideyipi commented on code in PR #13158: URL: https://github.com/apache/iotdb/pull/13158#discussion_r1919455529
########## iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/security/ITableAuthCheckerImpl.java: ########## @@ -0,0 +1,165 @@ +/* + * 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.iotdb.db.queryengine.plan.relational.security; + +import org.apache.iotdb.common.rpc.thrift.TSStatus; +import org.apache.iotdb.commons.exception.IoTDBException; +import org.apache.iotdb.db.auth.AuthorityChecker; +import org.apache.iotdb.db.queryengine.plan.relational.metadata.QualifiedObjectName; +import org.apache.iotdb.rpc.TSStatusCode; + +public class ITableAuthCheckerImpl implements ITableAuthChecker { + + @Override + public void checkDatabaseVisibility(String userName, String databaseName) { + if (AuthorityChecker.SUPER_USER.equals(userName)) { + return; + } + if (!AuthorityChecker.checkDBVisible(userName, databaseName)) { + throw new RuntimeException( + new IoTDBException("NO PERMISSION", TSStatusCode.NO_PERMISSION.getStatusCode())); + } + } + + @Override + public void checkDatabasePrivilege( + String userName, String databaseName, TableModelPrivilege privilege) { + if (AuthorityChecker.SUPER_USER.equals(userName)) { + return; + } + TSStatus result = + AuthorityChecker.getTSStatus( + AuthorityChecker.checkDBPermission( + userName, databaseName, privilege.getPrivilegeType()), + privilege.getPrivilegeType(), + databaseName); + if (result.getCode() != TSStatusCode.SUCCESS_STATUS.getStatusCode()) { + throw new RuntimeException(new IoTDBException(result.getMessage(), result.getCode())); + } + } + + @Override + public void checkDatabasePrivilegeGrantOption( + String userName, String databaseName, TableModelPrivilege privilege) { + TSStatus result = + AuthorityChecker.getGrantOptTSStatus( + AuthorityChecker.checkDBPermissionGrantOption( + userName, databaseName, privilege.getPrivilegeType()), + privilege.getPrivilegeType(), + databaseName); + if (result.getCode() != TSStatusCode.SUCCESS_STATUS.getStatusCode()) { + throw new RuntimeException(new IoTDBException(result.getMessage(), result.getCode())); + } + } + + @Override + public void checkTablePrivilege( + String userName, QualifiedObjectName tableName, TableModelPrivilege privilege) { + if (AuthorityChecker.SUPER_USER.equals(userName)) { + return; + } + TSStatus result = + AuthorityChecker.getTSStatus( + AuthorityChecker.checkTablePermission( + userName, + tableName.getDatabaseName(), + tableName.getObjectName(), + privilege.getPrivilegeType()), + privilege.getPrivilegeType(), + tableName.getDatabaseName(), + tableName.getObjectName()); + if (result.getCode() != TSStatusCode.SUCCESS_STATUS.getStatusCode()) { + throw new RuntimeException(new IoTDBException(result.getMessage(), result.getCode())); Review Comment: Now the outer "showDB" just catch AccessControlException... Using RuntimeException will break its logic and make user unable to show any db where there are databases without permission= = -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
