Search in sources :

Example 21 with CatalogSchemaName

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()));
}
Also used : CatalogSchemaName(io.trino.spi.connector.CatalogSchemaName) MetadataUtil.createCatalogSchemaName(io.trino.metadata.MetadataUtil.createCatalogSchemaName) Privilege(io.trino.spi.security.Privilege)

Example 22 with CatalogSchemaName

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());
}
Also used : CatalogSchemaName(io.trino.spi.connector.CatalogSchemaName) MetadataUtil.createCatalogSchemaName(io.trino.metadata.MetadataUtil.createCatalogSchemaName) Privilege(io.trino.spi.security.Privilege)

Example 23 with CatalogSchemaName

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();
}
Also used : CatalogSchemaName(io.trino.spi.connector.CatalogSchemaName) MetadataUtil.createCatalogSchemaName(io.trino.metadata.MetadataUtil.createCatalogSchemaName) TrinoException(io.trino.spi.TrinoException) Session(io.trino.Session)

Example 24 with CatalogSchemaName

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());
}
Also used : CatalogSchemaName(io.trino.spi.connector.CatalogSchemaName) MetadataUtil.createCatalogSchemaName(io.trino.metadata.MetadataUtil.createCatalogSchemaName) Privilege(io.trino.spi.security.Privilege)

Example 25 with CatalogSchemaName

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();
}
Also used : CatalogSchemaName(io.trino.spi.connector.CatalogSchemaName) TrinoPrincipal(io.trino.spi.security.TrinoPrincipal) Test(org.testng.annotations.Test)

Aggregations

CatalogSchemaName (io.trino.spi.connector.CatalogSchemaName)26 Test (org.testng.annotations.Test)15 SystemAccessControl (io.trino.spi.security.SystemAccessControl)13 TrinoPrincipal (io.trino.spi.security.TrinoPrincipal)11 Session (io.trino.Session)7 MetadataUtil.createCatalogSchemaName (io.trino.metadata.MetadataUtil.createCatalogSchemaName)7 TrinoException (io.trino.spi.TrinoException)5 CatalogSchemaTableName (io.trino.spi.connector.CatalogSchemaTableName)5 List (java.util.List)5 Objects.requireNonNull (java.util.Objects.requireNonNull)5 CatalogName (io.trino.connector.CatalogName)4 SchemaTableName (io.trino.spi.connector.SchemaTableName)4 Privilege (io.trino.spi.security.Privilege)4 Set (java.util.Set)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)3 Metadata (io.trino.metadata.Metadata)3 Optional (java.util.Optional)3 Inject (javax.inject.Inject)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2