use of io.trino.spi.connector.CatalogSchemaName in project trino by trinodb.
the class DenyTask method executeDenyOnSchema.
private static void executeDenyOnSchema(Session session, Deny statement, Metadata metadata, AccessControl accessControl) {
CatalogSchemaName schemaName = createCatalogSchemaName(session, statement, Optional.of(statement.getName()));
if (!metadata.schemaExists(session, schemaName)) {
throw semanticException(SCHEMA_NOT_FOUND, statement, "Schema '%s' does not exist", schemaName);
}
Set<Privilege> privileges = parseStatementPrivileges(statement);
for (Privilege privilege : privileges) {
accessControl.checkCanDenySchemaPrivilege(session.toSecurityContext(), privilege, schemaName, createPrincipal(statement.getGrantee()));
}
metadata.denySchemaPrivileges(session, schemaName, privileges, createPrincipal(statement.getGrantee()));
}
use of io.trino.spi.connector.CatalogSchemaName in project trino by trinodb.
the class RevokeTask method executeRevokeOnSchema.
private void executeRevokeOnSchema(Session session, Revoke statement) {
CatalogSchemaName schemaName = createCatalogSchemaName(session, statement, Optional.of(statement.getName()));
if (!metadata.schemaExists(session, schemaName)) {
throw semanticException(SCHEMA_NOT_FOUND, statement, "Schema '%s' does not exist", schemaName);
}
Set<Privilege> privileges = parseStatementPrivileges(statement);
for (Privilege privilege : privileges) {
accessControl.checkCanRevokeSchemaPrivilege(session.toSecurityContext(), privilege, schemaName, createPrincipal(statement.getGrantee()), statement.isGrantOptionFor());
}
metadata.revokeSchemaPrivileges(session, schemaName, privileges, createPrincipal(statement.getGrantee()), statement.isGrantOptionFor());
}
use of io.trino.spi.connector.CatalogSchemaName in project trino by trinodb.
the class DropSchemaTask method execute.
@Override
public ListenableFuture<Void> execute(DropSchema statement, QueryStateMachine stateMachine, List<Expression> parameters, WarningCollector warningCollector) {
if (statement.isCascade()) {
throw new TrinoException(NOT_SUPPORTED, "CASCADE is not yet supported for DROP SCHEMA");
}
Session session = stateMachine.getSession();
CatalogSchemaName schema = createCatalogSchemaName(session, statement, Optional.of(statement.getSchemaName()));
if (!metadata.schemaExists(session, schema)) {
if (!statement.isExists()) {
throw semanticException(SCHEMA_NOT_FOUND, statement, "Schema '%s' does not exist", schema);
}
return immediateVoidFuture();
}
if (!isSchemaEmpty(session, schema, metadata)) {
throw semanticException(SCHEMA_NOT_EMPTY, statement, "Cannot drop non-empty schema '%s'", schema.getSchemaName());
}
accessControl.checkCanDropSchema(session.toSecurityContext(), schema);
metadata.dropSchema(session, schema);
return immediateVoidFuture();
}
use of io.trino.spi.connector.CatalogSchemaName in project trino by trinodb.
the class GrantTask method executeGrantOnSchema.
private void executeGrantOnSchema(Session session, Grant statement) {
CatalogSchemaName schemaName = createCatalogSchemaName(session, statement, Optional.of(statement.getName()));
if (!metadata.schemaExists(session, schemaName)) {
throw semanticException(SCHEMA_NOT_FOUND, statement, "Schema '%s' does not exist", schemaName);
}
Set<Privilege> privileges = parseStatementPrivileges(statement);
for (Privilege privilege : privileges) {
accessControl.checkCanGrantSchemaPrivilege(session.toSecurityContext(), privilege, schemaName, createPrincipal(statement.getGrantee()), statement.isWithGrantOption());
}
metadata.grantSchemaPrivileges(session, schemaName, privileges, createPrincipal(statement.getGrantee()), statement.isWithGrantOption());
}
use of io.trino.spi.connector.CatalogSchemaName in project trino by trinodb.
the class TestDenyOnSchema method testValidDenySchema.
@Test(dataProvider = "privileges")
public void testValidDenySchema(String privilege) {
String username = randomUsername();
denyCalled = false;
expectedSchemaName = new CatalogSchemaName("local", "default");
if (privilege.equalsIgnoreCase("all privileges")) {
expectedPrivileges = ImmutableSet.copyOf(Privilege.values());
} else {
expectedPrivileges = ImmutableSet.of(Privilege.valueOf(privilege.toUpperCase(ROOT)));
}
expectedGrantee = new TrinoPrincipal(USER, username);
queryRunner.execute(admin, format("DENY %s ON SCHEMA default TO %s", privilege, username));
assertThat(denyCalled).isTrue();
}
Aggregations