use of com.facebook.presto.spi.security.SelectedRole in project presto by prestodb.
the class TestHiveIntegrationSmokeTest method testSchemaOperations.
@Test
public void testSchemaOperations() {
Session admin = Session.builder(getQueryRunner().getDefaultSession()).setIdentity(new Identity("hive", Optional.empty(), ImmutableMap.of("hive", new SelectedRole(SelectedRole.Type.ROLE, Optional.of("admin"))), ImmutableMap.of(), ImmutableMap.of())).build();
assertUpdate(admin, "CREATE SCHEMA new_schema");
assertUpdate(admin, "CREATE TABLE new_schema.test (x bigint)");
assertQueryFails(admin, "DROP SCHEMA new_schema", "Schema not empty: new_schema");
assertUpdate(admin, "DROP TABLE new_schema.test");
assertUpdate(admin, "DROP SCHEMA new_schema");
}
use of com.facebook.presto.spi.security.SelectedRole in project presto by prestodb.
the class Session method beginTransactionId.
public Session beginTransactionId(TransactionId transactionId, TransactionManager transactionManager, AccessControl accessControl) {
requireNonNull(transactionId, "transactionId is null");
checkArgument(!this.transactionId.isPresent(), "Session already has an active transaction");
requireNonNull(transactionManager, "transactionManager is null");
requireNonNull(accessControl, "accessControl is null");
for (Entry<String, String> property : systemProperties.entrySet()) {
// verify permissions
accessControl.checkCanSetSystemSessionProperty(identity, context, property.getKey());
// validate session property value
sessionPropertyManager.validateSystemSessionProperty(property.getKey(), property.getValue());
}
// Now that there is a transaction, the catalog name can be resolved to a connector, and the catalog properties can be validated
ImmutableMap.Builder<ConnectorId, Map<String, String>> connectorProperties = ImmutableMap.builder();
for (Entry<String, Map<String, String>> catalogEntry : unprocessedCatalogProperties.entrySet()) {
String catalogName = catalogEntry.getKey();
Map<String, String> catalogProperties = catalogEntry.getValue();
if (catalogProperties.isEmpty()) {
continue;
}
ConnectorId connectorId = transactionManager.getOptionalCatalogMetadata(transactionId, catalogName).orElseThrow(() -> new PrestoException(NOT_FOUND, "Session property catalog does not exist: " + catalogName)).getConnectorId();
for (Entry<String, String> property : catalogProperties.entrySet()) {
// verify permissions
accessControl.checkCanSetCatalogSessionProperty(transactionId, identity, context, catalogName, property.getKey());
// validate session property value
sessionPropertyManager.validateCatalogSessionProperty(connectorId, catalogName, property.getKey(), property.getValue());
}
connectorProperties.put(connectorId, catalogProperties);
}
ImmutableMap.Builder<String, SelectedRole> roles = ImmutableMap.builder();
for (Entry<String, SelectedRole> entry : identity.getRoles().entrySet()) {
String catalogName = entry.getKey();
SelectedRole role = entry.getValue();
ConnectorId connectorId = transactionManager.getOptionalCatalogMetadata(transactionId, catalogName).orElseThrow(() -> new PrestoException(NOT_FOUND, "Catalog does not exist: " + catalogName)).getConnectorId();
if (role.getType() == SelectedRole.Type.ROLE) {
accessControl.checkCanSetRole(transactionId, identity, context, role.getRole().get(), catalogName);
}
roles.put(connectorId.getCatalogName(), role);
String informationSchemaCatalogName = createInformationSchemaConnectorId(connectorId).getCatalogName();
if (transactionManager.getCatalogNames(transactionId).containsKey(informationSchemaCatalogName)) {
roles.put(createInformationSchemaConnectorId(connectorId).getCatalogName(), role);
}
String systemTablesCatalogName = createSystemTablesConnectorId(connectorId).getCatalogName();
if (transactionManager.getCatalogNames(transactionId).containsKey(systemTablesCatalogName)) {
roles.put(createSystemTablesConnectorId(connectorId).getCatalogName(), role);
}
}
return new Session(queryId, Optional.of(transactionId), clientTransactionSupport, new Identity(identity.getUser(), identity.getPrincipal(), roles.build(), identity.getExtraCredentials(), identity.getExtraAuthenticators()), source, catalog, schema, traceToken, timeZoneKey, locale, remoteUserAddress, userAgent, clientInfo, clientTags, resourceEstimates, startTime, systemProperties, connectorProperties.build(), ImmutableMap.of(), sessionPropertyManager, preparedStatements, sessionFunctions, tracer);
}
Aggregations