Search in sources :

Example 6 with HivePrincipal

use of io.trino.plugin.hive.metastore.HivePrincipal in project trino by trinodb.

the class ThriftMetastoreUtil method listEnabledRoles.

public static Stream<String> listEnabledRoles(ConnectorIdentity identity, Function<HivePrincipal, Set<RoleGrant>> listRoleGrants) {
    if (identity.getConnectorRole().isPresent() && identity.getConnectorRole().get().getType() == SelectedRole.Type.NONE) {
        return Stream.of(PUBLIC_ROLE_NAME);
    }
    HivePrincipal principal = HivePrincipal.from(identity);
    Stream<String> roles = Stream.of(PUBLIC_ROLE_NAME);
    if (principal.getType() == ROLE) {
        roles = Stream.concat(roles, Stream.of(principal.getName()));
    }
    return Stream.concat(roles, listApplicableRoles(principal, listRoleGrants).map(RoleGrant::getRoleName).filter(Predicate.isEqual(ADMIN_ROLE_NAME).negate())).distinct();
}
Also used : HivePrincipal(io.trino.plugin.hive.metastore.HivePrincipal)

Example 7 with HivePrincipal

use of io.trino.plugin.hive.metastore.HivePrincipal in project trino by trinodb.

the class ThriftMetastoreUtil method parsePrivilege.

