Search in sources :

Example 1 with PrincipalType

use of io.trino.spi.security.PrincipalType in project trino by trinodb.

the class ThriftMetastoreUtil method fromMetastoreApiDatabase.

public static Database fromMetastoreApiDatabase(org.apache.hadoop.hive.metastore.api.Database database) {
    String ownerName = "PUBLIC";
    PrincipalType ownerType = ROLE;
    if (database.getOwnerName() != null) {
        ownerName = database.getOwnerName();
        ownerType = fromMetastoreApiPrincipalType(database.getOwnerType());
    }
    Map<String, String> parameters = database.getParameters();
    if (parameters == null) {
        parameters = ImmutableMap.of();
    }
    return Database.builder().setDatabaseName(database.getName()).setLocation(Optional.ofNullable(database.getLocationUri())).setOwnerName(Optional.of(ownerName)).setOwnerType(Optional.of(ownerType)).setComment(Optional.ofNullable(database.getDescription())).setParameters(parameters).build();
}
Also used : PrincipalType(io.trino.spi.security.PrincipalType)

Example 2 with PrincipalType

use of io.trino.spi.security.PrincipalType in project trino by trinodb.

the class SqlStandardAccessControlMetadata method getRoleGrantsByGrantees.

private Set<RoleGrant> getRoleGrantsByGrantees(Set<String> grantees, OptionalLong limit) {
    ImmutableSet.Builder<RoleGrant> roleGrants = ImmutableSet.builder();
    int count = 0;
    for (String grantee : grantees) {
        for (PrincipalType type : new PrincipalType[] { USER, ROLE }) {
            if (limit.isPresent() && count >= limit.getAsLong()) {
                return roleGrants.build();
            }
            for (RoleGrant grant : metastore.listRoleGrants(new HivePrincipal(type, grantee))) {
                // Filter out the "public" role since it is not explicitly granted in Hive.
                if (PUBLIC_ROLE_NAME.equals(grant.getRoleName())) {
                    continue;
                }
                count++;
                roleGrants.add(grant);
            }
        }
    }
    return roleGrants.build();
}
Also used : RoleGrant(io.trino.spi.security.RoleGrant) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) ImmutableSet(com.google.common.collect.ImmutableSet) HivePrincipal(io.trino.plugin.hive.metastore.HivePrincipal) PrincipalType(io.trino.spi.security.PrincipalType)

Aggregations

PrincipalType (io.trino.spi.security.PrincipalType)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 ImmutableSet.toImmutableSet (com.google.common.collect.ImmutableSet.toImmutableSet)1 HivePrincipal (io.trino.plugin.hive.metastore.HivePrincipal)1 RoleGrant (io.trino.spi.security.RoleGrant)1