Search in sources :

Example 1 with ROLE

use of io.prestosql.spi.security.PrincipalType.ROLE in project hetu-core by openlookeng.

the class ThriftMetastoreUtil method listApplicableTablePrivileges.

public static Stream<HivePrivilegeInfo> listApplicableTablePrivileges(SemiTransactionalHiveMetastore metastore, String databaseName, String tableName, String user) {
    HivePrincipal userPrincipal = new HivePrincipal(USER, user);
    Stream<HivePrincipal> principals = Stream.concat(Stream.of(userPrincipal), listApplicableRoles(metastore, userPrincipal).map(role -> new HivePrincipal(ROLE, role)));
    return listTablePrivileges(metastore, databaseName, tableName, principals);
}
Also used : NUMBER_OF_TRUE_VALUES(io.prestosql.spi.statistics.ColumnStatisticType.NUMBER_OF_TRUE_VALUES) Arrays(java.util.Arrays) StorageFormat(io.prestosql.plugin.hive.metastore.StorageFormat) RoleGrant(io.prestosql.spi.security.RoleGrant) SerDeInfo(org.apache.hadoop.hive.metastore.api.SerDeInfo) BigDecimal(java.math.BigDecimal) BooleanColumnStatsData(org.apache.hadoop.hive.metastore.api.BooleanColumnStatsData) Math.round(java.lang.Math.round) Map(java.util.Map) RowType(io.prestosql.spi.type.RowType) DoubleColumnStatsData(org.apache.hadoop.hive.metastore.api.DoubleColumnStatsData) BigInteger(java.math.BigInteger) ENGLISH(java.util.Locale.ENGLISH) Chars.isCharType(io.prestosql.spi.type.Chars.isCharType) HiveErrorCode(io.prestosql.plugin.hive.HiveErrorCode) Longs(com.google.common.primitives.Longs) DecimalColumnStatsData(org.apache.hadoop.hive.metastore.api.DecimalColumnStatsData) ColumnStatisticsData.decimalStats(org.apache.hadoop.hive.metastore.api.ColumnStatisticsData.decimalStats) MAX_VALUE(io.prestosql.spi.statistics.ColumnStatisticType.MAX_VALUE) Set(java.util.Set) TIMESTAMP(io.prestosql.spi.type.TimestampType.TIMESTAMP) Stream(java.util.stream.Stream) Table(io.prestosql.plugin.hive.metastore.Table) Date(org.apache.hadoop.hive.metastore.api.Date) Database(io.prestosql.plugin.hive.metastore.Database) Partition(io.prestosql.plugin.hive.metastore.Partition) MIN_VALUE(io.prestosql.spi.statistics.ColumnStatisticType.MIN_VALUE) MapType(io.prestosql.spi.type.MapType) OptionalLong(java.util.OptionalLong) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) AVRO(io.prestosql.plugin.hive.HiveStorageFormat.AVRO) DOUBLE(io.prestosql.spi.type.DoubleType.DOUBLE) SemiTransactionalHiveMetastore(io.prestosql.plugin.hive.metastore.SemiTransactionalHiveMetastore) 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) AbstractIterator(com.google.common.collect.AbstractIterator) USER(io.prestosql.spi.security.PrincipalType.USER) MAX_VALUE_SIZE_IN_BYTES(io.prestosql.spi.statistics.ColumnStatisticType.MAX_VALUE_SIZE_IN_BYTES) PrincipalPrivileges(io.prestosql.plugin.hive.metastore.PrincipalPrivileges) HiveColumnStatistics(io.prestosql.plugin.hive.metastore.HiveColumnStatistics) StringColumnStatsData(org.apache.hadoop.hive.metastore.api.StringColumnStatsData) VARBINARY(io.prestosql.spi.type.VarbinaryType.VARBINARY) Strings.emptyToNull(com.google.common.base.Strings.emptyToNull) ColumnStatisticsData.longStats(org.apache.hadoop.hive.metastore.api.ColumnStatisticsData.longStats) DateColumnStatsData(org.apache.hadoop.hive.metastore.api.DateColumnStatsData) ArrayDeque(java.util.ArrayDeque) ColumnStatisticsData.stringStats(org.apache.hadoop.hive.metastore.api.ColumnStatisticsData.stringStats) PrestoPrincipal(io.prestosql.spi.security.PrestoPrincipal) PrincipalType(io.prestosql.spi.security.PrincipalType) HiveBasicStatistics(io.prestosql.plugin.hive.HiveBasicStatistics) Varchars.isVarcharType(io.prestosql.spi.type.Varchars.isVarcharType) ColumnStatisticsData.booleanStats(org.apache.hadoop.hive.metastore.api.ColumnStatisticsData.booleanStats) DecimalType(io.prestosql.spi.type.DecimalType) RolePrincipalGrant(org.apache.hadoop.hive.metastore.api.RolePrincipalGrant) ByteBuffer(java.nio.ByteBuffer) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) Locale(java.util.Locale) ColumnStatisticsData.doubleStats(org.apache.hadoop.hive.metastore.api.ColumnStatisticsData.doubleStats) BOOLEAN(io.prestosql.spi.type.BooleanType.BOOLEAN) Type(io.prestosql.spi.type.Type) PrimitiveTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.PrimitiveTypeInfo) StorageDescriptor(org.apache.hadoop.hive.metastore.api.StorageDescriptor) BIGINT(io.prestosql.spi.type.BigintType.BIGINT) PrestoException(io.prestosql.spi.PrestoException) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) Predicate(java.util.function.Predicate) ArrayType(io.prestosql.spi.type.ArrayType) 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) SelectedRole(io.prestosql.spi.security.SelectedRole) TINYINT(io.prestosql.spi.type.TinyintType.TINYINT) Streams(com.google.common.collect.Streams) HiveType(io.prestosql.plugin.hive.HiveType) String.format(java.lang.String.format) NUMBER_OF_DISTINCT_VALUES(io.prestosql.spi.statistics.ColumnStatisticType.NUMBER_OF_DISTINCT_VALUES) List(java.util.List) LocalDate(java.time.LocalDate) Optional(java.util.Optional) Queue(java.util.Queue) HiveBucketProperty(io.prestosql.plugin.hive.HiveBucketProperty) Strings.nullToEmpty(com.google.common.base.Strings.nullToEmpty) OptionalDouble(java.util.OptionalDouble) AVRO_SCHEMA_URL_KEY(io.prestosql.plugin.hive.HiveMetadata.AVRO_SCHEMA_URL_KEY) Shorts(com.google.common.primitives.Shorts) INTEGER(io.prestosql.spi.type.IntegerType.INTEGER) HivePrincipal(io.prestosql.plugin.hive.metastore.HivePrincipal) Function(java.util.function.Function) ColumnStatisticType(io.prestosql.spi.statistics.ColumnStatisticType) HashSet(java.util.HashSet) ROLE(io.prestosql.spi.security.PrincipalType.ROLE) ColumnStatisticsData.dateStats(org.apache.hadoop.hive.metastore.api.ColumnStatisticsData.dateStats) BinaryColumnStatsData(org.apache.hadoop.hive.metastore.api.BinaryColumnStatsData) HivePrivilegeInfo(io.prestosql.plugin.hive.metastore.HivePrivilegeInfo) Objects.requireNonNull(java.util.Objects.requireNonNull) DATE(io.prestosql.spi.type.DateType.DATE) REAL(io.prestosql.spi.type.RealType.REAL) TOTAL_SIZE_IN_BYTES(io.prestosql.spi.statistics.ColumnStatisticType.TOTAL_SIZE_IN_BYTES) NUMBER_OF_NON_NULL_VALUES(io.prestosql.spi.statistics.ColumnStatisticType.NUMBER_OF_NON_NULL_VALUES) CSV(io.prestosql.plugin.hive.HiveStorageFormat.CSV) PartitionWithStatistics(io.prestosql.plugin.hive.metastore.PartitionWithStatistics) ConnectorIdentity(io.prestosql.spi.security.ConnectorIdentity) 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) Storage(io.prestosql.plugin.hive.metastore.Storage) Collectors.toList(java.util.stream.Collectors.toList) SMALLINT(io.prestosql.spi.type.SmallintType.SMALLINT) Column(io.prestosql.plugin.hive.metastore.Column) HivePrincipal(io.prestosql.plugin.hive.metastore.HivePrincipal)

