use of io.prestosql.spi.security.GrantInfo in project hetu-core by openlookeng.
the class MetadataManager method listTablePrivileges.
@Override
public List<GrantInfo> listTablePrivileges(Session session, QualifiedTablePrefix prefix) {
requireNonNull(prefix, "prefix is null");
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.getCatalogName());
List<CatalogName> connectorIds = prefix.asQualifiedObjectName().map(qualifiedTableName -> singletonList(catalogMetadata.getConnectorId(session, qualifiedTableName))).orElseGet(catalogMetadata::listConnectorIds);
for (CatalogName catalogName : connectorIds) {
ConnectorMetadata metadata = catalogMetadata.getMetadataFor(catalogName);
grantInfos.addAll(metadata.listTablePrivileges(connectorSession, prefix.asSchemaTablePrefix()));
}
}
return ImmutableList.copyOf(grantInfos.build());
}
use of io.prestosql.spi.security.GrantInfo in project hetu-core by openlookeng.
the class SqlStandardAccessControlMetadata method buildGrants.
private List<GrantInfo> buildGrants(SchemaTableName tableName, HivePrincipal principal) {
ImmutableList.Builder<GrantInfo> result = ImmutableList.builder();
Set<HivePrivilegeInfo> hivePrivileges = metastore.listTablePrivileges(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().toPrestoPrincipal(), tableName, Optional.of(hivePrivilege.getGrantor().toPrestoPrincipal()), Optional.empty());
result.add(grant);
}
}
return result.build();
}
use of io.prestosql.spi.security.GrantInfo in project boostkit-bigdata by kunpengcompute.
the class SqlStandardAccessControlMetadata method listTablePrivileges.
@Override
public List<GrantInfo> listTablePrivileges(ConnectorSession session, List<SchemaTableName> tableNames) {
Set<HivePrincipal> principals = listEnabledPrincipals(metastore, session.getIdentity()).collect(toImmutableSet());
boolean isAdminRoleSet = hasAdminRole(principals);
ImmutableList.Builder<GrantInfo> result = ImmutableList.builder();
for (SchemaTableName tableName : tableNames) {
if (isAdminRoleSet) {
result.addAll(buildGrants(tableName, null));
} else {
for (HivePrincipal grantee : principals) {
result.addAll(buildGrants(tableName, grantee));
}
}
}
return result.build();
}
use of io.prestosql.spi.security.GrantInfo in project hetu-core by openlookeng.
the class SqlStandardAccessControlMetadata method listTablePrivileges.
@Override
public List<GrantInfo> listTablePrivileges(ConnectorSession session, List<SchemaTableName> tableNames) {
Set<HivePrincipal> principals = listEnabledPrincipals(metastore, session.getIdentity()).collect(toImmutableSet());
boolean isAdminRoleSet = hasAdminRole(principals);
ImmutableList.Builder<GrantInfo> result = ImmutableList.builder();
for (SchemaTableName tableName : tableNames) {
if (isAdminRoleSet) {
result.addAll(buildGrants(tableName, null));
} else {
for (HivePrincipal grantee : principals) {
result.addAll(buildGrants(tableName, grantee));
}
}
}
return result.build();
}
use of io.prestosql.spi.security.GrantInfo in project boostkit-bigdata by kunpengcompute.
the class SqlStandardAccessControlMetadata method buildGrants.
private List<GrantInfo> buildGrants(SchemaTableName tableName, HivePrincipal principal) {
ImmutableList.Builder<GrantInfo> result = ImmutableList.builder();
Set<HivePrivilegeInfo> hivePrivileges = metastore.listTablePrivileges(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().toPrestoPrincipal(), tableName, Optional.of(hivePrivilege.getGrantor().toPrestoPrincipal()), Optional.empty());
result.add(grant);
}
}
return result.build();
}
Aggregations