public static Set<HivePrivilegeInfo> parsePrivilege(PrivilegeGrantInfo userGrant, Optional<HivePrincipal> grantee) {
    boolean grantOption = userGrant.isGrantOption();
    String name = userGrant.getPrivilege().toUpperCase(ENGLISH);
    HivePrincipal grantor = new HivePrincipal(fromMetastoreApiPrincipalType(userGrant.getGrantorType()), userGrant.getGrantor());
    switch(name) {
        case "ALL":
            return Arrays.stream(HivePrivilegeInfo.HivePrivilege.values()).map(hivePrivilege -> new HivePrivilegeInfo(hivePrivilege, grantOption, grantor, grantee.orElse(grantor))).collect(toImmutableSet());
        case "SELECT":
            return ImmutableSet.of(new HivePrivilegeInfo(SELECT, grantOption, grantor, grantee.orElse(grantor)));
        case "INSERT":
            return ImmutableSet.of(new HivePrivilegeInfo(INSERT, grantOption, grantor, grantee.orElse(grantor)));
        case "UPDATE":
            return ImmutableSet.of(new HivePrivilegeInfo(UPDATE, grantOption, grantor, grantee.orElse(grantor)));
        case "DELETE":
            return ImmutableSet.of(new HivePrivilegeInfo(DELETE, grantOption, grantor, grantee.orElse(grantor)));
        case "OWNERSHIP":
            return ImmutableSet.of(new HivePrivilegeInfo(OWNERSHIP, grantOption, grantor, grantee.orElse(grantor)));
        default:
            throw new IllegalArgumentException("Unsupported privilege name: " + name);
    }
}
Also used : Arrays(java.util.Arrays) USER(io.trino.spi.security.PrincipalType.USER) HiveColumnStatistics.createDecimalColumnStatistics(io.trino.plugin.hive.metastore.HiveColumnStatistics.createDecimalColumnStatistics) NUMBER_OF_DISTINCT_VALUES(io.trino.spi.statistics.ColumnStatisticType.NUMBER_OF_DISTINCT_VALUES) SerDeInfo(org.apache.hadoop.hive.metastore.api.SerDeInfo) ColumnStatisticType(io.trino.spi.statistics.ColumnStatisticType) BigDecimal(java.math.BigDecimal) HiveColumnStatistics.createDateColumnStatistics(io.trino.plugin.hive.metastore.HiveColumnStatistics.createDateColumnStatistics) Column(io.trino.plugin.hive.metastore.Column) BooleanColumnStatsData(org.apache.hadoop.hive.metastore.api.BooleanColumnStatsData) Math.round(java.lang.Math.round) Map(java.util.Map) DoubleColumnStatsData(org.apache.hadoop.hive.metastore.api.DoubleColumnStatsData) BigInteger(java.math.BigInteger) PartitionWithStatistics(io.trino.plugin.hive.metastore.PartitionWithStatistics) ENGLISH(java.util.Locale.ENGLISH) SMALLINT(io.trino.spi.type.SmallintType.SMALLINT) UPDATE(io.trino.plugin.hive.metastore.HivePrivilegeInfo.HivePrivilege.UPDATE) Longs(com.google.common.primitives.Longs) DecimalColumnStatsData(org.apache.hadoop.hive.metastore.api.DecimalColumnStatsData) Table(io.trino.plugin.hive.metastore.Table) ConnectorIdentity(io.trino.spi.security.ConnectorIdentity) ColumnStatisticsData.decimalStats(org.apache.hadoop.hive.metastore.api.ColumnStatisticsData.decimalStats) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Set(java.util.Set) Stream(java.util.stream.Stream) TrinoPrincipal(io.trino.spi.security.TrinoPrincipal) HiveColumnStatistics.createBooleanColumnStatistics(io.trino.plugin.hive.metastore.HiveColumnStatistics.createBooleanColumnStatistics) OWNERSHIP(io.trino.plugin.hive.metastore.HivePrivilegeInfo.HivePrivilege.OWNERSHIP) Date(org.apache.hadoop.hive.metastore.api.Date) DATE(io.trino.spi.type.DateType.DATE) REAL(io.trino.spi.type.RealType.REAL) Partition(io.trino.plugin.hive.metastore.Partition) HivePrincipal(io.trino.plugin.hive.metastore.HivePrincipal) BOOLEAN(io.trino.spi.type.BooleanType.BOOLEAN) TimestampType(io.trino.spi.type.TimestampType) HiveBucketProperty(io.trino.plugin.hive.HiveBucketProperty) HiveType(io.trino.plugin.hive.HiveType) OptionalLong(java.util.OptionalLong) HIVE_INVALID_METADATA(io.trino.plugin.hive.HiveErrorCode.HIVE_INVALID_METADATA) NUMBER_OF_TRUE_VALUES(io.trino.spi.statistics.ColumnStatisticType.NUMBER_OF_TRUE_VALUES) AVRO_SCHEMA_URL_KEY(io.trino.plugin.hive.HiveMetadata.AVRO_SCHEMA_URL_KEY) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) VARBINARY(io.trino.spi.type.VarbinaryType.VARBINARY) NUMBER_OF_NON_NULL_VALUES(io.trino.spi.statistics.ColumnStatisticType.NUMBER_OF_NON_NULL_VALUES) LongColumnStatsData(org.apache.hadoop.hive.metastore.api.LongColumnStatsData) PrincipalPrivilegeSet(org.apache.hadoop.hive.metastore.api.PrincipalPrivilegeSet) PrivilegeGrantInfo(org.apache.hadoop.hive.metastore.api.PrivilegeGrantInfo) Nullable(javax.annotation.Nullable) ColumnStatisticsData.binaryStats(org.apache.hadoop.hive.metastore.api.ColumnStatisticsData.binaryStats) PrincipalType(io.trino.spi.security.PrincipalType) MapType(io.trino.spi.type.MapType) AbstractIterator(com.google.common.collect.AbstractIterator) Storage(io.trino.plugin.hive.metastore.Storage) RoleGrant(io.trino.spi.security.RoleGrant) DOUBLE(io.trino.spi.type.DoubleType.DOUBLE) StringColumnStatsData(org.apache.hadoop.hive.metastore.api.StringColumnStatsData) Strings.emptyToNull(com.google.common.base.Strings.emptyToNull) ColumnStatisticsData.longStats(org.apache.hadoop.hive.metastore.api.ColumnStatisticsData.longStats) CharType(io.trino.spi.type.CharType) DateColumnStatsData(org.apache.hadoop.hive.metastore.api.DateColumnStatsData) MAX_VALUE(io.trino.spi.statistics.ColumnStatisticType.MAX_VALUE) TINYINT(io.trino.spi.type.TinyintType.TINYINT) ArrayDeque(java.util.ArrayDeque) ColumnStatisticsData.stringStats(org.apache.hadoop.hive.metastore.api.ColumnStatisticsData.stringStats) TOTAL_SIZE_IN_BYTES(io.trino.spi.statistics.ColumnStatisticType.TOTAL_SIZE_IN_BYTES) HiveColumnStatistics.createStringColumnStatistics(io.trino.plugin.hive.metastore.HiveColumnStatistics.createStringColumnStatistics) ColumnStatisticsData.booleanStats(org.apache.hadoop.hive.metastore.api.ColumnStatisticsData.booleanStats) HiveColumnStatistics.createBinaryColumnStatistics(io.trino.plugin.hive.metastore.HiveColumnStatistics.createBinaryColumnStatistics) Database(io.trino.plugin.hive.metastore.Database) RolePrincipalGrant(org.apache.hadoop.hive.metastore.api.RolePrincipalGrant) ByteBuffer(java.nio.ByteBuffer) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) ColumnStatisticsData.doubleStats(org.apache.hadoop.hive.metastore.api.ColumnStatisticsData.doubleStats) MAX_VALUE_SIZE_IN_BYTES(io.trino.spi.statistics.ColumnStatisticType.MAX_VALUE_SIZE_IN_BYTES) PrimitiveTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.PrimitiveTypeInfo) INTEGER(io.trino.spi.type.IntegerType.INTEGER) StorageDescriptor(org.apache.hadoop.hive.metastore.api.StorageDescriptor) AVRO(io.trino.plugin.hive.HiveStorageFormat.AVRO) StorageFormat(io.trino.plugin.hive.metastore.StorageFormat) HiveBasicStatistics(io.trino.plugin.hive.HiveBasicStatistics) RowType(io.trino.spi.type.RowType) INSERT(io.trino.plugin.hive.metastore.HivePrivilegeInfo.HivePrivilege.INSERT) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) Predicate(java.util.function.Predicate) ColumnStatisticsObj(org.apache.hadoop.hive.metastore.api.ColumnStatisticsObj) Collection(java.util.Collection) Decimal(org.apache.hadoop.hive.metastore.api.Decimal) Order(org.apache.hadoop.hive.metastore.api.Order) TrinoException(io.trino.spi.TrinoException) ArrayType(io.trino.spi.type.ArrayType) Streams(com.google.common.collect.Streams) String.format(java.lang.String.format) HiveColumnStatistics.createDoubleColumnStatistics(io.trino.plugin.hive.metastore.HiveColumnStatistics.createDoubleColumnStatistics) SelectedRole(io.trino.spi.security.SelectedRole) List(java.util.List) BIGINT(io.trino.spi.type.BigintType.BIGINT) LocalDate(java.time.LocalDate) Optional(java.util.Optional) Queue(java.util.Queue) HivePrivilegeInfo(io.trino.plugin.hive.metastore.HivePrivilegeInfo) DecimalType(io.trino.spi.type.DecimalType) Strings.nullToEmpty(com.google.common.base.Strings.nullToEmpty) Type(io.trino.spi.type.Type) OptionalDouble(java.util.OptionalDouble) Shorts(com.google.common.primitives.Shorts) CSV(io.trino.plugin.hive.HiveStorageFormat.CSV) Function(java.util.function.Function) HashSet(java.util.HashSet) VarcharType(io.trino.spi.type.VarcharType) HiveColumnStatistics(io.trino.plugin.hive.metastore.HiveColumnStatistics) ColumnStatisticsData.dateStats(org.apache.hadoop.hive.metastore.api.ColumnStatisticsData.dateStats) BinaryColumnStatsData(org.apache.hadoop.hive.metastore.api.BinaryColumnStatsData) Objects.requireNonNull(java.util.Objects.requireNonNull) HiveColumnStatistics.createIntegerColumnStatistics(io.trino.plugin.hive.metastore.HiveColumnStatistics.createIntegerColumnStatistics) DELETE(io.trino.plugin.hive.metastore.HivePrivilegeInfo.HivePrivilege.DELETE) ROLE(io.trino.spi.security.PrincipalType.ROLE) PRIMITIVE(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector.Category.PRIMITIVE) TypeInfo(org.apache.hadoop.hive.serde2.typeinfo.TypeInfo) FieldSchema(org.apache.hadoop.hive.metastore.api.FieldSchema) SELECT(io.trino.plugin.hive.metastore.HivePrivilegeInfo.HivePrivilege.SELECT) PrincipalPrivileges(io.trino.plugin.hive.metastore.PrincipalPrivileges) MIN_VALUE(io.trino.spi.statistics.ColumnStatisticType.MIN_VALUE) HivePrivilegeInfo(io.trino.plugin.hive.metastore.HivePrivilegeInfo) HivePrincipal(io.trino.plugin.hive.metastore.HivePrincipal)

