use of io.trino.transaction.TransactionManager in project trino by trinodb.
the class TestAccessControlManager method testDenyExecuteProcedureBySystem.
@Test
public void testDenyExecuteProcedureBySystem() {
CatalogManager catalogManager = new CatalogManager();
TransactionManager transactionManager = createTestTransactionManager(catalogManager);
AccessControlManager accessControlManager = createAccessControlManager(transactionManager);
TestSystemAccessControlFactory accessControlFactory = new TestSystemAccessControlFactory("deny-all");
accessControlManager.addSystemAccessControlFactory(accessControlFactory);
accessControlManager.setSystemAccessControl("deny-all", ImmutableMap.of());
assertDenyExecuteProcedure(transactionManager, accessControlManager, "Access Denied: Cannot execute procedure connector.schema.procedure");
}
use of io.trino.transaction.TransactionManager in project trino by trinodb.
the class TestAccessControlManager method testDenyExecuteFunctionBySystemAccessControl.
@Test
public void testDenyExecuteFunctionBySystemAccessControl() {
CatalogManager catalogManager = new CatalogManager();
TransactionManager transactionManager = createTestTransactionManager(catalogManager);
AccessControlManager accessControlManager = createAccessControlManager(transactionManager);
TestSystemAccessControlFactory accessControlFactory = new TestSystemAccessControlFactory("deny-all");
accessControlManager.addSystemAccessControlFactory(accessControlFactory);
accessControlManager.setSystemAccessControl("deny-all", ImmutableMap.of());
transaction(transactionManager, accessControlManager).execute(transactionId -> {
assertThatThrownBy(() -> accessControlManager.checkCanExecuteFunction(context(transactionId), "executed_function")).isInstanceOf(AccessDeniedException.class).hasMessage("Access Denied: Cannot execute function executed_function");
assertThatThrownBy(() -> accessControlManager.checkCanGrantExecuteFunctionPrivilege(context(transactionId), "executed_function", Identity.ofUser("bob"), true)).isInstanceOf(AccessDeniedException.class).hasMessage("Access Denied: 'user_name' cannot grant 'executed_function' execution to user 'bob'");
});
}
use of io.trino.transaction.TransactionManager in project trino by trinodb.
the class TestAccessControlManager method testDenySystemAccessControl.
@Test
public void testDenySystemAccessControl() {
try (LocalQueryRunner queryRunner = LocalQueryRunner.create(TEST_SESSION)) {
TransactionManager transactionManager = queryRunner.getTransactionManager();
AccessControlManager accessControlManager = createAccessControlManager(transactionManager);
TestSystemAccessControlFactory accessControlFactory = new TestSystemAccessControlFactory("test");
accessControlManager.addSystemAccessControlFactory(accessControlFactory);
accessControlManager.setSystemAccessControl("test", ImmutableMap.of());
queryRunner.createCatalog("catalog", MockConnectorFactory.create(), ImmutableMap.of());
accessControlManager.addCatalogAccessControl(new CatalogName("connector"), new DenyConnectorAccessControl());
assertThatThrownBy(() -> transaction(transactionManager, accessControlManager).execute(transactionId -> {
accessControlManager.checkCanSelectFromColumns(context(transactionId), new QualifiedObjectName("secured_catalog", "schema", "table"), ImmutableSet.of("column"));
})).isInstanceOf(TrinoException.class).hasMessageMatching("Access Denied: Cannot select from table secured_catalog.schema.table");
}
}
use of io.trino.transaction.TransactionManager in project trino by trinodb.
the class TestQuerySessionSupplier method createSessionSupplier.
private static QuerySessionSupplier createSessionSupplier(SqlEnvironmentConfig config) {
TransactionManager transactionManager = createTestTransactionManager();
Metadata metadata = testMetadataManagerBuilder().withTransactionManager(transactionManager).build();
return new QuerySessionSupplier(metadata, new AllowAllAccessControl(), new SessionPropertyManager(), config);
}
use of io.trino.transaction.TransactionManager in project trino by trinodb.
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) {
}
AccessControlManager accessControlManagerNoPatterns = newAccessControlManager(transactionManager, "catalog.json");
accessControlManagerNoPatterns.checkCanSetUser(kerberosValidAlice.getPrincipal(), kerberosValidAlice.getUser());
}
Aggregations