MetastoreAuthzObjectFilter { public List<T> filterTables(String username, List<T> tables) { if (tables == null) { return Collections.emptyList(); } List<T> filteredTables = Lists.newArrayList(); for (T table : tables) { String dbName = extractor.getDatabaseName(table); String tableName = extractor.getTableName(table); if (Strings.isEmpty(dbName) || authorizeTable(username, dbName, tableName)) { filteredTables.add(table); } } return filteredTables; } MetastoreAuthzObjectFilter(HiveAuthzBinding authzBinding, ObjectExtractor extractor); static HiveAuthzPrivileges getListDatabasesPrivileges(); HiveAuthzPrivileges getListTablePrivileges(); List<T> filterDatabases(String username, List<T> dbNames); List<T> filterTables(String username, List<T> tables);  }
@Test public void testFilterTableStrings() { final String USER1 = "user1"; final String DB1 = "db1"; MetastoreAuthzObjectFilter filter = new MetastoreAuthzObjectFilter(mockBinding, createTableStringExtractor(DB1)); assertThat(filter).isNotNull(); assertThat(filter.filterTables(USER1, null)).isNotNull().isEmpty(); assertThat(filter.filterTables(USER1, null)).isNotNull().isEmpty(); assertThat(filter.filterTables(USER1, Collections.emptyList())).isNotNull().isEmpty(); assertThat(filter.filterTables(USER1, Arrays.asList(null, "", null, null, ""))) .containsExactly(null, "", null, null, ""); restrictTablesNamesOnBinding(USER1, DB1, Arrays.asList("t1", "t3", "t5")); assertThat(filter.filterTables(USER1, Arrays.asList("t1", "t2", "t3", "t4", "t5"))) .containsExactly("t2", "t4"); }
@Test public void testFilterTableHiveObjects() { final String USER1 = "user1"; final String DB1 = "db1"; MetastoreAuthzObjectFilter<HivePrivilegeObject> filter = new MetastoreAuthzObjectFilter(mockBinding, HIVE_OBJECT_EXTRACTOR); assertThat(filter).isNotNull(); assertThat(filter.filterTables(USER1, null)).isNotNull().isEmpty(); assertThat(filter.filterTables(USER1, null)).isNotNull().isEmpty(); assertThat(filter.filterTables(USER1, Collections.emptyList())).isNotNull().isEmpty(); assertThat(filter.filterTables(USER1, Arrays.asList(null, null))) .containsExactly(null, null); restrictTablesNamesOnBinding(USER1, DB1, Arrays.asList("t1", "t3", "t5")); assertThat(filter.filterTables(USER1, createHivePrivilegeTableList(DB1, "t1", "t2", "t3", "t4", "t5"))) .extracting(HiveObjectExtractor.objectName()).containsExactly("t2", "t4"); }