Example 8 with HivePrincipal

use of io.trino.plugin.hive.metastore.HivePrincipal in project trino by trinodb.

the class SqlStandardAccessControl method isDatabaseOwner.

private boolean isDatabaseOwner(ConnectorSecurityContext context, String databaseName) {
    // all users are "owners" of the default database
    if (DEFAULT_DATABASE_NAME.equalsIgnoreCase(databaseName)) {
        return true;
    }
    if (isAdmin(context)) {
        return true;
    }
    Optional<Database> databaseMetadata = metastore.getDatabase(context, databaseName);
    if (databaseMetadata.isEmpty()) {
        return false;
    }
    Database database = databaseMetadata.get();
    // a database can be owned by a user or role
    ConnectorIdentity identity = context.getIdentity();
    if (database.getOwnerName().isPresent()) {
        if (database.getOwnerType().orElse(null) == USER && identity.getUser().equals(database.getOwnerName().get())) {
            return true;
        }
        if (database.getOwnerType().orElse(null) == ROLE && isRoleEnabled(identity, hivePrincipal -> metastore.listRoleGrants(context, hivePrincipal), database.getOwnerName().get())) {
            return true;
        }
    }
    return false;
}
Also used : AccessDeniedException.denyAddColumn(io.trino.spi.security.AccessDeniedException.denyAddColumn) DEFAULT_DATABASE_NAME(io.trino.plugin.hive.metastore.Database.DEFAULT_DATABASE_NAME) SchemaRoutineName(io.trino.spi.connector.SchemaRoutineName) AccessDeniedException.denySetCatalogSessionProperty(io.trino.spi.security.AccessDeniedException.denySetCatalogSessionProperty) AccessDeniedException.denyDropTable(io.trino.spi.security.AccessDeniedException.denyDropTable) AccessDeniedException.denySetTableProperties(io.trino.spi.security.AccessDeniedException.denySetTableProperties) USER(io.trino.spi.security.PrincipalType.USER) AccessDeniedException.denySetMaterializedViewProperties(io.trino.spi.security.AccessDeniedException.denySetMaterializedViewProperties) Database(io.trino.plugin.hive.metastore.Database) AccessDeniedException.denyInsertTable(io.trino.spi.security.AccessDeniedException.denyInsertTable) ThriftMetastoreUtil.listEnabledPrincipals(io.trino.plugin.hive.metastore.thrift.ThriftMetastoreUtil.listEnabledPrincipals) AccessDeniedException.denyExecuteTableProcedure(io.trino.spi.security.AccessDeniedException.denyExecuteTableProcedure) AccessDeniedException.denyShowCreateTable(io.trino.spi.security.AccessDeniedException.denyShowCreateTable) AccessDeniedException.denyRevokeTablePrivilege(io.trino.spi.security.AccessDeniedException.denyRevokeTablePrivilege) NOT_SUPPORTED(io.trino.spi.StandardErrorCode.NOT_SUPPORTED) AccessDeniedException.denyUpdateTableColumns(io.trino.spi.security.AccessDeniedException.denyUpdateTableColumns) Map(java.util.Map) AccessDeniedException.denyCreateSchema(io.trino.spi.security.AccessDeniedException.denyCreateSchema) AccessDeniedException.denyCreateMaterializedView(io.trino.spi.security.AccessDeniedException.denyCreateMaterializedView) AccessDeniedException.denyCreateTable(io.trino.spi.security.AccessDeniedException.denyCreateTable) AccessDeniedException.denyDeleteTable(io.trino.spi.security.AccessDeniedException.denyDeleteTable) AccessDeniedException.denyDropView(io.trino.spi.security.AccessDeniedException.denyDropView) AccessDeniedException.denyRenameSchema(io.trino.spi.security.AccessDeniedException.denyRenameSchema) AccessDeniedException.denyShowRoles(io.trino.spi.security.AccessDeniedException.denyShowRoles) Collectors.toSet(java.util.stream.Collectors.toSet) AccessDeniedException.denyShowColumns(io.trino.spi.security.AccessDeniedException.denyShowColumns) UPDATE(io.trino.plugin.hive.metastore.HivePrivilegeInfo.HivePrivilege.UPDATE) INSERT(io.trino.plugin.hive.metastore.HivePrivilegeInfo.HivePrivilege.INSERT) AccessDeniedException.denyRenameMaterializedView(io.trino.spi.security.AccessDeniedException.denyRenameMaterializedView) ImmutableSet(com.google.common.collect.ImmutableSet) ConnectorIdentity(io.trino.spi.security.ConnectorIdentity) AccessDeniedException.denySetTableAuthorization(io.trino.spi.security.AccessDeniedException.denySetTableAuthorization) AccessDeniedException.denyDropSchema(io.trino.spi.security.AccessDeniedException.denyDropSchema) AccessDeniedException.denyTruncateTable(io.trino.spi.security.AccessDeniedException.denyTruncateTable) ViewExpression(io.trino.spi.security.ViewExpression) ConnectorAccessControl(io.trino.spi.connector.ConnectorAccessControl) Set(java.util.Set) TrinoException(io.trino.spi.TrinoException) SchemaTableName(io.trino.spi.connector.SchemaTableName) AccessDeniedException.denySetRole(io.trino.spi.security.AccessDeniedException.denySetRole) AccessDeniedException.denyShowCreateSchema(io.trino.spi.security.AccessDeniedException.denyShowCreateSchema) Stream(java.util.stream.Stream) TrinoPrincipal(io.trino.spi.security.TrinoPrincipal) OWNERSHIP(io.trino.plugin.hive.metastore.HivePrivilegeInfo.HivePrivilege.OWNERSHIP) AccessDeniedException.denyRefreshMaterializedView(io.trino.spi.security.AccessDeniedException.denyRefreshMaterializedView) AccessDeniedException.denyCreateRole(io.trino.spi.security.AccessDeniedException.denyCreateRole) Optional(java.util.Optional) HivePrivilegeInfo(io.trino.plugin.hive.metastore.HivePrivilegeInfo) HivePrincipal(io.trino.plugin.hive.metastore.HivePrincipal) AccessDeniedException(io.trino.spi.security.AccessDeniedException) HivePrivilegeInfo.toHivePrivilege(io.trino.plugin.hive.metastore.HivePrivilegeInfo.toHivePrivilege) AccessDeniedException.denyDropColumn(io.trino.spi.security.AccessDeniedException.denyDropColumn) Type(io.trino.spi.type.Type) ThriftMetastoreUtil.isRoleApplicable(io.trino.plugin.hive.metastore.thrift.ThriftMetastoreUtil.isRoleApplicable) AccessDeniedException.denyDropRole(io.trino.spi.security.AccessDeniedException.denyDropRole) AccessDeniedException.denySetViewAuthorization(io.trino.spi.security.AccessDeniedException.denySetViewAuthorization) Inject(javax.inject.Inject) AccessDeniedException.denyCommentColumn(io.trino.spi.security.AccessDeniedException.denyCommentColumn) AccessDeniedException.denySetSchemaAuthorization(io.trino.spi.security.AccessDeniedException.denySetSchemaAuthorization) AccessDeniedException.denyCreateViewWithSelect(io.trino.spi.security.AccessDeniedException.denyCreateViewWithSelect) AccessDeniedException.denyDropMaterializedView(io.trino.spi.security.AccessDeniedException.denyDropMaterializedView) Objects.requireNonNull(java.util.Objects.requireNonNull) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) AccessDeniedException.denyRevokeRoles(io.trino.spi.security.AccessDeniedException.denyRevokeRoles) Privilege(io.trino.spi.security.Privilege) AccessDeniedException.denyRenameTable(io.trino.spi.security.AccessDeniedException.denyRenameTable) AccessDeniedException.denyShowRoleAuthorizationDescriptors(io.trino.spi.security.AccessDeniedException.denyShowRoleAuthorizationDescriptors) ConnectorSecurityContext(io.trino.spi.connector.ConnectorSecurityContext) AccessDeniedException.denySelectTable(io.trino.spi.security.AccessDeniedException.denySelectTable) AccessDeniedException.denyCreateView(io.trino.spi.security.AccessDeniedException.denyCreateView) DELETE(io.trino.plugin.hive.metastore.HivePrivilegeInfo.HivePrivilege.DELETE) AccessDeniedException.denyCommentTable(io.trino.spi.security.AccessDeniedException.denyCommentTable) CatalogName(io.trino.plugin.base.CatalogName) ROLE(io.trino.spi.security.PrincipalType.ROLE) RoleGrant(io.trino.spi.security.RoleGrant) SELECT(io.trino.plugin.hive.metastore.HivePrivilegeInfo.HivePrivilege.SELECT) AccessDeniedException.denyRenameColumn(io.trino.spi.security.AccessDeniedException.denyRenameColumn) AccessDeniedException.denyGrantRoles(io.trino.spi.security.AccessDeniedException.denyGrantRoles) ThriftMetastoreUtil.listApplicableRoles(io.trino.plugin.hive.metastore.thrift.ThriftMetastoreUtil.listApplicableRoles) ThriftMetastoreUtil.isRoleEnabled(io.trino.plugin.hive.metastore.thrift.ThriftMetastoreUtil.isRoleEnabled) AccessDeniedException.denyRenameView(io.trino.spi.security.AccessDeniedException.denyRenameView) AccessDeniedException.denyGrantTablePrivilege(io.trino.spi.security.AccessDeniedException.denyGrantTablePrivilege) HivePrivilege(io.trino.plugin.hive.metastore.HivePrivilegeInfo.HivePrivilege) Database(io.trino.plugin.hive.metastore.Database) ConnectorIdentity(io.trino.spi.security.ConnectorIdentity)

