use of io.trino.plugin.hive.metastore.HivePrincipal in project trino by trinodb.
the class TestThriftMetastoreUtil method testListApplicableRoles.
@Test
public void testListApplicableRoles() {
TrinoPrincipal admin = new TrinoPrincipal(USER, "admin");
Multimap<String, String> inheritance = ImmutableMultimap.<String, String>builder().put("a", "b1").put("a", "b2").put("b1", "d").put("b1", "e").put("b2", "d").put("b2", "e").put("d", "u").put("e", "w").build();
assertThat(ThriftMetastoreUtil.listApplicableRoles(new HivePrincipal(ROLE, "a"), principal -> inheritance.get(principal.getName()).stream().map(name -> new RoleGrant(admin, name, false)).collect(toImmutableSet()))).containsOnly(new RoleGrant(admin, "b1", false), new RoleGrant(admin, "b2", false), new RoleGrant(admin, "d", false), new RoleGrant(admin, "e", false), new RoleGrant(admin, "u", false), new RoleGrant(admin, "w", false));
}
use of io.trino.plugin.hive.metastore.HivePrincipal in project trino by trinodb.
the class SqlStandardAccessControl method listApplicableTablePrivileges.
private Stream<HivePrivilegeInfo> listApplicableTablePrivileges(ConnectorSecurityContext context, String databaseName, String tableName, ConnectorIdentity identity) {
String user = identity.getUser();
HivePrincipal userPrincipal = new HivePrincipal(USER, user);
Stream<HivePrincipal> principals = Stream.concat(Stream.of(userPrincipal), listApplicableRoles(userPrincipal, hivePrincipal -> metastore.listRoleGrants(context, hivePrincipal)).map(role -> new HivePrincipal(ROLE, role.getRoleName())));
return listTablePrivileges(context, databaseName, tableName, principals);
}
use of io.trino.plugin.hive.metastore.HivePrincipal in project trino by trinodb.
the class SqlStandardAccessControlMetadata method revokeTablePrivileges.
@Override
public void revokeTablePrivileges(ConnectorSession session, SchemaTableName schemaTableName, Set<Privilege> privileges, HivePrincipal grantee, boolean grantOption) {
String schemaName = schemaTableName.getSchemaName();
String tableName = schemaTableName.getTableName();
// Hive does not support the CREATE privilege, so ignore. Normally we would throw
// an error for this, but when the Trino engine sees ALL_PRIVILEGES, it sends the
// enumerated list of privileges instead of an Optional.empty
privileges = privileges.stream().filter(not(Privilege.CREATE::equals)).collect(toImmutableSet());
metastore.revokeTablePrivileges(schemaName, tableName, grantee, new HivePrincipal(USER, session.getUser()), privileges.stream().map(HivePrivilegeInfo::toHivePrivilege).collect(toSet()), grantOption);
}
use of io.trino.plugin.hive.metastore.HivePrincipal in project trino by trinodb.
the class SqlStandardAccessControlMetadata method grantTablePrivileges.
@Override
public void grantTablePrivileges(ConnectorSession session, SchemaTableName schemaTableName, Set<Privilege> privileges, HivePrincipal grantee, boolean grantOption) {
String schemaName = schemaTableName.getSchemaName();
String tableName = schemaTableName.getTableName();
// Hive does not support the CREATE privilege, so ignore. Normally we would throw
// an error for this, but when the Trino engine sees ALL_PRIVILEGES, it sends the
// enumerated list of privileges instead of an Optional.empty
privileges = privileges.stream().filter(not(Privilege.CREATE::equals)).collect(toImmutableSet());
metastore.grantTablePrivileges(schemaName, tableName, grantee, new HivePrincipal(USER, session.getUser()), privileges.stream().map(HivePrivilegeInfo::toHivePrivilege).collect(toSet()), grantOption);
}
use of io.trino.plugin.hive.metastore.HivePrincipal 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