Search in sources :

Example 36 with AllowAllAccessControl

use of com.facebook.presto.security.AllowAllAccessControl in project urban-eureka by errir503.

the class TestQuerySessionSupplier method testCreateSession.

@Test
public void testCreateSession() {
    HttpRequestSessionContext context = new HttpRequestSessionContext(TEST_REQUEST, new SqlParserOptions());
    QuerySessionSupplier sessionSupplier = new QuerySessionSupplier(createTestTransactionManager(), new AllowAllAccessControl(), new SessionPropertyManager(), new SqlEnvironmentConfig());
    Session session = sessionSupplier.createSession(new QueryId("test_query_id"), context);
    assertEquals(session.getQueryId(), new QueryId("test_query_id"));
    assertEquals(session.getUser(), "testUser");
    assertEquals(session.getSource().get(), "testSource");
    assertEquals(session.getCatalog().get(), "testCatalog");
    assertEquals(session.getSchema().get(), "testSchema");
    assertEquals(session.getLocale(), Locale.TAIWAN);
    assertEquals(session.getTimeZoneKey(), getTimeZoneKey("Asia/Taipei"));
    assertEquals(session.getRemoteUserAddress().get(), "testRemote");
    assertEquals(session.getClientInfo().get(), "client-info");
    assertEquals(session.getClientTags(), ImmutableSet.of("tag1", "tag2", "tag3"));
    assertEquals(session.getSystemProperties(), ImmutableMap.<String, String>builder().put(QUERY_MAX_MEMORY, "1GB").put(JOIN_DISTRIBUTION_TYPE, "partitioned").put(HASH_PARTITION_COUNT, "43").build());
    assertEquals(session.getPreparedStatements(), ImmutableMap.<String, String>builder().put("query1", "select * from foo").put("query2", "select * from bar").build());
    assertEquals(session.getSessionFunctions(), ImmutableMap.of(SQL_FUNCTION_ID_ADD, SQL_FUNCTION_ADD));
}
Also used : SqlParserOptions(com.facebook.presto.sql.parser.SqlParserOptions) AllowAllAccessControl(com.facebook.presto.security.AllowAllAccessControl) QueryId(com.facebook.presto.spi.QueryId) SessionPropertyManager(com.facebook.presto.metadata.SessionPropertyManager) SqlEnvironmentConfig(com.facebook.presto.sql.SqlEnvironmentConfig) Session(com.facebook.presto.Session) Test(org.testng.annotations.Test)

Example 37 with AllowAllAccessControl

use of com.facebook.presto.security.AllowAllAccessControl in project urban-eureka by errir503.

the class TestMinimalFunctionality method testTableExists.

@Test
public void testTableExists() {
    QualifiedObjectName name = new QualifiedObjectName("redis", "default", tableName);
    transaction(queryRunner.getTransactionManager(), new AllowAllAccessControl()).singleStatement().execute(SESSION, session -> {
        Optional<TableHandle> handle = queryRunner.getServer().getMetadata().getTableHandle(session, name);
        assertTrue(handle.isPresent());
    });
}
Also used : AllowAllAccessControl(com.facebook.presto.security.AllowAllAccessControl) TableHandle(com.facebook.presto.spi.TableHandle) QualifiedObjectName(com.facebook.presto.common.QualifiedObjectName) Test(org.testng.annotations.Test)

Example 38 with AllowAllAccessControl

use of com.facebook.presto.security.AllowAllAccessControl in project presto by prestodb.

the class Analysis method buildMaterializedViewAccessControl.

/**
 * For a query on materialized view, only check the actual required access controls for its base tables. For the materialized view,
 * will not check access control by replacing with AllowAllAccessControl.
 */
