use of com.facebook.presto.spi.security.GrantInfo in project presto by prestodb.
the class HiveMetadata method buildGrants.
private List<GrantInfo> buildGrants(ConnectorSession session, SchemaTableName tableName, PrestoPrincipal principal) {
ImmutableList.Builder<GrantInfo> result = ImmutableList.builder();
MetastoreContext metastoreContext = getMetastoreContext(session);
Set<HivePrivilegeInfo> hivePrivileges = metastore.listTablePrivileges(metastoreContext, tableName.getSchemaName(), tableName.getTableName(), principal);
for (HivePrivilegeInfo hivePrivilege : hivePrivileges) {
Set<PrivilegeInfo> prestoPrivileges = hivePrivilege.toPrivilegeInfo();
for (PrivilegeInfo prestoPrivilege : prestoPrivileges) {
GrantInfo grant = new GrantInfo(prestoPrivilege, hivePrivilege.getGrantee(), tableName, Optional.of(hivePrivilege.getGrantor()), Optional.empty());
result.add(grant);
}
}
return result.build();
}
use of com.facebook.presto.spi.security.GrantInfo in project presto by prestodb.
the class HiveMetadata method listTablePrivileges.
@Override
public List<GrantInfo> listTablePrivileges(ConnectorSession session, SchemaTablePrefix schemaTablePrefix) {
MetastoreContext metastoreContext = getMetastoreContext(session);
Set<PrestoPrincipal> principals = listEnabledPrincipals(metastore, session.getIdentity(), metastoreContext).collect(toImmutableSet());
boolean isAdminRoleSet = hasAdminRole(principals);
ImmutableList.Builder<GrantInfo> result = ImmutableList.builder();
for (SchemaTableName tableName : listTables(session, schemaTablePrefix)) {
if (isAdminRoleSet) {
result.addAll(buildGrants(session, tableName, null));
} else {
for (PrestoPrincipal grantee : principals) {
result.addAll(buildGrants(session, tableName, grantee));
}
}
}
return result.build();
}
use of com.facebook.presto.spi.security.GrantInfo in project presto by prestodb.
the class MetadataManager method listTablePrivileges.
@Override
public List<GrantInfo> listTablePrivileges(Session session, QualifiedTablePrefix prefix) {
requireNonNull(prefix, "prefix is null");
SchemaTablePrefix tablePrefix = prefix.asSchemaTablePrefix();
Optional<CatalogMetadata> catalog = getOptionalCatalogMetadata(session, prefix.getCatalogName());
ImmutableSet.Builder<GrantInfo> grantInfos = ImmutableSet.builder();
if (catalog.isPresent()) {
CatalogMetadata catalogMetadata = catalog.get();
ConnectorSession connectorSession = session.toConnectorSession(catalogMetadata.getConnectorId());
for (ConnectorId connectorId : catalogMetadata.listConnectorIds()) {
ConnectorMetadata metadata = catalogMetadata.getMetadataFor(connectorId);
grantInfos.addAll(metadata.listTablePrivileges(connectorSession, tablePrefix));
}
}
return ImmutableList.copyOf(grantInfos.build());
}
Aggregations