Example 2 with ROLE

use of io.prestosql.spi.security.PrincipalType.ROLE in project hetu-core by openlookeng.

the class RevokeRolesTask method execute.

@Override
public ListenableFuture<?> execute(RevokeRoles statement, TransactionManager transactionManager, Metadata metadata, AccessControl accessControl, QueryStateMachine stateMachine, List<Expression> parameters, HeuristicIndexerManager heuristicIndexerManager) {
    Session session = stateMachine.getSession();
    Set<String> roles = statement.getRoles().stream().map(role -> role.getValue().toLowerCase(Locale.ENGLISH)).collect(toImmutableSet());
    Set<PrestoPrincipal> grantees = statement.getGrantees().stream().map(MetadataUtil::createPrincipal).collect(toImmutableSet());
    boolean adminOptionFor = statement.isAdminOptionFor();
    Optional<PrestoPrincipal> grantor = statement.getGrantor().map(specification -> createPrincipal(session, specification));
    String catalog = createCatalogName(session, statement);
    Set<String> availableRoles = metadata.listRoles(session, catalog);
    Set<String> specifiedRoles = new LinkedHashSet<>();
    specifiedRoles.addAll(roles);
    grantees.stream().filter(principal -> principal.getType() == ROLE).map(PrestoPrincipal::getName).forEach(specifiedRoles::add);
    if (grantor.isPresent() && grantor.get().getType() == ROLE) {
        specifiedRoles.add(grantor.get().getName());
    }
    for (String role : specifiedRoles) {
        if (!availableRoles.contains(role)) {
            throw new SemanticException(MISSING_ROLE, statement, "Role '%s' does not exist", role);
        }
    }
    accessControl.checkCanRevokeRoles(session.getRequiredTransactionId(), session.getIdentity(), roles, grantees, adminOptionFor, grantor, catalog);
    metadata.revokeRoles(session, roles, grantees, adminOptionFor, grantor, catalog);
    return immediateFuture(null);
}
Also used : HeuristicIndexerManager(io.prestosql.heuristicindex.HeuristicIndexerManager) Futures.immediateFuture(com.google.common.util.concurrent.Futures.immediateFuture) AccessControl(io.prestosql.security.AccessControl) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) MetadataUtil.createPrincipal(io.prestosql.metadata.MetadataUtil.createPrincipal) TransactionManager(io.prestosql.transaction.TransactionManager) Set(java.util.Set) Metadata(io.prestosql.metadata.Metadata) SemanticException(io.prestosql.sql.analyzer.SemanticException) List(java.util.List) ROLE(io.prestosql.spi.security.PrincipalType.ROLE) MetadataUtil.createCatalogName(io.prestosql.metadata.MetadataUtil.createCatalogName) Locale(java.util.Locale) MetadataUtil(io.prestosql.metadata.MetadataUtil) MISSING_ROLE(io.prestosql.sql.analyzer.SemanticErrorCode.MISSING_ROLE) Session(io.prestosql.Session) Optional(java.util.Optional) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) RevokeRoles(io.prestosql.sql.tree.RevokeRoles) PrestoPrincipal(io.prestosql.spi.security.PrestoPrincipal) Expression(io.prestosql.sql.tree.Expression) LinkedHashSet(java.util.LinkedHashSet) LinkedHashSet(java.util.LinkedHashSet) PrestoPrincipal(io.prestosql.spi.security.PrestoPrincipal) Session(io.prestosql.Session) SemanticException(io.prestosql.sql.analyzer.SemanticException)

Example 3 with ROLE

use of io.prestosql.spi.security.PrincipalType.ROLE in project hetu-core by openlookeng.

the class GrantRolesTask method execute.

@Override
public ListenableFuture<?> execute(GrantRoles statement, TransactionManager transactionManager, Metadata metadata, AccessControl accessControl, QueryStateMachine stateMachine, List<Expression> parameters, HeuristicIndexerManager heuristicIndexerManager) {
    Session session = stateMachine.getSession();
    Set<String> roles = statement.getRoles().stream().map(role -> role.getValue().toLowerCase(Locale.ENGLISH)).collect(toImmutableSet());
    Set<PrestoPrincipal> grantees = statement.getGrantees().stream().map(MetadataUtil::createPrincipal).collect(toImmutableSet());
    boolean withAdminOption = statement.isWithAdminOption();
    Optional<PrestoPrincipal> grantor = statement.getGrantor().map(specification -> createPrincipal(session, specification));
    String catalog = createCatalogName(session, statement);
    Set<String> availableRoles = metadata.listRoles(session, catalog);
    Set<String> specifiedRoles = new LinkedHashSet<>();
    specifiedRoles.addAll(roles);
    grantees.stream().filter(principal -> principal.getType() == ROLE).map(PrestoPrincipal::getName).forEach(specifiedRoles::add);
    if (grantor.isPresent() && grantor.get().getType() == ROLE) {
        specifiedRoles.add(grantor.get().getName());
    }
    for (String role : specifiedRoles) {
        if (!availableRoles.contains(role)) {
            throw new SemanticException(MISSING_ROLE, statement, "Role '%s' does not exist", role);
        }
    }
    accessControl.checkCanGrantRoles(session.getRequiredTransactionId(), session.getIdentity(), roles, grantees, withAdminOption, grantor, catalog);
    metadata.grantRoles(session, roles, grantees, withAdminOption, grantor, catalog);
    return immediateFuture(null);
}
Also used : HeuristicIndexerManager(io.prestosql.heuristicindex.HeuristicIndexerManager) GrantRoles(io.prestosql.sql.tree.GrantRoles) Futures.immediateFuture(com.google.common.util.concurrent.Futures.immediateFuture) AccessControl(io.prestosql.security.AccessControl) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) MetadataUtil.createPrincipal(io.prestosql.metadata.MetadataUtil.createPrincipal) TransactionManager(io.prestosql.transaction.TransactionManager) Set(java.util.Set) Metadata(io.prestosql.metadata.Metadata) SemanticException(io.prestosql.sql.analyzer.SemanticException) List(java.util.List) ROLE(io.prestosql.spi.security.PrincipalType.ROLE) MetadataUtil.createCatalogName(io.prestosql.metadata.MetadataUtil.createCatalogName) Locale(java.util.Locale) MetadataUtil(io.prestosql.metadata.MetadataUtil) MISSING_ROLE(io.prestosql.sql.analyzer.SemanticErrorCode.MISSING_ROLE) Session(io.prestosql.Session) Optional(java.util.Optional) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) PrestoPrincipal(io.prestosql.spi.security.PrestoPrincipal) Expression(io.prestosql.sql.tree.Expression) LinkedHashSet(java.util.LinkedHashSet) LinkedHashSet(java.util.LinkedHashSet) PrestoPrincipal(io.prestosql.spi.security.PrestoPrincipal) Session(io.prestosql.Session) SemanticException(io.prestosql.sql.analyzer.SemanticException)

Aggregations

ImmutableSet.toImmutableSet (com.google.common.collect.ImmutableSet.toImmutableSet)3 PrestoPrincipal (io.prestosql.spi.security.PrestoPrincipal)3 ROLE (io.prestosql.spi.security.PrincipalType.ROLE)3 Futures.immediateFuture (com.google.common.util.concurrent.Futures.immediateFuture)2 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)2 Session (io.prestosql.Session)2 HeuristicIndexerManager (io.prestosql.heuristicindex.HeuristicIndexerManager)2 Metadata (io.prestosql.metadata.Metadata)2 MetadataUtil (io.prestosql.metadata.MetadataUtil)2 MetadataUtil.createCatalogName (io.prestosql.metadata.MetadataUtil.createCatalogName)2 MetadataUtil.createPrincipal (io.prestosql.metadata.MetadataUtil.createPrincipal)2 AccessControl (io.prestosql.security.AccessControl)2 MISSING_ROLE (io.prestosql.sql.analyzer.SemanticErrorCode.MISSING_ROLE)2 SemanticException (io.prestosql.sql.analyzer.SemanticException)2 Expression (io.prestosql.sql.tree.Expression)2 TransactionManager (io.prestosql.transaction.TransactionManager)2 LinkedHashSet (java.util.LinkedHashSet)2 List (java.util.List)2 Locale (java.util.Locale)2 Optional (java.util.Optional)2