private Map<AccessControlInfo, Map<QualifiedObjectName, Set<String>>> buildMaterializedViewAccessControl(Map<AccessControlInfo, Map<QualifiedObjectName, Set<String>>> tableColumnReferences) {
    if (!(getStatement() instanceof Query) || materializedViews.isEmpty()) {
        return tableColumnReferences;
    }
    Map<AccessControlInfo, Map<QualifiedObjectName, Set<String>>> newTableColumnReferences = new LinkedHashMap<>();
    tableColumnReferences.forEach((accessControlInfo, references) -> {
        AccessControlInfo allowAllAccessControlInfo = new AccessControlInfo(new AllowAllAccessControl(), accessControlInfo.getIdentity());
        Map<QualifiedObjectName, Set<String>> newAllowAllReferences = newTableColumnReferences.getOrDefault(allowAllAccessControlInfo, new LinkedHashMap<>());
        Map<QualifiedObjectName, Set<String>> newOtherReferences = new LinkedHashMap<>();
        references.forEach((table, columns) -> {
            if (materializedViews.containsKey(table)) {
                newAllowAllReferences.computeIfAbsent(table, key -> new HashSet<>()).addAll(columns);
            } else {
                newOtherReferences.put(table, columns);
            }
        });
        if (!newAllowAllReferences.isEmpty()) {
            newTableColumnReferences.put(allowAllAccessControlInfo, newAllowAllReferences);
        }
        if (!newOtherReferences.isEmpty()) {
            newTableColumnReferences.put(accessControlInfo, newOtherReferences);
        }
    });
    return newTableColumnReferences;
}
Also used : ArrayListMultimap(com.google.common.collect.ArrayListMultimap) SubqueryExpression(com.facebook.presto.sql.tree.SubqueryExpression) Collections.unmodifiableList(java.util.Collections.unmodifiableList) ListMultimap(com.google.common.collect.ListMultimap) Collections.unmodifiableCollection(java.util.Collections.unmodifiableCollection) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) Join(com.facebook.presto.sql.tree.Join) Map(java.util.Map) QualifiedObjectName(com.facebook.presto.common.QualifiedObjectName) FunctionCall(com.facebook.presto.sql.tree.FunctionCall) Query(com.facebook.presto.sql.tree.Query) QuerySpecification(com.facebook.presto.sql.tree.QuerySpecification) ImmutableMap(com.google.common.collect.ImmutableMap) NOT_VISITED(com.facebook.presto.sql.analyzer.Analysis.MaterializedViewAnalysisState.NOT_VISITED) Collections.emptyList(java.util.Collections.emptyList) Collection(java.util.Collection) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Node(com.facebook.presto.sql.tree.Node) Set(java.util.Set) String.format(java.lang.String.format) SampledRelation(com.facebook.presto.sql.tree.SampledRelation) Preconditions.checkState(com.google.common.base.Preconditions.checkState) Objects(java.util.Objects) List(java.util.List) InPredicate(com.facebook.presto.sql.tree.InPredicate) Optional(java.util.Optional) AllowAllAccessControl(com.facebook.presto.security.AllowAllAccessControl) SystemSessionProperties.isCheckAccessControlOnUtilizedColumnsOnly(com.facebook.presto.SystemSessionProperties.isCheckAccessControlOnUtilizedColumnsOnly) LambdaArgumentDeclaration(com.facebook.presto.sql.tree.LambdaArgumentDeclaration) Table(com.facebook.presto.sql.tree.Table) VISITING(com.facebook.presto.sql.analyzer.Analysis.MaterializedViewAnalysisState.VISITING) QuantifiedComparisonExpression(com.facebook.presto.sql.tree.QuantifiedComparisonExpression) Multimaps.forMap(com.google.common.collect.Multimaps.forMap) HashMap(java.util.HashMap) Multimap(com.google.common.collect.Multimap) Deque(java.util.Deque) Identifier(com.facebook.presto.sql.tree.Identifier) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) VISITED(com.facebook.presto.sql.analyzer.Analysis.MaterializedViewAnalysisState.VISITED) ImmutableList(com.google.common.collect.ImmutableList) Identity(com.facebook.presto.spi.security.Identity) Objects.requireNonNull(java.util.Objects.requireNonNull) TableHandle(com.facebook.presto.spi.TableHandle) Type(com.facebook.presto.common.type.Type) Nullable(javax.annotation.Nullable) LinkedHashSet(java.util.LinkedHashSet) ExistsPredicate(com.facebook.presto.sql.tree.ExistsPredicate) GroupingOperation(com.facebook.presto.sql.tree.GroupingOperation) OrderBy(com.facebook.presto.sql.tree.OrderBy) Relation(com.facebook.presto.sql.tree.Relation) Session(com.facebook.presto.Session) Multimaps.unmodifiableMultimap(com.google.common.collect.Multimaps.unmodifiableMultimap) Offset(com.facebook.presto.sql.tree.Offset) NodeRef(com.facebook.presto.sql.tree.NodeRef) Collections.unmodifiableSet(java.util.Collections.unmodifiableSet) Expression(com.facebook.presto.sql.tree.Expression) ColumnHandle(com.facebook.presto.spi.ColumnHandle) FunctionHandle(com.facebook.presto.spi.function.FunctionHandle) Collections.unmodifiableMap(java.util.Collections.unmodifiableMap) ArrayDeque(java.util.ArrayDeque) Immutable(javax.annotation.concurrent.Immutable) AccessControl(com.facebook.presto.security.AccessControl) Statement(com.facebook.presto.sql.tree.Statement) Set(java.util.Set) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Collections.unmodifiableSet(java.util.Collections.unmodifiableSet) Query(com.facebook.presto.sql.tree.Query) QualifiedObjectName(com.facebook.presto.common.QualifiedObjectName) LinkedHashMap(java.util.LinkedHashMap) AllowAllAccessControl(com.facebook.presto.security.AllowAllAccessControl) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Multimaps.forMap(com.google.common.collect.Multimaps.forMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Collections.unmodifiableMap(java.util.Collections.unmodifiableMap) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 39 with AllowAllAccessControl

use of com.facebook.presto.security.AllowAllAccessControl in project urban-eureka by errir503.

the class TestStartTransactionTask method testStartTransactionExplicitModes.

@Test
public void testStartTransactionExplicitModes() {
    Session session = sessionBuilder().setClientTransactionSupport().build();
    TransactionManager transactionManager = createTestTransactionManager();
    QueryStateMachine stateMachine = createQueryStateMachine("START TRANSACTION", session, true, transactionManager, executor, metadata);
    assertFalse(stateMachine.getSession().getTransactionId().isPresent());
    StartTransactionTask startTransactionTask = new StartTransactionTask();
    getFutureValue(startTransactionTask.execute(new StartTransaction(ImmutableList.of(new Isolation(Isolation.Level.SERIALIZABLE), new TransactionAccessMode(true))), transactionManager, metadata, new AllowAllAccessControl(), stateMachine, emptyList()));
    assertFalse(stateMachine.getQueryInfo(Optional.empty()).isClearTransactionId());
    assertTrue(stateMachine.getQueryInfo(Optional.empty()).getStartedTransactionId().isPresent());
    assertEquals(transactionManager.getAllTransactionInfos().size(), 1);
    TransactionInfo transactionInfo = transactionManager.getTransactionInfo(stateMachine.getQueryInfo(Optional.empty()).getStartedTransactionId().get());
    assertEquals(transactionInfo.getIsolationLevel(), IsolationLevel.SERIALIZABLE);
    assertTrue(transactionInfo.isReadOnly());
    assertFalse(transactionInfo.isAutoCommitContext());
}
Also used : TaskTestUtils.createQueryStateMachine(com.facebook.presto.execution.TaskTestUtils.createQueryStateMachine) TransactionManager(com.facebook.presto.transaction.TransactionManager) InMemoryTransactionManager.createTestTransactionManager(com.facebook.presto.transaction.InMemoryTransactionManager.createTestTransactionManager) InMemoryTransactionManager(com.facebook.presto.transaction.InMemoryTransactionManager) TransactionAccessMode(com.facebook.presto.sql.tree.TransactionAccessMode) AllowAllAccessControl(com.facebook.presto.security.AllowAllAccessControl) Isolation(com.facebook.presto.sql.tree.Isolation) TransactionInfo(com.facebook.presto.transaction.TransactionInfo) StartTransaction(com.facebook.presto.sql.tree.StartTransaction) Session(com.facebook.presto.Session) Test(org.testng.annotations.Test)

Example 40 with AllowAllAccessControl

use of com.facebook.presto.security.AllowAllAccessControl in project urban-eureka by errir503.

the class TestStartTransactionTask method testNestedTransaction.

@Test
public void testNestedTransaction() {
    TransactionManager transactionManager = createTestTransactionManager();
    Session session = sessionBuilder().setTransactionId(TransactionId.create()).setClientTransactionSupport().build();
    QueryStateMachine stateMachine = createQueryStateMachine("START TRANSACTION", session, true, transactionManager, executor, metadata);
    StartTransactionTask startTransactionTask = new StartTransactionTask();
    try {
        getFutureValue(startTransactionTask.execute(new StartTransaction(ImmutableList.of()), transactionManager, metadata, new AllowAllAccessControl(), stateMachine, emptyList()));
        fail();
    } catch (PrestoException e) {
        assertEquals(e.getErrorCode(), NOT_SUPPORTED.toErrorCode());
    }
    assertTrue(transactionManager.getAllTransactionInfos().isEmpty());
    assertFalse(stateMachine.getQueryInfo(Optional.empty()).isClearTransactionId());
    assertFalse(stateMachine.getQueryInfo(Optional.empty()).getStartedTransactionId().isPresent());
}
Also used : TaskTestUtils.createQueryStateMachine(com.facebook.presto.execution.TaskTestUtils.createQueryStateMachine) TransactionManager(com.facebook.presto.transaction.TransactionManager) InMemoryTransactionManager.createTestTransactionManager(com.facebook.presto.transaction.InMemoryTransactionManager.createTestTransactionManager) InMemoryTransactionManager(com.facebook.presto.transaction.InMemoryTransactionManager) AllowAllAccessControl(com.facebook.presto.security.AllowAllAccessControl) PrestoException(com.facebook.presto.spi.PrestoException) StartTransaction(com.facebook.presto.sql.tree.StartTransaction) Session(com.facebook.presto.Session) Test(org.testng.annotations.Test)

Aggregations

AllowAllAccessControl (com.facebook.presto.security.AllowAllAccessControl)64 Test (org.testng.annotations.Test)48 TaskTestUtils.createQueryStateMachine (com.facebook.presto.execution.TaskTestUtils.createQueryStateMachine)36 InMemoryTransactionManager.createTestTransactionManager (com.facebook.presto.transaction.InMemoryTransactionManager.createTestTransactionManager)36 TransactionManager (com.facebook.presto.transaction.TransactionManager)36 Session (com.facebook.presto.Session)33 StartTransaction (com.facebook.presto.sql.tree.StartTransaction)14 InMemoryTransactionManager (com.facebook.presto.transaction.InMemoryTransactionManager)14 PrestoException (com.facebook.presto.spi.PrestoException)12 SqlParser (com.facebook.presto.sql.parser.SqlParser)10 QualifiedObjectName (com.facebook.presto.common.QualifiedObjectName)8 TableHandle (com.facebook.presto.spi.TableHandle)8 WarningCollector (com.facebook.presto.spi.WarningCollector)8 ColumnDefinition (com.facebook.presto.sql.tree.ColumnDefinition)8 CreateTable (com.facebook.presto.sql.tree.CreateTable)8 CatalogManager (com.facebook.presto.metadata.CatalogManager)6 Identifier (com.facebook.presto.sql.tree.Identifier)6 Rollback (com.facebook.presto.sql.tree.Rollback)6 SessionPropertyManager (com.facebook.presto.metadata.SessionPropertyManager)5 QueryId (com.facebook.presto.spi.QueryId)5