Example 9 with HivePrincipal

use of io.trino.plugin.hive.metastore.HivePrincipal in project trino by trinodb.

the class TestCachingHiveMetastore method testSetTableAuthorization.

@Test
public void testSetTableAuthorization() {
    assertEquals(mockClient.getAccessCount(), 0);
    assertNotNull(metastore.getTable(TEST_DATABASE, TEST_TABLE));
    assertNotNull(metastore.getDatabase(TEST_DATABASE));
    assertEquals(mockClient.getAccessCount(), 2);
    metastore.setTableOwner(TEST_DATABASE, TEST_TABLE, new HivePrincipal(USER, "ignore"));
    assertEquals(mockClient.getAccessCount(), 3);
    assertNotNull(metastore.getTable(TEST_DATABASE, TEST_TABLE));
    assertEquals(mockClient.getAccessCount(), 4);
    // Assert that database cache has not been invalidated
    assertNotNull(metastore.getDatabase(TEST_DATABASE));
    assertEquals(mockClient.getAccessCount(), 4);
}
Also used : HivePrincipal(io.trino.plugin.hive.metastore.HivePrincipal) Test(org.testng.annotations.Test)

Example 10 with HivePrincipal

use of io.trino.plugin.hive.metastore.HivePrincipal in project trino by trinodb.

