saihemanth-cloudera commented on code in PR #5819: URL: https://github.com/apache/hive/pull/5819#discussion_r2141062590
########## ql/src/test/org/apache/hadoop/hive/ql/security/authorization/plugin/metastore/MockMetaStoreFilterHook.java: ########## @@ -0,0 +1,190 @@ +/* + * 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.hadoop.hive.ql.security.authorization.plugin.metastore; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.hive.metastore.MetaStoreFilterHook; +import org.apache.hadoop.hive.metastore.api.Database; +import org.apache.hadoop.hive.metastore.api.MetaException; +import org.apache.hadoop.hive.metastore.api.NoSuchObjectException; +import org.apache.hadoop.hive.metastore.api.Partition; +import org.apache.hadoop.hive.metastore.api.PartitionSpec; +import org.apache.hadoop.hive.metastore.api.Table; +import org.apache.hadoop.hive.metastore.api.TableMeta; + +import java.util.List; +import java.util.stream.Collectors; + +/** + * Mock implementation of MetaStoreFilterHook that filters based on ownership. + */ +public class MockMetaStoreFilterHook implements MetaStoreFilterHook { + + private static final Logger LOG = LoggerFactory.getLogger(MockMetaStoreFilterHook.class); + private static final String AUTHORIZED_OWNER = TestHiveMetaStoreAuthorizer.authorizedUser; + + public MockMetaStoreFilterHook(Configuration conf) { + LOG.info("Initialized MockMetaStoreFilterHook with authorized owner: " + AUTHORIZED_OWNER); + } + + @Override + public List<String> filterDatabases(List<String> dbList) throws MetaException { + LOG.debug("filterDatabases: Original list size: {}", dbList != null ? dbList.size() : 0); + return dbList; + } + + @Override + public Database filterDatabase(Database dataBase) throws MetaException, NoSuchObjectException { + if (dataBase == null) { + LOG.debug("filterDatabase: Database is null"); + return null; + } + + String dbName = dataBase.getName(); + String ownerName = dataBase.getOwnerName(); + + if (!AUTHORIZED_OWNER.equals(ownerName)) { + LOG.info("filterDatabase: Filtering out database '{}' - owner '{}' is not authorized", dbName, ownerName); + return null; + } + + LOG.debug("filterDatabase: Allowed access to database '{}' for owner '{}'", dbName, ownerName); + return dataBase; + } + + @Override + public List<String> filterTableNames(String catName, String dbName, List<String> tableList) throws MetaException { + LOG.debug("filterTableNames: Returning all tables for {}.{}, count: {}", catName, dbName, tableList != null ? tableList.size() : 0); + return tableList; + } + + @Override + public List<TableMeta> filterTableMetas(String catName, String dbName, List<TableMeta> tableMetas) throws MetaException { + if (tableMetas == null) { + LOG.debug("filterTableMetas: Table metas list is null"); + return null; + } + + LOG.info("filterTableMetas: Filtering {} table metas for {}.{}", tableMetas.size(), catName, dbName); + + List<TableMeta> filtered = tableMetas.stream() + .filter(tm -> { + boolean authorized = AUTHORIZED_OWNER.equals(tm.getOwnerName()); + if (!authorized) { + LOG.debug("Filtering out table meta '{}' - owner '{}' is not authorized", tm.getTableName(), tm.getOwnerName()); + } + return authorized; Review Comment: why do we return this? -- 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: gitbox-unsubscr...@hive.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: gitbox-unsubscr...@hive.apache.org For additional commands, e-mail: gitbox-h...@hive.apache.org