Search in sources :

Example 1 with PrestoPrincipal

use of io.prestosql.spi.security.PrestoPrincipal in project ranger by apache.

the class RangerSystemAccessControlTest method testViewOperations.

@Test
@SuppressWarnings("PMD")
public void testViewOperations() {
    accessControlManager.checkCanCreateView(context(alice), aliceView);
    accessControlManager.checkCanDropView(context(alice), aliceView);
    accessControlManager.checkCanSelectFromColumns(context(alice), aliceView, ImmutableSet.of());
    accessControlManager.checkCanCreateViewWithSelectFromColumns(context(alice), aliceTable, ImmutableSet.of());
    accessControlManager.checkCanCreateViewWithSelectFromColumns(context(alice), aliceView, ImmutableSet.of());
    accessControlManager.checkCanSetCatalogSessionProperty(context(alice), aliceCatalog, "property");
    accessControlManager.checkCanGrantTablePrivilege(context(alice), SELECT, aliceTable, new PrestoPrincipal(USER, "grantee"), true);
    accessControlManager.checkCanRevokeTablePrivilege(context(alice), SELECT, aliceTable, new PrestoPrincipal(USER, "revokee"), true);
    try {
        accessControlManager.checkCanCreateView(context(bob), aliceView);
    } catch (AccessDeniedException expected) {
    }
}
Also used : AccessDeniedException(io.prestosql.spi.security.AccessDeniedException) PrestoPrincipal(io.prestosql.spi.security.PrestoPrincipal) Test(org.junit.Test)

Example 2 with PrestoPrincipal

use of io.prestosql.spi.security.PrestoPrincipal in project ranger by apache.

the class RangerSystemAccessControlTest method testSchemaOperations.

@Test
@SuppressWarnings("PMD")
public void testSchemaOperations() {
    Set<String> aliceSchemas = ImmutableSet.of("schema");
    assertEquals(accessControlManager.filterSchemas(context(alice), aliceCatalog, aliceSchemas), aliceSchemas);
    assertEquals(accessControlManager.filterSchemas(context(bob), "alice-catalog", aliceSchemas), ImmutableSet.of());
    accessControlManager.checkCanCreateSchema(context(alice), aliceSchema);
    accessControlManager.checkCanDropSchema(context(alice), aliceSchema);
    accessControlManager.checkCanRenameSchema(context(alice), aliceSchema, "new-schema");
    accessControlManager.checkCanShowSchemas(context(alice), aliceCatalog);
    try {
        accessControlManager.checkCanCreateSchema(context(bob), aliceSchema);
    } catch (AccessDeniedException expected) {
    }
    accessControlManager.checkCanSetSchemaAuthorization(context(alice), aliceSchema, new PrestoPrincipal(USER, "principal"));
    accessControlManager.checkCanShowCreateSchema(context(alice), aliceSchema);
}
Also used : AccessDeniedException(io.prestosql.spi.security.AccessDeniedException) PrestoPrincipal(io.prestosql.spi.security.PrestoPrincipal) Test(org.junit.Test)

Example 3 with PrestoPrincipal

use of io.prestosql.spi.security.PrestoPrincipal in project ranger by apache.

the class RangerSystemAccessControlTest method testMisc.

@Test
@SuppressWarnings("PMD")
public void testMisc() {
    assertEquals(accessControlManager.filterViewQueryOwnedBy(context(alice), queryOwners), queryOwners);
    // check {type} / {col} replacement
    final VarcharType varcharType = VarcharType.createVarcharType(20);
    Optional<ViewExpression> ret = accessControlManager.getColumnMask(context(alice), aliceTable, "cast_me", varcharType);
    assertNotNull(ret.get());
    assertEquals(ret.get().getExpression(), "cast cast_me as varchar(20)");
    ret = accessControlManager.getColumnMask(context(alice), aliceTable, "do-not-cast-me", varcharType);
    assertFalse(ret.isPresent());
    ret = accessControlManager.getRowFilter(context(alice), aliceTable);
    assertFalse(ret.isPresent());
    accessControlManager.checkCanExecuteFunction(context(alice), functionName);
    accessControlManager.checkCanGrantExecuteFunctionPrivilege(context(alice), functionName, new PrestoPrincipal(USER, "grantee"), true);
    accessControlManager.checkCanExecuteProcedure(context(alice), aliceProcedure);
}
Also used : VarcharType(io.prestosql.spi.type.VarcharType) PrestoPrincipal(io.prestosql.spi.security.PrestoPrincipal) ViewExpression(io.prestosql.spi.security.ViewExpression) Test(org.junit.Test)

Aggregations

PrestoPrincipal (io.prestosql.spi.security.PrestoPrincipal)3 Test (org.junit.Test)3 AccessDeniedException (io.prestosql.spi.security.AccessDeniedException)2 ViewExpression (io.prestosql.spi.security.ViewExpression)1 VarcharType (io.prestosql.spi.type.VarcharType)1