the class TestRecordingHiveMetastore method validateMetadata.

private void validateMetadata(HiveMetastore hiveMetastore) {
    assertEquals(hiveMetastore.getDatabase("database"), Optional.of(DATABASE));
    assertEquals(hiveMetastore.getAllDatabases(), ImmutableList.of("database"));
    assertEquals(hiveMetastore.getTable("database", "table"), Optional.of(TABLE));
    assertEquals(hiveMetastore.getSupportedColumnStatistics(createVarcharType(123)), ImmutableSet.of(MIN_VALUE, MAX_VALUE));
    assertEquals(hiveMetastore.getTableStatistics(TABLE), PARTITION_STATISTICS);
    assertEquals(hiveMetastore.getPartitionStatistics(TABLE, ImmutableList.of(PARTITION)), ImmutableMap.of("value", PARTITION_STATISTICS));
    assertEquals(hiveMetastore.getAllTables("database"), ImmutableList.of("table"));
    assertEquals(hiveMetastore.getTablesWithParameter("database", "param", "value3"), ImmutableList.of("table"));
    assertEquals(hiveMetastore.getAllViews("database"), ImmutableList.of());
    assertEquals(hiveMetastore.getPartition(TABLE, ImmutableList.of("value")), Optional.of(PARTITION));
    assertEquals(hiveMetastore.getPartitionNamesByFilter("database", "table", PARTITION_COLUMN_NAMES, TupleDomain.all()), Optional.of(ImmutableList.of("value")));
    assertEquals(hiveMetastore.getPartitionNamesByFilter("database", "table", PARTITION_COLUMN_NAMES, TUPLE_DOMAIN), Optional.of(ImmutableList.of("value")));
    assertEquals(hiveMetastore.getPartitionsByNames(TABLE, ImmutableList.of("value")), ImmutableMap.of("value", Optional.of(PARTITION)));
    assertEquals(hiveMetastore.listTablePrivileges("database", "table", Optional.of("owner"), Optional.of(new HivePrincipal(USER, "user"))), ImmutableSet.of(PRIVILEGE_INFO));
    assertEquals(hiveMetastore.listRoles(), ImmutableSet.of("role"));
    assertEquals(hiveMetastore.listRoleGrants(new HivePrincipal(USER, "user")), ImmutableSet.of(ROLE_GRANT));
    assertEquals(hiveMetastore.listGrantedPrincipals("role"), ImmutableSet.of(ROLE_GRANT));
}
Also used : HivePrincipal(io.trino.plugin.hive.metastore.HivePrincipal)

