Search in sources :

Example 21 with TransactionManager

use of com.facebook.presto.transaction.TransactionManager in project presto by prestodb.

the class TestAccessControlManager method testReadOnlySystemAccessControl.

@Test
public void testReadOnlySystemAccessControl() throws Exception {
    Identity identity = new Identity(USER_NAME, Optional.of(PRINCIPAL));
    QualifiedObjectName tableName = new QualifiedObjectName("catalog", "schema", "table");
    TransactionManager transactionManager = createTestTransactionManager();
    AccessControlManager accessControlManager = new AccessControlManager(transactionManager);
    accessControlManager.setSystemAccessControl(ReadOnlySystemAccessControl.NAME, ImmutableMap.of());
    accessControlManager.checkCanSetUser(PRINCIPAL, USER_NAME);
    accessControlManager.checkCanSetSystemSessionProperty(identity, "property");
    transaction(transactionManager, accessControlManager).execute(transactionId -> {
        accessControlManager.checkCanSetCatalogSessionProperty(transactionId, identity, "catalog", "property");
        accessControlManager.checkCanSelectFromTable(transactionId, identity, tableName);
        accessControlManager.checkCanSelectFromView(transactionId, identity, tableName);
        accessControlManager.checkCanCreateViewWithSelectFromTable(transactionId, identity, tableName);
        accessControlManager.checkCanCreateViewWithSelectFromView(transactionId, identity, tableName);
        accessControlManager.checkCanShowSchemas(transactionId, identity, "catalog");
        accessControlManager.checkCanShowTables(transactionId, identity, new CatalogSchemaName("catalog", "schema"));
        Set<String> catalogs = ImmutableSet.of("catalog");
        assertEquals(accessControlManager.filterCatalogs(identity, catalogs), catalogs);
        Set<String> schemas = ImmutableSet.of("schema");
        assertEquals(accessControlManager.filterSchemas(transactionId, identity, "catalog", schemas), schemas);
        Set<SchemaTableName> tableNames = ImmutableSet.of(new SchemaTableName("schema", "table"));
        assertEquals(accessControlManager.filterTables(transactionId, identity, "catalog", tableNames), tableNames);
    });
    try {
        transaction(transactionManager, accessControlManager).execute(transactionId -> {
            accessControlManager.checkCanInsertIntoTable(transactionId, identity, tableName);
        });
        fail();
    } catch (AccessDeniedException expected) {
    }
}
Also used : AccessDeniedException(com.facebook.presto.spi.security.AccessDeniedException) TransactionManager(com.facebook.presto.transaction.TransactionManager) TransactionManager.createTestTransactionManager(com.facebook.presto.transaction.TransactionManager.createTestTransactionManager) CatalogSchemaName(com.facebook.presto.spi.CatalogSchemaName) Identity(com.facebook.presto.spi.security.Identity) SchemaTableName(com.facebook.presto.spi.SchemaTableName) CatalogSchemaTableName(com.facebook.presto.spi.CatalogSchemaTableName) QualifiedObjectName(com.facebook.presto.metadata.QualifiedObjectName) Test(org.testng.annotations.Test)

Example 22 with TransactionManager

use of com.facebook.presto.transaction.TransactionManager in project presto by prestodb.

the class TestAccessControlManager method testNoCatalogAccessControl.

@Test
public void testNoCatalogAccessControl() throws Exception {
    TransactionManager transactionManager = createTestTransactionManager();
    AccessControlManager accessControlManager = new AccessControlManager(transactionManager);
    TestSystemAccessControlFactory accessControlFactory = new TestSystemAccessControlFactory("test");
    accessControlManager.addSystemAccessControlFactory(accessControlFactory);
    accessControlManager.setSystemAccessControl("test", ImmutableMap.of());
    transaction(transactionManager, accessControlManager).execute(transactionId -> {
        accessControlManager.checkCanSelectFromTable(transactionId, new Identity(USER_NAME, Optional.of(PRINCIPAL)), new QualifiedObjectName("catalog", "schema", "table"));
    });
}
Also used : TransactionManager(com.facebook.presto.transaction.TransactionManager) TransactionManager.createTestTransactionManager(com.facebook.presto.transaction.TransactionManager.createTestTransactionManager) Identity(com.facebook.presto.spi.security.Identity) QualifiedObjectName(com.facebook.presto.metadata.QualifiedObjectName) Test(org.testng.annotations.Test)

Aggregations

TransactionManager (com.facebook.presto.transaction.TransactionManager)22 TransactionManager.createTestTransactionManager (com.facebook.presto.transaction.TransactionManager.createTestTransactionManager)20 AccessControl (com.facebook.presto.security.AccessControl)18 Test (org.testng.annotations.Test)17 AccessControlManager (com.facebook.presto.security.AccessControlManager)16 Session (com.facebook.presto.Session)15 AllowAllAccessControl (com.facebook.presto.security.AllowAllAccessControl)15 QueryId (com.facebook.presto.spi.QueryId)15 StartTransaction (com.facebook.presto.sql.tree.StartTransaction)7 CompletionException (java.util.concurrent.CompletionException)7 QualifiedObjectName (com.facebook.presto.metadata.QualifiedObjectName)6 PrestoException (com.facebook.presto.spi.PrestoException)6 Identity (com.facebook.presto.spi.security.Identity)4 ConnectorId (com.facebook.presto.connector.ConnectorId)3 CatalogManager (com.facebook.presto.metadata.CatalogManager)3 Metadata (com.facebook.presto.metadata.Metadata)3 SemanticException (com.facebook.presto.sql.analyzer.SemanticException)3 Commit (com.facebook.presto.sql.tree.Commit)3 ConnectorId.createInformationSchemaConnectorId (com.facebook.presto.connector.ConnectorId.createInformationSchemaConnectorId)2 ConnectorId.createSystemTablesConnectorId (com.facebook.presto.connector.ConnectorId.createSystemTablesConnectorId)2