use of io.trino.spi.security.SelectedRole in project trino by trinodb.
the class BaseHiveConnectorTest method testIoExplainFilterOnAgg.
@Test
public void testIoExplainFilterOnAgg() {
Session admin = Session.builder(getSession()).setIdentity(Identity.forUser("hive").withConnectorRole("hive", new SelectedRole(ROLE, Optional.of("admin"))).build()).build();
assertUpdate(admin, "create table io_explain_test_filter_on_agg(\n" + "id integer,\n" + "a varchar,\n" + "b varchar,\n" + "ds varchar)" + "WITH (format='PARQUET', partitioned_by = ARRAY['ds'])");
assertUpdate(admin, "insert into io_explain_test_filter_on_agg(id,a,ds) values(1, 'a','a')", 1);
EstimatedStatsAndCost estimate = new EstimatedStatsAndCost(1.0, 5.0, 5.0, 0.0, 0.0);
EstimatedStatsAndCost finalEstimate = new EstimatedStatsAndCost(Double.NaN, Double.NaN, Double.NaN, Double.NaN, Double.NaN);
MaterializedResult result = computeActual("EXPLAIN (TYPE IO, FORMAT JSON) SELECT * FROM (SELECT COUNT(*) cnt FROM io_explain_test_filter_on_agg WHERE b = 'b') WHERE cnt > 0");
assertEquals(getIoPlanCodec().fromJson((String) getOnlyElement(result.getOnlyColumnAsSet())), new IoPlan(ImmutableSet.of(new TableColumnInfo(new CatalogSchemaTableName(catalog, "tpch", "io_explain_test_filter_on_agg"), ImmutableSet.of(new ColumnConstraint("ds", VARCHAR, new FormattedDomain(false, ImmutableSet.of(new FormattedRange(new FormattedMarker(Optional.of("a"), EXACTLY), new FormattedMarker(Optional.of("a"), EXACTLY))))), new ColumnConstraint("b", VARCHAR, new FormattedDomain(false, ImmutableSet.of(new FormattedRange(new FormattedMarker(Optional.of("b"), EXACTLY), new FormattedMarker(Optional.of("b"), EXACTLY)))))), estimate)), Optional.empty(), finalEstimate));
assertUpdate("DROP TABLE io_explain_test_filter_on_agg");
}
use of io.trino.spi.security.SelectedRole in project trino by trinodb.
the class SetRoleTask method execute.
@Override
public ListenableFuture<Void> execute(SetRole statement, QueryStateMachine stateMachine, List<Expression> parameters, WarningCollector warningCollector) {
Session session = stateMachine.getSession();
Optional<String> catalog = processRoleCommandCatalog(metadata, session, statement, statement.getCatalog().map(Identifier::getValue));
if (statement.getType() == SetRole.Type.ROLE) {
String role = statement.getRole().map(c -> c.getValue().toLowerCase(ENGLISH)).orElseThrow();
if (!metadata.roleExists(session, role, catalog)) {
throw semanticException(ROLE_NOT_FOUND, statement, "Role '%s' does not exist", role);
}
if (catalog.isPresent()) {
accessControl.checkCanSetCatalogRole(SecurityContext.of(session), role, catalog.get());
} else {
Set<RoleGrant> roleGrants = metadata.listApplicableRoles(session, new TrinoPrincipal(USER, session.getUser()), Optional.empty());
if (roleGrants.stream().map(RoleGrant::getRoleName).noneMatch(role::equals)) {
denySetRole(role);
}
}
}
SelectedRole.Type type = toSelectedRoleType(statement.getType());
stateMachine.addSetRole(catalog.orElse("system"), new SelectedRole(type, statement.getRole().map(c -> c.getValue().toLowerCase(ENGLISH))));
return immediateVoidFuture();
}
use of io.trino.spi.security.SelectedRole in project trino by trinodb.
the class TestAccessControl method testShowRolesWithLegacyCatalogRoles.
@Test
public void testShowRolesWithLegacyCatalogRoles() {
Session session = testSessionBuilder().setCatalog("mock").setIdentity(Identity.forUser("alice").withConnectorRoles(ImmutableMap.of("mock", new SelectedRole(ROLE, Optional.of("alice_role")))).build()).setSystemProperty("legacy_catalog_roles", "true").build();
assertQuery(session, "SHOW ROLES", "VALUES 'alice_role'");
assertQuery(session, "SHOW ROLE GRANTS", "VALUES 'alice_role'");
assertQuery(session, "SHOW CURRENT ROLES", "VALUES 'alice_role'");
assertQuery(session, "SELECT * FROM mock.information_schema.applicable_roles", "SELECT 'alice', 'USER', 'alice_role', 'NO'");
}
use of io.trino.spi.security.SelectedRole in project trino by trinodb.
the class AbstractTestingTrinoClient method getRoles.
private static Map<String, ClientSelectedRole> getRoles(Session session) {
ImmutableMap.Builder<String, ClientSelectedRole> builder = ImmutableMap.builder();
session.getIdentity().getEnabledRoles().forEach(role -> builder.put("system", toClientSelectedRole(new SelectedRole(ROLE, Optional.of(role)))));
session.getIdentity().getCatalogRoles().forEach((key, value) -> builder.put(key, toClientSelectedRole(value)));
return builder.buildOrThrow();
}
use of io.trino.spi.security.SelectedRole in project trino by trinodb.
the class TestingSessionContext method fromSession.
public static SessionContext fromSession(Session session) {
requireNonNull(session, "session is null");
Set<String> enabledRoles = session.getIdentity().getEnabledRoles();
SelectedRole selectedRole;
if (enabledRoles.isEmpty()) {
selectedRole = new SelectedRole(Type.NONE, Optional.empty());
} else if (enabledRoles.size() == 1) {
selectedRole = new SelectedRole(Type.ROLE, Optional.of(enabledRoles.iterator().next()));
} else {
selectedRole = new SelectedRole(Type.ALL, Optional.empty());
}
return new SessionContext(session.getProtocolHeaders(), session.getCatalog(), session.getSchema(), session.getPath().getRawPath(), Optional.empty(), session.getIdentity(), selectedRole, session.getSource(), session.getTraceToken(), session.getUserAgent(), session.getRemoteUserAddress(), Optional.of(session.getTimeZoneKey().getId()), Optional.of(session.getLocale().getLanguage()), session.getClientTags(), session.getClientCapabilities(), session.getResourceEstimates(), session.getSystemProperties(), session.getCatalogProperties(), session.getPreparedStatements(), session.getTransactionId(), session.isClientTransactionSupport(), session.getClientInfo());
}
Aggregations