Aggregations

HivePrincipal (io.trino.plugin.hive.metastore.HivePrincipal)18 RoleGrant (io.trino.spi.security.RoleGrant)9 ImmutableSet (com.google.common.collect.ImmutableSet)7 ImmutableSet.toImmutableSet (com.google.common.collect.ImmutableSet.toImmutableSet)7 HivePrivilegeInfo (io.trino.plugin.hive.metastore.HivePrivilegeInfo)7 TrinoException (io.trino.spi.TrinoException)6 Database (io.trino.plugin.hive.metastore.Database)4 OWNERSHIP (io.trino.plugin.hive.metastore.HivePrivilegeInfo.HivePrivilege.OWNERSHIP)4 Table (io.trino.plugin.hive.metastore.Table)4 SchemaTableName (io.trino.spi.connector.SchemaTableName)4 HashSet (java.util.HashSet)4 HivePrivilege (io.trino.plugin.hive.metastore.HivePrivilegeInfo.HivePrivilege)3 DELETE (io.trino.plugin.hive.metastore.HivePrivilegeInfo.HivePrivilege.DELETE)3 INSERT (io.trino.plugin.hive.metastore.HivePrivilegeInfo.HivePrivilege.INSERT)3 SELECT (io.trino.plugin.hive.metastore.HivePrivilegeInfo.HivePrivilege.SELECT)3 UPDATE (io.trino.plugin.hive.metastore.HivePrivilegeInfo.HivePrivilege.UPDATE)3 HiveUtil.isIcebergTable (io.trino.plugin.hive.util.HiveUtil.isIcebergTable)3 NOT_SUPPORTED (io.trino.spi.StandardErrorCode.NOT_SUPPORTED)3 ConnectorIdentity (io.trino.spi.security.ConnectorIdentity)3 ROLE (io.trino.spi.security.PrincipalType.ROLE)3