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();
}
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();
}
Aggregations