use of io.trino.spi.security.TrinoPrincipal in project trino by trinodb.
the class TestGrantOnTable method initClass.
@BeforeClass
public void initClass() throws Exception {
queryRunner = DistributedQueryRunner.builder(admin).build();
MockConnectorFactory connectorFactory = MockConnectorFactory.builder().withListSchemaNames(session -> ImmutableList.of("default")).withListTables((session, schemaName) -> "default".equalsIgnoreCase(schemaName) ? ImmutableList.of(table) : ImmutableList.of()).withGetTableHandle((session, tableName) -> tableName.equals(table) ? new MockConnectorTableHandle(tableName) : null).withSchemaGrants(new MutableGrants<>()).withTableGrants(tableGrants).build();
queryRunner.installPlugin(new MockConnectorPlugin(connectorFactory));
queryRunner.createCatalog("local", "mock");
assertions = new QueryAssertions(queryRunner);
tableGrants.grant(new TrinoPrincipal(USER, "admin"), table, EnumSet.allOf(Privilege.class), true);
}
use of io.trino.spi.security.TrinoPrincipal in project trino by trinodb.
the class TestDenyOnSchema method testValidDenySchema.
@Test(dataProvider = "privileges")
public void testValidDenySchema(String privilege) {
String username = randomUsername();
denyCalled = false;
expectedSchemaName = new CatalogSchemaName("local", "default");
if (privilege.equalsIgnoreCase("all privileges")) {
expectedPrivileges = ImmutableSet.copyOf(Privilege.values());
} else {
expectedPrivileges = ImmutableSet.of(Privilege.valueOf(privilege.toUpperCase(ROOT)));
}
expectedGrantee = new TrinoPrincipal(USER, username);
queryRunner.execute(admin, format("DENY %s ON SCHEMA default TO %s", privilege, username));
assertThat(denyCalled).isTrue();
}
use of io.trino.spi.security.TrinoPrincipal in project trino by trinodb.
the class TestDenyOnSchema method initClass.
@BeforeClass
public void initClass() throws Exception {
queryRunner = DistributedQueryRunner.builder(admin).setAdditionalModule(binder -> {
newOptionalBinder(binder, SystemSecurityMetadata.class).setBinding().toInstance(new DisabledSystemSecurityMetadata() {
@Override
public void denySchemaPrivileges(Session session, CatalogSchemaName schemaName, Set<Privilege> privileges, TrinoPrincipal grantee) {
assertThat(expectedSchemaName).isEqualTo(schemaName);
assertThat(expectedPrivileges).isEqualTo(privileges);
assertThat(expectedGrantee).isEqualTo(grantee);
assertThat(denyCalled).isFalse();
denyCalled = true;
}
});
}).build();
MockConnectorFactory connectorFactory = MockConnectorFactory.builder().withListSchemaNames(session -> ImmutableList.of("default")).withListTables((session, schemaName) -> "default".equalsIgnoreCase(schemaName) ? ImmutableList.of(table) : ImmutableList.of()).withGetTableHandle((session, tableName) -> tableName.equals(table) ? new MockConnectorTableHandle(tableName) : null).build();
queryRunner.installPlugin(new MockConnectorPlugin(connectorFactory));
queryRunner.createCatalog("local", "mock");
assertions = new QueryAssertions(queryRunner);
tableGrants.grant(new TrinoPrincipal(USER, "admin"), table, EnumSet.allOf(Privilege.class), true);
}
use of io.trino.spi.security.TrinoPrincipal in project trino by trinodb.
the class TestDenyOnTable method initClass.
@BeforeClass
public void initClass() throws Exception {
queryRunner = DistributedQueryRunner.builder(admin).setAdditionalModule(binder -> {
newOptionalBinder(binder, SystemSecurityMetadata.class).setBinding().toInstance(new DisabledSystemSecurityMetadata() {
@Override
public void denyTablePrivileges(Session session, QualifiedObjectName tableName, Set<Privilege> privileges, TrinoPrincipal grantee) {
assertThat(expectedTableName).isEqualTo(tableName);
assertThat(expectedPrivileges).isEqualTo(privileges);
assertThat(expectedGrantee).isEqualTo(grantee);
assertThat(denyCalled).isFalse();
denyCalled = true;
}
});
}).build();
MockConnectorFactory connectorFactory = MockConnectorFactory.builder().withListSchemaNames(session -> ImmutableList.of("default")).withListTables((session, schemaName) -> "default".equalsIgnoreCase(schemaName) ? ImmutableList.of(table) : ImmutableList.of()).withGetTableHandle((session, tableName) -> tableName.equals(table) ? new MockConnectorTableHandle(tableName) : null).build();
queryRunner.installPlugin(new MockConnectorPlugin(connectorFactory));
queryRunner.createCatalog("local", "mock");
assertions = new QueryAssertions(queryRunner);
tableGrants.grant(new TrinoPrincipal(USER, "admin"), table, EnumSet.allOf(Privilege.class), true);
}
use of io.trino.spi.security.TrinoPrincipal in project trino by trinodb.
the class TestDenyOnTable method testValidDenyTable.
@Test(dataProvider = "privileges")
public void testValidDenyTable(String privilege) {
String username = randomUsername();
denyCalled = false;
expectedTableName = new QualifiedObjectName("local", "default", "table_one");
if (privilege.equalsIgnoreCase("all privileges")) {
expectedPrivileges = ImmutableSet.copyOf(Privilege.values());
} else {
expectedPrivileges = ImmutableSet.of(Privilege.valueOf(privilege.toUpperCase(ROOT)));
}
expectedGrantee = new TrinoPrincipal(USER, username);
queryRunner.execute(admin, format("DENY %s ON TABLE table_one TO %s", privilege, username));
assertThat(denyCalled).isTrue();
}
Aggregations