All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.facebook.presto.jdbc.internal.spi.connector.ConnectorAccessControl Maven / Gradle / Ivy

There is a newer version: 0.286
Show newest version
/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.facebook.presto.jdbc.internal.spi.connector;

import com.facebook.presto.jdbc.internal.spi.SchemaTableName;
import com.facebook.presto.jdbc.internal.spi.security.AccessControlContext;
import com.facebook.presto.jdbc.internal.spi.security.ConnectorIdentity;
import com.facebook.presto.jdbc.internal.spi.security.PrestoPrincipal;
import com.facebook.presto.jdbc.internal.spi.security.Privilege;

import java.util.Optional;
import java.util.Set;

import static com.facebook.presto.jdbc.internal.spi.security.AccessDeniedException.denyAddColumn;
import static com.facebook.presto.jdbc.internal.spi.security.AccessDeniedException.denyCreateRole;
import static com.facebook.presto.jdbc.internal.spi.security.AccessDeniedException.denyCreateSchema;
import static com.facebook.presto.jdbc.internal.spi.security.AccessDeniedException.denyCreateTable;
import static com.facebook.presto.jdbc.internal.spi.security.AccessDeniedException.denyCreateView;
import static com.facebook.presto.jdbc.internal.spi.security.AccessDeniedException.denyCreateViewWithSelect;
import static com.facebook.presto.jdbc.internal.spi.security.AccessDeniedException.denyDeleteTable;
import static com.facebook.presto.jdbc.internal.spi.security.AccessDeniedException.denyDropColumn;
import static com.facebook.presto.jdbc.internal.spi.security.AccessDeniedException.denyDropRole;
import static com.facebook.presto.jdbc.internal.spi.security.AccessDeniedException.denyDropSchema;
import static com.facebook.presto.jdbc.internal.spi.security.AccessDeniedException.denyDropTable;
import static com.facebook.presto.jdbc.internal.spi.security.AccessDeniedException.denyDropView;
import static com.facebook.presto.jdbc.internal.spi.security.AccessDeniedException.denyGrantRoles;
import static com.facebook.presto.jdbc.internal.spi.security.AccessDeniedException.denyGrantTablePrivilege;
import static com.facebook.presto.jdbc.internal.spi.security.AccessDeniedException.denyInsertTable;
import static com.facebook.presto.jdbc.internal.spi.security.AccessDeniedException.denyRenameColumn;
import static com.facebook.presto.jdbc.internal.spi.security.AccessDeniedException.denyRenameSchema;
import static com.facebook.presto.jdbc.internal.spi.security.AccessDeniedException.denyRenameTable;
import static com.facebook.presto.jdbc.internal.spi.security.AccessDeniedException.denyRevokeRoles;
import static com.facebook.presto.jdbc.internal.spi.security.AccessDeniedException.denyRevokeTablePrivilege;
import static com.facebook.presto.jdbc.internal.spi.security.AccessDeniedException.denySelectColumns;
import static com.facebook.presto.jdbc.internal.spi.security.AccessDeniedException.denySetCatalogSessionProperty;
import static com.facebook.presto.jdbc.internal.spi.security.AccessDeniedException.denySetRole;
import static com.facebook.presto.jdbc.internal.spi.security.AccessDeniedException.denyShowCurrentRoles;
import static com.facebook.presto.jdbc.internal.spi.security.AccessDeniedException.denyShowRoleGrants;
import static com.facebook.presto.jdbc.internal.spi.security.AccessDeniedException.denyShowRoles;
import static com.facebook.presto.jdbc.internal.spi.security.AccessDeniedException.denyShowSchemas;
import static com.facebook.presto.jdbc.internal.spi.security.AccessDeniedException.denyShowTablesMetadata;
import static java.util.Collections.emptySet;

public interface ConnectorAccessControl
{
    /**
     * Check if identity is allowed to create the specified schema in this catalog.
     *
     * @throws com.facebook.presto.jdbc.internal.spi.security.AccessDeniedException if not allowed
     */
    default void checkCanCreateSchema(ConnectorTransactionHandle transactionHandle, ConnectorIdentity identity, AccessControlContext context, String schemaName)
    {
        denyCreateSchema(schemaName);
    }

    /**
     * Check if identity is allowed to drop the specified schema in this catalog.
     *
     * @throws com.facebook.presto.jdbc.internal.spi.security.AccessDeniedException if not allowed
     */
    default void checkCanDropSchema(ConnectorTransactionHandle transactionHandle, ConnectorIdentity identity, AccessControlContext context, String schemaName)
    {
        denyDropSchema(schemaName);
    }

    /**
     * Check if identity is allowed to rename the specified schema in this catalog.
     *
     * @throws com.facebook.presto.jdbc.internal.spi.security.AccessDeniedException if not allowed
     */
    default void checkCanRenameSchema(ConnectorTransactionHandle transactionHandle, ConnectorIdentity identity, AccessControlContext context, String schemaName, String newSchemaName)
    {
        denyRenameSchema(schemaName, newSchemaName);
    }

