Search in sources :

Example 21 with TransactionManager

use of io.prestosql.transaction.TransactionManager in project hetu-core by openlookeng.

the class TestFileBasedSystemAccessControl method testTableOperations.

@Test
public void testTableOperations() {
    TransactionManager transactionManager = createTestTransactionManager();
    AccessControlManager accessControlManager = newAccessControlManager(transactionManager, "catalog.json");
    transaction(transactionManager, accessControlManager).execute(transactionId -> {
        Set<SchemaTableName> aliceTables = ImmutableSet.of(new SchemaTableName("schema", "table"));
        assertEquals(accessControlManager.filterTables(transactionId, alice, "alice-catalog", aliceTables), aliceTables);
        assertEquals(accessControlManager.filterTables(transactionId, bob, "alice-catalog", aliceTables), ImmutableSet.of());
        accessControlManager.checkCanCreateTable(transactionId, alice, aliceTable);
        accessControlManager.checkCanDropTable(transactionId, alice, aliceTable);
        accessControlManager.checkCanSelectFromColumns(transactionId, alice, aliceTable, ImmutableSet.of());
        accessControlManager.checkCanInsertIntoTable(transactionId, alice, aliceTable);
        accessControlManager.checkCanDeleteFromTable(transactionId, alice, aliceTable);
        accessControlManager.checkCanAddColumns(transactionId, alice, aliceTable);
        accessControlManager.checkCanRenameColumn(transactionId, alice, aliceTable);
    });
    assertThrows(AccessDeniedException.class, () -> transaction(transactionManager, accessControlManager).execute(transactionId -> {
        accessControlManager.checkCanCreateTable(transactionId, bob, aliceTable);
    }));
}
Also used : SECURITY_CONFIG_FILE(io.prestosql.plugin.base.security.FileBasedAccessControlConfig.SECURITY_CONFIG_FILE) TransactionManager(io.prestosql.transaction.TransactionManager) InterfaceTestUtils.assertAllMethodsOverridden(io.prestosql.spi.testing.InterfaceTestUtils.assertAllMethodsOverridden) Assert.assertEquals(org.testng.Assert.assertEquals) Test(org.testng.annotations.Test) QualifiedObjectName(io.prestosql.spi.connector.QualifiedObjectName) AccessDeniedException(io.prestosql.spi.security.AccessDeniedException) SchemaTableName(io.prestosql.spi.connector.SchemaTableName) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) Assert.assertThrows(org.testng.Assert.assertThrows) Thread.sleep(java.lang.Thread.sleep) TransactionBuilder.transaction(io.prestosql.transaction.TransactionBuilder.transaction) CatalogSchemaName(io.prestosql.spi.connector.CatalogSchemaName) InMemoryTransactionManager.createTestTransactionManager(io.prestosql.transaction.InMemoryTransactionManager.createTestTransactionManager) Files.newTemporaryFile(org.assertj.core.util.Files.newTemporaryFile) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) KerberosPrincipal(javax.security.auth.kerberos.KerberosPrincipal) Set(java.util.Set) Identity(io.prestosql.spi.security.Identity) USER(io.prestosql.spi.security.PrincipalType.USER) File(java.io.File) SystemAccessControl(io.prestosql.spi.security.SystemAccessControl) SECURITY_REFRESH_PERIOD(io.prestosql.plugin.base.security.FileBasedAccessControlConfig.SECURITY_REFRESH_PERIOD) Files.copy(com.google.common.io.Files.copy) Optional(java.util.Optional) PrestoPrincipal(io.prestosql.spi.security.PrestoPrincipal) SELECT(io.prestosql.spi.security.Privilege.SELECT) TransactionManager(io.prestosql.transaction.TransactionManager) InMemoryTransactionManager.createTestTransactionManager(io.prestosql.transaction.InMemoryTransactionManager.createTestTransactionManager) SchemaTableName(io.prestosql.spi.connector.SchemaTableName) Test(org.testng.annotations.Test)

Example 22 with TransactionManager

use of io.prestosql.transaction.TransactionManager in project hetu-core by openlookeng.

the class TestFileBasedSystemAccessControl method testSchemaOperations.

@Test
public void testSchemaOperations() {
    TransactionManager transactionManager = createTestTransactionManager();
    AccessControlManager accessControlManager = newAccessControlManager(transactionManager, "catalog.json");
    transaction(transactionManager, accessControlManager).execute(transactionId -> {
        Set<String> aliceSchemas = ImmutableSet.of("schema");
        assertEquals(accessControlManager.filterSchemas(transactionId, alice, "alice-catalog", aliceSchemas), aliceSchemas);
        assertEquals(accessControlManager.filterSchemas(transactionId, bob, "alice-catalog", aliceSchemas), ImmutableSet.of());
        accessControlManager.checkCanCreateSchema(transactionId, alice, aliceSchema);
        accessControlManager.checkCanDropSchema(transactionId, alice, aliceSchema);
        accessControlManager.checkCanRenameSchema(transactionId, alice, aliceSchema, "new-schema");
        accessControlManager.checkCanShowSchemas(transactionId, alice, "alice-catalog");
    });
    assertThrows(AccessDeniedException.class, () -> transaction(transactionManager, accessControlManager).execute(transactionId -> {
        accessControlManager.checkCanCreateSchema(transactionId, bob, aliceSchema);
    }));
}
Also used : SECURITY_CONFIG_FILE(io.prestosql.plugin.base.security.FileBasedAccessControlConfig.SECURITY_CONFIG_FILE) TransactionManager(io.prestosql.transaction.TransactionManager) InterfaceTestUtils.assertAllMethodsOverridden(io.prestosql.spi.testing.InterfaceTestUtils.assertAllMethodsOverridden) Assert.assertEquals(org.testng.Assert.assertEquals) Test(org.testng.annotations.Test) QualifiedObjectName(io.prestosql.spi.connector.QualifiedObjectName) AccessDeniedException(io.prestosql.spi.security.AccessDeniedException) SchemaTableName(io.prestosql.spi.connector.SchemaTableName) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) Assert.assertThrows(org.testng.Assert.assertThrows) Thread.sleep(java.lang.Thread.sleep) TransactionBuilder.transaction(io.prestosql.transaction.TransactionBuilder.transaction) CatalogSchemaName(io.prestosql.spi.connector.CatalogSchemaName) InMemoryTransactionManager.createTestTransactionManager(io.prestosql.transaction.InMemoryTransactionManager.createTestTransactionManager) Files.newTemporaryFile(org.assertj.core.util.Files.newTemporaryFile) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) KerberosPrincipal(javax.security.auth.kerberos.KerberosPrincipal) Set(java.util.Set) Identity(io.prestosql.spi.security.Identity) USER(io.prestosql.spi.security.PrincipalType.USER) File(java.io.File) SystemAccessControl(io.prestosql.spi.security.SystemAccessControl) SECURITY_REFRESH_PERIOD(io.prestosql.plugin.base.security.FileBasedAccessControlConfig.SECURITY_REFRESH_PERIOD) Files.copy(com.google.common.io.Files.copy) Optional(java.util.Optional) PrestoPrincipal(io.prestosql.spi.security.PrestoPrincipal) SELECT(io.prestosql.spi.security.Privilege.SELECT) TransactionManager(io.prestosql.transaction.TransactionManager) InMemoryTransactionManager.createTestTransactionManager(io.prestosql.transaction.InMemoryTransactionManager.createTestTransactionManager) Test(org.testng.annotations.Test)

Example 23 with TransactionManager

use of io.prestosql.transaction.TransactionManager in project hetu-core by openlookeng.

the class TestFileBasedSystemAccessControl method testCanSetUserOperations.

@Test
public void testCanSetUserOperations() {
    TransactionManager transactionManager = createTestTransactionManager();
    AccessControlManager accessControlManager = newAccessControlManager(transactionManager, "catalog_principal.json");
    try {
        accessControlManager.checkCanSetUser(Optional.empty(), alice.getUser());
        throw new AssertionError("expected AccessDeniedExeption");
    } catch (AccessDeniedException expected) {
    }
    accessControlManager.checkCanSetUser(kerberosValidAlice.getPrincipal(), kerberosValidAlice.getUser());
    accessControlManager.checkCanSetUser(kerberosValidNonAsciiUser.getPrincipal(), kerberosValidNonAsciiUser.getUser());
    try {
        accessControlManager.checkCanSetUser(kerberosInvalidAlice.getPrincipal(), kerberosInvalidAlice.getUser());
        throw new AssertionError("expected AccessDeniedExeption");
    } catch (AccessDeniedException expected) {
    }
    accessControlManager.checkCanSetUser(kerberosValidShare.getPrincipal(), kerberosValidShare.getUser());
    try {
        accessControlManager.checkCanSetUser(kerberosInValidShare.getPrincipal(), kerberosInValidShare.getUser());
        throw new AssertionError("expected AccessDeniedExeption");
    } catch (AccessDeniedException expected) {
    }
    accessControlManager.checkCanSetUser(validSpecialRegexWildDot.getPrincipal(), validSpecialRegexWildDot.getUser());
    accessControlManager.checkCanSetUser(validSpecialRegexEndQuote.getPrincipal(), validSpecialRegexEndQuote.getUser());
    try {
        accessControlManager.checkCanSetUser(invalidSpecialRegex.getPrincipal(), invalidSpecialRegex.getUser());
        throw new AssertionError("expected AccessDeniedExeption");
    } catch (AccessDeniedException expected) {
    }
    TransactionManager transactionManagerNoPatterns = createTestTransactionManager();
    AccessControlManager accessControlManagerNoPatterns = newAccessControlManager(transactionManager, "catalog.json");
    accessControlManagerNoPatterns.checkCanSetUser(kerberosValidAlice.getPrincipal(), kerberosValidAlice.getUser());
}
Also used : AccessDeniedException(io.prestosql.spi.security.AccessDeniedException) TransactionManager(io.prestosql.transaction.TransactionManager) InMemoryTransactionManager.createTestTransactionManager(io.prestosql.transaction.InMemoryTransactionManager.createTestTransactionManager) Test(org.testng.annotations.Test)

