use of io.trino.spi.security.TrinoPrincipal in project trino by trinodb.
the class BaseTrinoCatalogTest method testUseUniqueTableLocations.
@Test
public void testUseUniqueTableLocations() throws IOException {
TrinoCatalog catalog = createTrinoCatalog(true);
Path tmpDirectory = Files.createTempDirectory("iceberg_catalog_test_rename_table_");
tmpDirectory.toFile().deleteOnExit();
String namespace = "test_unique_table_locations_" + randomTableSuffix();
String table = "tableName";
SchemaTableName schemaTableName = new SchemaTableName(namespace, table);
catalog.createNamespace(SESSION, namespace, ImmutableMap.of(LOCATION_PROPERTY, tmpDirectory.toString()), new TrinoPrincipal(PrincipalType.USER, SESSION.getUser()));
try {
String location1 = catalog.defaultTableLocation(SESSION, schemaTableName);
String location2 = catalog.defaultTableLocation(SESSION, schemaTableName);
assertNotEquals(location1, location2);
assertEquals(Path.of(location1).getParent(), tmpDirectory);
assertEquals(Path.of(location2).getParent(), tmpDirectory);
} finally {
try {
catalog.dropNamespace(SESSION, namespace);
} catch (Exception e) {
LOG.warn("Failed to clean up namespace: %s", namespace);
}
}
}
use of io.trino.spi.security.TrinoPrincipal in project trino by trinodb.
the class TestMemoryMetadata method testRenameTable.
@Test
public void testRenameTable() {
SchemaTableName tableName = new SchemaTableName("test_schema", "test_table_to_be_renamed");
metadata.createSchema(SESSION, "test_schema", ImmutableMap.of(), new TrinoPrincipal(USER, SESSION.getUser()));
ConnectorOutputTableHandle table = metadata.beginCreateTable(SESSION, new ConnectorTableMetadata(tableName, ImmutableList.of(), ImmutableMap.of()), Optional.empty(), NO_RETRIES);
metadata.finishCreateTable(SESSION, table, ImmutableList.of(), ImmutableList.of());
// rename table to schema which does not exist
SchemaTableName invalidSchemaTableName = new SchemaTableName("test_schema_not_exist", "test_table_renamed");
ConnectorTableHandle tableHandle = metadata.getTableHandle(SESSION, tableName);
Throwable throwable = expectThrows(SchemaNotFoundException.class, () -> metadata.renameTable(SESSION, tableHandle, invalidSchemaTableName));
assertEquals(throwable.getMessage(), "Schema test_schema_not_exist not found");
// rename table to same schema
SchemaTableName sameSchemaTableName = new SchemaTableName("test_schema", "test_renamed");
metadata.renameTable(SESSION, metadata.getTableHandle(SESSION, tableName), sameSchemaTableName);
assertEquals(metadata.listTables(SESSION, Optional.of("test_schema")), ImmutableList.of(sameSchemaTableName));
// rename table to different schema
metadata.createSchema(SESSION, "test_different_schema", ImmutableMap.of(), new TrinoPrincipal(USER, SESSION.getUser()));
SchemaTableName differentSchemaTableName = new SchemaTableName("test_different_schema", "test_renamed");
metadata.renameTable(SESSION, metadata.getTableHandle(SESSION, sameSchemaTableName), differentSchemaTableName);
assertEquals(metadata.listTables(SESSION, Optional.of("test_schema")), ImmutableList.of());
assertEquals(metadata.listTables(SESSION, Optional.of("test_different_schema")), ImmutableList.of(differentSchemaTableName));
}
use of io.trino.spi.security.TrinoPrincipal in project trino by trinodb.
the class TestRevokeOnTable method initClass.
@BeforeClass
public void initClass() throws Exception {
SchemaTableName table = new SchemaTableName("default", "table_one");
queryRunner = DistributedQueryRunner.builder(userWithAllPrivileges).build();
Grants<SchemaTableName> tableGrants = new MutableGrants<>();
tableGrants.grant(new TrinoPrincipal(USER, admin.getUser()), table, EnumSet.allOf(Privilege.class), true);
tableGrants.grant(new TrinoPrincipal(USER, userWithAllPrivileges.getUser()), table, EnumSet.allOf(Privilege.class), true);
tableGrants.grant(new TrinoPrincipal(USER, userWithCreate.getUser()), table, ImmutableSet.of(Privilege.CREATE), true);
tableGrants.grant(new TrinoPrincipal(USER, userWithSelect.getUser()), table, ImmutableSet.of(Privilege.SELECT), true);
tableGrants.grant(new TrinoPrincipal(USER, userWithInsert.getUser()), table, ImmutableSet.of(Privilege.INSERT), true);
tableGrants.grant(new TrinoPrincipal(USER, userWithUpdate.getUser()), table, ImmutableSet.of(Privilege.UPDATE), true);
tableGrants.grant(new TrinoPrincipal(USER, userWithDelete.getUser()), table, ImmutableSet.of(Privilege.DELETE), true);
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);
}
use of io.trino.spi.security.TrinoPrincipal in project trino by trinodb.
the class TestingSystemSecurityMetadata method listEnabledRoles.
@Override
public Set<String> listEnabledRoles(Identity identity) {
Set<String> allUserRoles = getRoleGrantsRecursively(new TrinoPrincipal(USER, identity.getUser())).stream().map(RoleGrant::getRoleName).collect(toImmutableSet());
if (identity.getEnabledRoles().isEmpty()) {
return allUserRoles;
}
Set<String> enabledRoles = identity.getEnabledRoles().stream().filter(allUserRoles::contains).collect(toImmutableSet());
Set<String> transitiveRoles = enabledRoles.stream().flatMap(role -> getRoleGrantsRecursively(new TrinoPrincipal(ROLE, role)).stream()).map(RoleGrant::getRoleName).collect(toImmutableSet());
return ImmutableSet.<String>builder().addAll(enabledRoles).addAll(transitiveRoles).build();
}
use of io.trino.spi.security.TrinoPrincipal in project trino by trinodb.
the class TestingSystemSecurityMetadata method createRoleGrants.
private static Set<RoleGrant> createRoleGrants(Set<String> roles, Set<TrinoPrincipal> grantees, boolean adminOption, Optional<TrinoPrincipal> grantor) {
checkArgument(grantor.isEmpty(), "Grantor is not yet supported");
Set<RoleGrant> roleGrantToAdd = new HashSet<>();
for (String role : roles) {
for (TrinoPrincipal grantee : grantees) {
roleGrantToAdd.add(new RoleGrant(grantee, role, adminOption));
}
}
return roleGrantToAdd;
}
Aggregations