zddr commented on code in PR #16679: URL: https://github.com/apache/doris/pull/16679#discussion_r1105217886
########## fe/fe-core/src/main/java/org/apache/doris/mysql/privilege/AccessControllerManager.java: ########## @@ -0,0 +1,161 @@ +// 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.mysql.privilege; + +import org.apache.doris.analysis.TableName; +import org.apache.doris.analysis.UserIdentity; +import org.apache.doris.catalog.AuthorizationInfo; +import org.apache.doris.datasource.InternalCatalog; +import org.apache.doris.mysql.privilege.Auth.PrivLevel; +import org.apache.doris.qe.ConnectContext; + +import com.google.common.base.Preconditions; +import com.google.common.collect.Maps; + +import java.util.Map; + +/** + * AccessControllerManager is the entry point of privilege authentication. + * There are 2 kinds of access controller: + * SystemAccessController: for global level priv, resource priv and other Doris internal priv checking + * CatalogAccessController: for specified catalog's priv checking, can be customized. + * And using InternalCatalogAccessController as default. + */ +public class AccessControllerManager { + private SystemAccessController sysAccessController; + private CatalogAccessController internalAccessController; + private Map<String, CatalogAccessController> ctlToCtlAccessController = Maps.newConcurrentMap(); + + public AccessControllerManager(Auth auth) { + sysAccessController = new SystemAccessController(auth); + internalAccessController = new InternalCatalogAccessController(auth); + ctlToCtlAccessController.put(InternalCatalog.INTERNAL_CATALOG_NAME, internalAccessController); + } + + private CatalogAccessController getAccessControllerOrDefault(String ctl) { + return ctlToCtlAccessController.getOrDefault(ctl, internalAccessController); + } + + public void addCatalogAccessControl(String ctl, CatalogAccessController controller) { + ctlToCtlAccessController.put(ctl, controller); + } + + public Auth getAuth() { + return sysAccessController.getAuth(); + } + + // ==== Global ==== + public boolean checkGlobalPriv(ConnectContext ctx, PrivPredicate wanted) { + return checkGlobalPriv(ctx.getCurrentUserIdentity(), wanted); + } + + public boolean checkGlobalPriv(UserIdentity currentUser, PrivPredicate wanted) { + return sysAccessController.checkGlobalPriv(currentUser, wanted); + } + + // ==== Catalog ==== + public boolean checkCtlPriv(ConnectContext ctx, String ctl, PrivPredicate wanted) { + return checkCtlPriv(ctx.getCurrentUserIdentity(), ctl, wanted); + } + + public boolean checkCtlPriv(UserIdentity currentUser, String ctl, PrivPredicate wanted) { + boolean hasGlobal = sysAccessController.checkGlobalPriv(currentUser, wanted); + boolean hasCtl = getAccessControllerOrDefault(ctl).checkCtlPriv(hasGlobal, currentUser, ctl, wanted); + return hasGlobal || hasCtl; Review Comment: logic is repeated with 'CatalogAccessController.checkCtlPriv(boolean hasGlobal, UserIdentity currentUser, String ctl, PrivPredicate wanted)',here,can we use 'CatalogAccessController.checkCtlPriv(UserIdentity currentUser, String ctl, PrivPredicate wanted)'? and delete 'CatalogAccessController.checkCtlPriv(boolean hasGlobal, UserIdentity currentUser, String ctl, PrivPredicate wanted)'? -- 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: commits-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org