Example 24 with TransactionManager

use of io.prestosql.transaction.TransactionManager in project hetu-core by openlookeng.

the class TestFileBasedSystemAccessControl method testNodeOperations.

@Test
public void testNodeOperations() {
    TransactionManager transactionManager = createTestTransactionManager();
    AccessControlManager accessControlManager = newAccessControlManager(transactionManager, "server.json");
    accessControlManager.checkCanAccessNodeInfo(alice);
    try {
        accessControlManager.checkCanAccessNodeInfo(bob);
    } catch (AccessDeniedException expected) {
    }
}
Also used : AccessDeniedException(io.prestosql.spi.security.AccessDeniedException) TransactionManager(io.prestosql.transaction.TransactionManager) InMemoryTransactionManager.createTestTransactionManager(io.prestosql.transaction.InMemoryTransactionManager.createTestTransactionManager) Test(org.testng.annotations.Test)

Example 25 with TransactionManager

use of io.prestosql.transaction.TransactionManager in project hetu-core by openlookeng.

the class TestCreateTableTask method setUp.

@BeforeMethod
public void setUp() {
    CatalogManager catalogManager = new CatalogManager();
    TransactionManager transactionManager = createTestTransactionManager(catalogManager);
    TablePropertyManager tablePropertyManager = new TablePropertyManager();
    ColumnPropertyManager columnPropertyManager = new ColumnPropertyManager();
    Catalog testCatalog = createBogusTestingCatalog(CATALOG_NAME);
    catalogManager.registerCatalog(testCatalog);
    tablePropertyManager.addProperties(testCatalog.getConnectorCatalogName(), ImmutableList.of(stringProperty("baz", "test property", null, false)));
    columnPropertyManager.addProperties(testCatalog.getConnectorCatalogName(), ImmutableList.of());
    testSession = testSessionBuilder().setTransactionId(transactionManager.beginTransaction(false)).build();
    metadata = new MockMetadata(tablePropertyManager, columnPropertyManager, testCatalog.getConnectorCatalogName(), emptySet());
}
Also used : ColumnPropertyManager(io.prestosql.metadata.ColumnPropertyManager) TransactionManager(io.prestosql.transaction.TransactionManager) InMemoryTransactionManager.createTestTransactionManager(io.prestosql.transaction.InMemoryTransactionManager.createTestTransactionManager) AbstractMockMetadata(io.prestosql.metadata.AbstractMockMetadata) TablePropertyManager(io.prestosql.metadata.TablePropertyManager) CatalogManager(io.prestosql.metadata.CatalogManager) TestingSession.createBogusTestingCatalog(io.prestosql.testing.TestingSession.createBogusTestingCatalog) Catalog(io.prestosql.metadata.Catalog) BeforeMethod(org.testng.annotations.BeforeMethod)

Aggregations

TransactionManager (io.prestosql.transaction.TransactionManager)34 InMemoryTransactionManager.createTestTransactionManager (io.prestosql.transaction.InMemoryTransactionManager.createTestTransactionManager)30 Test (org.testng.annotations.Test)26 HeuristicIndexerManager (io.prestosql.heuristicindex.HeuristicIndexerManager)19 Session (io.prestosql.Session)17 FileSystemClientManager (io.prestosql.filesystem.FileSystemClientManager)15 HetuMetaStoreManager (io.prestosql.metastore.HetuMetaStoreManager)15 AllowAllAccessControl (io.prestosql.security.AllowAllAccessControl)15 QualifiedObjectName (io.prestosql.spi.connector.QualifiedObjectName)12 Identity (io.prestosql.spi.security.Identity)11 AccessDeniedException (io.prestosql.spi.security.AccessDeniedException)9 Optional (java.util.Optional)9 PrestoPrincipal (io.prestosql.spi.security.PrestoPrincipal)8 SchemaTableName (io.prestosql.spi.connector.SchemaTableName)7 Set (java.util.Set)7 CatalogSchemaName (io.prestosql.spi.connector.CatalogSchemaName)6 StartTransaction (io.prestosql.sql.tree.StartTransaction)6 InMemoryTransactionManager (io.prestosql.transaction.InMemoryTransactionManager)6 ImmutableMap (com.google.common.collect.ImmutableMap)5 ImmutableSet (com.google.common.collect.ImmutableSet)5