    /**
     * Check if identity is allowed to execute SHOW SCHEMAS in a catalog.
     * 

* NOTE: This method is only present to give users an error message when listing is not allowed. * The {@link #filterSchemas} method must handle filter all results for unauthorized users, * since there are multiple way to list schemas. * * @throws com.facebook.presto.jdbc.internal.spi.security.AccessDeniedException if not allowed */ default void checkCanShowSchemas(ConnectorTransactionHandle transactionHandle, ConnectorIdentity identity, AccessControlContext context) { denyShowSchemas(); } /** * Filter the list of schemas to those visible to the identity. */ default Set filterSchemas(ConnectorTransactionHandle transactionHandle, ConnectorIdentity identity, AccessControlContext context, Set schemaNames) { return emptySet(); } /** * Check if identity is allowed to create the specified table in this catalog. * * @throws com.facebook.presto.jdbc.internal.spi.security.AccessDeniedException if not allowed */ default void checkCanCreateTable(ConnectorTransactionHandle transactionHandle, ConnectorIdentity identity, AccessControlContext context, SchemaTableName tableName) { denyCreateTable(tableName.toString()); } /** * Check if identity is allowed to drop the specified table in this catalog. * * @throws com.facebook.presto.jdbc.internal.spi.security.AccessDeniedException if not allowed */ default void checkCanDropTable(ConnectorTransactionHandle transactionHandle, ConnectorIdentity identity, AccessControlContext context, SchemaTableName tableName) { denyDropTable(tableName.toString()); } /** * Check if identity is allowed to rename the specified table in this catalog. * * @throws com.facebook.presto.jdbc.internal.spi.security.AccessDeniedException if not allowed */ default void checkCanRenameTable(ConnectorTransactionHandle transactionHandle, ConnectorIdentity identity, AccessControlContext context, SchemaTableName tableName, SchemaTableName newTableName) { denyRenameTable(tableName.toString(), newTableName.toString()); } /** * Check if identity is allowed to show metadata of tables by executing SHOW TABLES, SHOW GRANTS etc. in a catalog. *

* NOTE: This method is only present to give users an error message when listing is not allowed. * The {@link #filterTables} method must filter all results for unauthorized users, * since there are multiple ways to list tables. * * @throws com.facebook.presto.jdbc.internal.spi.security.AccessDeniedException if not allowed */ default void checkCanShowTablesMetadata(ConnectorTransactionHandle transactionHandle, ConnectorIdentity identity, AccessControlContext context, String schemaName) { denyShowTablesMetadata(schemaName); } /** * Filter the list of tables and views to those visible to the identity. */ default Set filterTables(ConnectorTransactionHandle transactionHandle, ConnectorIdentity identity, AccessControlContext context, Set tableNames) { return emptySet(); } /** * Check if identity is allowed to add columns to the specified table in this catalog. * * @throws com.facebook.presto.jdbc.internal.spi.security.AccessDeniedException if not allowed */ default void checkCanAddColumn(ConnectorTransactionHandle transactionHandle, ConnectorIdentity identity, AccessControlContext context, SchemaTableName tableName) { denyAddColumn(tableName.toString()); } /** * Check if identity is allowed to drop columns from the specified table in this catalog. * * @throws com.facebook.presto.jdbc.internal.spi.security.AccessDeniedException if not allowed */ default void checkCanDropColumn(ConnectorTransactionHandle transactionHandle, ConnectorIdentity identity, AccessControlContext context, SchemaTableName tableName) { denyDropColumn(tableName.toString()); } /** * Check if identity is allowed to rename a column in the specified table in this catalog. * * @throws com.facebook.presto.jdbc.internal.spi.security.AccessDeniedException if not allowed */ default void checkCanRenameColumn(ConnectorTransactionHandle transactionHandle, ConnectorIdentity identity, AccessControlContext context, SchemaTableName tableName) { denyRenameColumn(tableName.toString()); } /** * Check if identity is allowed to select from the specified columns in a relation. The column set can be empty. * * @throws com.facebook.presto.jdbc.internal.spi.security.AccessDeniedException if not allowed */ default void checkCanSelectFromColumns(ConnectorTransactionHandle transactionHandle, ConnectorIdentity identity, AccessControlContext context, SchemaTableName tableName, Set columnNames) { denySelectColumns(tableName.toString(), columnNames); } /** * Check if identity is allowed to insert into the specified table in this catalog. * * @throws com.facebook.presto.jdbc.internal.spi.security.AccessDeniedException if not allowed */ default void checkCanInsertIntoTable(ConnectorTransactionHandle transactionHandle, ConnectorIdentity identity, AccessControlContext context, SchemaTableName tableName) { denyInsertTable(tableName.toString()); } /** * Check if identity is allowed to delete from the specified table in this catalog. * * @throws com.facebook.presto.jdbc.internal.spi.security.AccessDeniedException if not allowed */ default void checkCanDeleteFromTable(ConnectorTransactionHandle transactionHandle, ConnectorIdentity identity, AccessControlContext context, SchemaTableName tableName) { denyDeleteTable(tableName.toString()); } /** * Check if identity is allowed to create the specified view in this catalog. * * @throws com.facebook.presto.jdbc.internal.spi.security.AccessDeniedException if not allowed */ default void checkCanCreateView(ConnectorTransactionHandle transactionHandle, ConnectorIdentity identity, AccessControlContext context, SchemaTableName viewName) { denyCreateView(viewName.toString()); } /** * Check if identity is allowed to drop the specified view in this catalog. * * @throws com.facebook.presto.jdbc.internal.spi.security.AccessDeniedException if not allowed */ default void checkCanDropView(ConnectorTransactionHandle transactionHandle, ConnectorIdentity identity, AccessControlContext context, SchemaTableName viewName) { denyDropView(viewName.toString()); } /** * Check if identity is allowed to create a view that selects from the specified columns in a relation. * * @throws com.facebook.presto.jdbc.internal.spi.security.AccessDeniedException if not allowed */ default void checkCanCreateViewWithSelectFromColumns(ConnectorTransactionHandle transactionHandle, ConnectorIdentity identity, AccessControlContext context, SchemaTableName tableName, Set columnNames) { denyCreateViewWithSelect(tableName.toString(), identity); } /** * Check if identity is allowed to set the specified property in this catalog. * * @throws com.facebook.presto.jdbc.internal.spi.security.AccessDeniedException if not allowed */ default void checkCanSetCatalogSessionProperty(ConnectorTransactionHandle transactionHandle, ConnectorIdentity identity, AccessControlContext context, String propertyName) { denySetCatalogSessionProperty(propertyName); } /** * Check if identity is allowed to grant to any other user the specified privilege on the specified table. * * @throws com.facebook.presto.jdbc.internal.spi.security.AccessDeniedException if not allowed */ default void checkCanGrantTablePrivilege(ConnectorTransactionHandle transactionHandle, ConnectorIdentity identity, AccessControlContext context, Privilege privilege, SchemaTableName tableName, PrestoPrincipal grantee, boolean withGrantOption) { denyGrantTablePrivilege(privilege.toString(), tableName.toString()); } /** * Check if identity is allowed to revoke the specified privilege on the specified table from any user. * * @throws com.facebook.presto.jdbc.internal.spi.security.AccessDeniedException if not allowed */ default void checkCanRevokeTablePrivilege(ConnectorTransactionHandle transactionHandle, ConnectorIdentity identity, AccessControlContext context, Privilege privilege, SchemaTableName tableName, PrestoPrincipal revokee, boolean grantOptionFor) { denyRevokeTablePrivilege(privilege.toString(), tableName.toString()); } default void checkCanCreateRole(ConnectorTransactionHandle transactionHandle, ConnectorIdentity identity, AccessControlContext context, String role, Optional grantor) { denyCreateRole(role); } default void checkCanDropRole(ConnectorTransactionHandle transactionHandle, ConnectorIdentity identity, AccessControlContext context, String role) { denyDropRole(role); } default void checkCanGrantRoles(ConnectorTransactionHandle transactionHandle, ConnectorIdentity identity, AccessControlContext context, Set roles, Set grantees, boolean withAdminOption, Optional grantor, String catalogName) { denyGrantRoles(roles, grantees); } default void checkCanRevokeRoles(ConnectorTransactionHandle transactionHandle, ConnectorIdentity identity, AccessControlContext context, Set roles, Set grantees, boolean adminOptionFor, Optional grantor, String catalogName) { denyRevokeRoles(roles, grantees); } default void checkCanSetRole(ConnectorTransactionHandle transactionHandle, ConnectorIdentity identity, AccessControlContext accessControlContext, String role, String catalogName) { denySetRole(role); } /** * Check if identity is allowed to show roles on the specified catalog. * * @throws com.facebook.presto.jdbc.internal.spi.security.AccessDeniedException if not allowed */ default void checkCanShowRoles(ConnectorTransactionHandle transactionHandle, ConnectorIdentity identity, AccessControlContext context, String catalogName) { denyShowRoles(catalogName); } /** * Check if identity is allowed to show current roles on the specified catalog. * * @throws com.facebook.presto.jdbc.internal.spi.security.AccessDeniedException if not allowed */ default void checkCanShowCurrentRoles(ConnectorTransactionHandle transactionHandle, ConnectorIdentity identity, AccessControlContext context, String catalogName) { denyShowCurrentRoles(catalogName); } /** * Check if identity is allowed to show its own role grants on the specified catalog. * * @throws com.facebook.presto.jdbc.internal.spi.security.AccessDeniedException if not allowed */ default void checkCanShowRoleGrants(ConnectorTransactionHandle transactionHandle, ConnectorIdentity identity, AccessControlContext context, String catalogName) { denyShowRoleGrants(catalogName); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy