Search in sources :

Example 1 with SECURITY_REFRESH_PERIOD

use of io.prestosql.plugin.base.security.FileBasedAccessControlConfig.SECURITY_REFRESH_PERIOD in project hetu-core by openlookeng.

the class TestFileBasedSystemAccessControl method testRefreshing.

@Test
public void testRefreshing() throws Exception {
    TransactionManager transactionManager = createTestTransactionManager();
    AccessControlManager accessControlManager = new AccessControlManager(transactionManager);
    File configFile = newTemporaryFile();
    configFile.deleteOnExit();
    copy(new File(getResourcePath("catalog.json")), configFile);
    accessControlManager.setSystemAccessControl(FileBasedSystemAccessControl.NAME, ImmutableMap.of(SECURITY_CONFIG_FILE, configFile.getCanonicalPath(), SECURITY_REFRESH_PERIOD, "1ms"));
    transaction(transactionManager, accessControlManager).execute(transactionId -> {
        accessControlManager.checkCanCreateView(transactionId, alice, aliceView);
        accessControlManager.checkCanCreateView(transactionId, alice, aliceView);
        accessControlManager.checkCanCreateView(transactionId, alice, aliceView);
    });
    copy(new File(getResourcePath("security-config-file-with-unknown-rules.json")), configFile);
    sleep(2);
    assertThatThrownBy(() -> transaction(transactionManager, accessControlManager).execute(transactionId -> {
        accessControlManager.checkCanCreateView(transactionId, alice, aliceView);
    })).isInstanceOf(IllegalArgumentException.class).hasMessageStartingWith("Invalid JSON file");
    // test if file based cached control was not cached somewhere
    assertThatThrownBy(() -> transaction(transactionManager, accessControlManager).execute(transactionId -> {
        accessControlManager.checkCanCreateView(transactionId, alice, aliceView);
    })).isInstanceOf(IllegalArgumentException.class).hasMessageStartingWith("Invalid JSON file");
    copy(new File(getResourcePath("catalog.json")), configFile);
    sleep(2);
    transaction(transactionManager, accessControlManager).execute(transactionId -> {
        accessControlManager.checkCanCreateView(transactionId, alice, aliceView);
    });
}
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) Files.newTemporaryFile(org.assertj.core.util.Files.newTemporaryFile) File(java.io.File) Test(org.testng.annotations.Test)

Aggregations

ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Files.copy (com.google.common.io.Files.copy)1 SECURITY_CONFIG_FILE (io.prestosql.plugin.base.security.FileBasedAccessControlConfig.SECURITY_CONFIG_FILE)1 SECURITY_REFRESH_PERIOD (io.prestosql.plugin.base.security.FileBasedAccessControlConfig.SECURITY_REFRESH_PERIOD)1 CatalogSchemaName (io.prestosql.spi.connector.CatalogSchemaName)1 QualifiedObjectName (io.prestosql.spi.connector.QualifiedObjectName)1 SchemaTableName (io.prestosql.spi.connector.SchemaTableName)1 AccessDeniedException (io.prestosql.spi.security.AccessDeniedException)1 Identity (io.prestosql.spi.security.Identity)1 PrestoPrincipal (io.prestosql.spi.security.PrestoPrincipal)1 USER (io.prestosql.spi.security.PrincipalType.USER)1 SELECT (io.prestosql.spi.security.Privilege.SELECT)1 SystemAccessControl (io.prestosql.spi.security.SystemAccessControl)1 InterfaceTestUtils.assertAllMethodsOverridden (io.prestosql.spi.testing.InterfaceTestUtils.assertAllMethodsOverridden)1 InMemoryTransactionManager.createTestTransactionManager (io.prestosql.transaction.InMemoryTransactionManager.createTestTransactionManager)1 TransactionBuilder.transaction (io.prestosql.transaction.TransactionBuilder.transaction)1 TransactionManager (io.prestosql.transaction.TransactionManager)1 File (java.io.File)1 Thread.sleep (java.lang.Thread.sleep)1