diff --git a/client/trino-cli/src/test/java/io/trino/cli/TestQueryRunner.java b/client/trino-cli/src/test/java/io/trino/cli/TestQueryRunner.java index fe012eab80d48c..2975565aa469d7 100644 --- a/client/trino-cli/src/test/java/io/trino/cli/TestQueryRunner.java +++ b/client/trino-cli/src/test/java/io/trino/cli/TestQueryRunner.java @@ -115,7 +115,7 @@ static ClientSession createClientSession(MockWebServer server) { return ClientSession.builder() .server(server.url("/").uri()) - .principal(Optional.of("user")) + .user(Optional.of("user")) .source("source") .clientInfo("clientInfo") .catalog("catalog") diff --git a/client/trino-client/src/main/java/io/trino/client/ClientSession.java b/client/trino-client/src/main/java/io/trino/client/ClientSession.java index f8fd6762107d42..e803ffe9dec812 100644 --- a/client/trino-client/src/main/java/io/trino/client/ClientSession.java +++ b/client/trino-client/src/main/java/io/trino/client/ClientSession.java @@ -36,7 +36,7 @@ public class ClientSession { private final URI server; - private final Optional principal; + private final Optional user; private final Optional sessionUser; private final Optional authorizationUser; private final String source; @@ -77,7 +77,7 @@ public static ClientSession stripTransactionId(ClientSession session) private ClientSession( URI server, - Optional principal, + Optional user, Optional sessionUser, Optional authorizationUser, String source, @@ -100,7 +100,7 @@ private ClientSession( Optional encoding) { this.server = requireNonNull(server, "server is null"); - this.principal = requireNonNull(principal, "principal is null"); + this.user = requireNonNull(user, "user is null"); this.sessionUser = requireNonNull(sessionUser, "user is null"); this.authorizationUser = requireNonNull(authorizationUser, "authorizationUser is null"); this.source = requireNonNull(source, "source is null"); @@ -156,9 +156,9 @@ public URI getServer() return server; } - public Optional getPrincipal() + public Optional getUser() { - return principal; + return user; } public Optional getSessionUser() @@ -274,7 +274,7 @@ public String toString() { return toStringHelper(this) .add("server", server) - .add("principal", principal) + .add("user", user) .add("sessionUser", sessionUser) .add("authorizationUser", authorizationUser) .add("clientTags", clientTags) @@ -299,7 +299,7 @@ public String toString() public static final class Builder { private URI server; - private Optional principal = Optional.empty(); + private Optional user = Optional.empty(); private Optional sessionUser = Optional.empty(); private Optional authorizationUser = Optional.empty(); private String source; @@ -327,7 +327,7 @@ private Builder(ClientSession clientSession) { requireNonNull(clientSession, "clientSession is null"); server = clientSession.getServer(); - principal = clientSession.getPrincipal(); + user = clientSession.getUser(); sessionUser = clientSession.getSessionUser(); authorizationUser = clientSession.getAuthorizationUser(); source = clientSession.getSource(); @@ -368,9 +368,9 @@ public Builder authorizationUser(Optional authorizationUser) return this; } - public Builder principal(Optional principal) + public Builder user(Optional user) { - this.principal = principal; + this.user = user; return this; } @@ -486,7 +486,7 @@ public ClientSession build() { return new ClientSession( server, - principal, + user, sessionUser, authorizationUser, source, diff --git a/client/trino-client/src/main/java/io/trino/client/StatementClientV1.java b/client/trino-client/src/main/java/io/trino/client/StatementClientV1.java index 918e74915a8d1a..94633652bc8cc2 100644 --- a/client/trino-client/src/main/java/io/trino/client/StatementClientV1.java +++ b/client/trino-client/src/main/java/io/trino/client/StatementClientV1.java @@ -122,11 +122,11 @@ public StatementClientV1(Call.Factory httpCallFactory, Call.Factory segmentHttpC this.timeZone = session.getTimeZone(); this.query = query; this.requestTimeoutNanos = session.getClientRequestTimeout(); - this.user = Stream.of(session.getAuthorizationUser(), session.getSessionUser(), session.getPrincipal()) + this.user = Stream.of(session.getAuthorizationUser(), session.getSessionUser(), session.getUser()) .filter(Optional::isPresent) .map(Optional::get) .findFirst(); - this.originalUser = Stream.of(session.getSessionUser(), session.getPrincipal()) + this.originalUser = Stream.of(session.getSessionUser(), session.getUser()) .filter(Optional::isPresent) .map(Optional::get) .findFirst(); diff --git a/client/trino-client/src/main/java/io/trino/client/uri/TrinoUri.java b/client/trino-client/src/main/java/io/trino/client/uri/TrinoUri.java index a612a069098f13..e37db260a07474 100644 --- a/client/trino-client/src/main/java/io/trino/client/uri/TrinoUri.java +++ b/client/trino-client/src/main/java/io/trino/client/uri/TrinoUri.java @@ -491,7 +491,7 @@ public ClientSession.Builder toClientSessionBuilder() { return ClientSession.builder() .server(getHttpUri()) - .principal(getUser()) + .user(getUser()) .path(getPath().orElse(ImmutableList.of())) .clientRequestTimeout(getTimeout()) .sessionUser(getSessionUser()) diff --git a/client/trino-jdbc/src/main/java/io/trino/jdbc/TrinoConnection.java b/client/trino-jdbc/src/main/java/io/trino/jdbc/TrinoConnection.java index 2711c33baf9b5b..460859a026d64f 100644 --- a/client/trino-jdbc/src/main/java/io/trino/jdbc/TrinoConnection.java +++ b/client/trino-jdbc/src/main/java/io/trino/jdbc/TrinoConnection.java @@ -756,7 +756,7 @@ StatementClient startQuery(String sql, Map sessionPropertiesOver ClientSession session = ClientSession.builder() .server(httpUri) - .principal(user) + .user(user) .user(sessionUser.get()) .authorizationUser(Optional.ofNullable(authorizationUser.get())) .source(source) diff --git a/testing/trino-testing/src/main/java/io/trino/testing/AbstractTestingTrinoClient.java b/testing/trino-testing/src/main/java/io/trino/testing/AbstractTestingTrinoClient.java index f20fc786fee928..4b26b92fc6393d 100644 --- a/testing/trino-testing/src/main/java/io/trino/testing/AbstractTestingTrinoClient.java +++ b/testing/trino-testing/src/main/java/io/trino/testing/AbstractTestingTrinoClient.java @@ -159,7 +159,7 @@ private static ClientSession toClientSession(Session session, URI server, Durati estimates.getPeakMemoryBytes().ifPresent(e -> resourceEstimates.put(PEAK_MEMORY, e.toString())); return ClientSession.builder() .server(server) - .principal(Optional.of(session.getIdentity().getUser())) + .user(Optional.of(session.getIdentity().getUser())) .source(session.getSource().orElse("test")) .traceToken(session.getTraceToken()) .clientTags(session.getClientTags()) diff --git a/testing/trino-tests/src/test/java/io/trino/execution/TestFinalQueryInfo.java b/testing/trino-tests/src/test/java/io/trino/execution/TestFinalQueryInfo.java index ae9ae32e42c8d1..10472f629b1dd3 100644 --- a/testing/trino-tests/src/test/java/io/trino/execution/TestFinalQueryInfo.java +++ b/testing/trino-tests/src/test/java/io/trino/execution/TestFinalQueryInfo.java @@ -67,7 +67,7 @@ private static QueryId startQuery(String sql, QueryRunner queryRunner) try { ClientSession clientSession = ClientSession.builder() .server(queryRunner.getCoordinator().getBaseUrl()) - .principal(Optional.of("user")) + .user(Optional.of("user")) .source("source") .timeZone(ZoneId.of("America/Los_Angeles")) .locale(Locale.ENGLISH) diff --git a/testing/trino-tests/src/test/java/io/trino/execution/TestSetSessionAuthorization.java b/testing/trino-tests/src/test/java/io/trino/execution/TestSetSessionAuthorization.java index 5f2eaefb3b5fc9..71add281d460bd 100644 --- a/testing/trino-tests/src/test/java/io/trino/execution/TestSetSessionAuthorization.java +++ b/testing/trino-tests/src/test/java/io/trino/execution/TestSetSessionAuthorization.java @@ -57,7 +57,7 @@ protected QueryRunner createQueryRunner() public void testSetSessionAuthorizationToSelf() { ClientSession clientSession = defaultClientSessionBuilder() - .principal(Optional.of("user")) + .user(Optional.of("user")) .user(Optional.of("user")) .build(); assertThat(submitQuery("SET SESSION AUTHORIZATION user", clientSession).getSetAuthorizationUser().get()).isEqualTo("user"); @@ -69,13 +69,13 @@ public void testSetSessionAuthorizationToSelf() public void testValidSetSessionAuthorization() { ClientSession clientSession = defaultClientSessionBuilder() - .principal(Optional.of("user")) + .user(Optional.of("user")) .user(Optional.of("user")) .build(); assertThat(submitQuery("SET SESSION AUTHORIZATION alice", clientSession).getSetAuthorizationUser().get()).isEqualTo("alice"); clientSession = defaultClientSessionBuilder() - .principal(Optional.of("user2")) + .user(Optional.of("user2")) .user(Optional.of("user2")) .build(); assertThat(submitQuery("SET SESSION AUTHORIZATION bob", clientSession).getSetAuthorizationUser().get()).isEqualTo("bob"); @@ -85,7 +85,7 @@ public void testValidSetSessionAuthorization() public void testInvalidSetSessionAuthorization() { ClientSession clientSession = defaultClientSessionBuilder() - .principal(Optional.of("user")) + .user(Optional.of("user")) .user(Optional.of("user")) .build(); assertError(submitQuery("SET SESSION AUTHORIZATION user2", clientSession), @@ -107,19 +107,19 @@ public void testInvalidSetSessionAuthorization() public void testInvalidTransitiveSetSessionAuthorization() { ClientSession clientSession = defaultClientSessionBuilder() - .principal(Optional.of("user")) + .user(Optional.of("user")) .user(Optional.of("user")) .build(); assertThat(submitQuery("SET SESSION AUTHORIZATION alice", clientSession).getSetAuthorizationUser().get()).isEqualTo("alice"); clientSession = defaultClientSessionBuilder() - .principal(Optional.of("alice")) + .user(Optional.of("alice")) .user(Optional.of("alice")) .build(); assertThat(submitQuery("SET SESSION AUTHORIZATION charlie", clientSession).getSetAuthorizationUser().get()).isEqualTo("charlie"); clientSession = defaultClientSessionBuilder() - .principal(Optional.of("user")) + .user(Optional.of("user")) .user(Optional.of("user")) .build(); assertThat(submitQuery("SET SESSION AUTHORIZATION alice", clientSession).getSetAuthorizationUser().get()).isEqualTo("alice"); @@ -131,21 +131,21 @@ public void testInvalidTransitiveSetSessionAuthorization() public void testValidSessionAuthorizationExecution() { ClientSession clientSession = defaultClientSessionBuilder() - .principal(Optional.of("user")) + .user(Optional.of("user")) .user(Optional.of("user")) .authorizationUser(Optional.of("alice")) .build(); assertThat(submitQuery("SELECT 1+1", clientSession).currentStatusInfo().getError()).isEqualTo(null); clientSession = defaultClientSessionBuilder() - .principal(Optional.of("user")) + .user(Optional.of("user")) .user(Optional.of("user")) .authorizationUser(Optional.of("user")) .build(); assertThat(submitQuery("SELECT 1+1", clientSession).currentStatusInfo().getError()).isEqualTo(null); clientSession = defaultClientSessionBuilder() - .principal(Optional.of("user")) + .user(Optional.of("user")) .authorizationUser(Optional.of("alice")) .build(); assertThat(submitQuery("SELECT 1+1", clientSession).currentStatusInfo().getError()).isEqualTo(null); @@ -155,7 +155,7 @@ public void testValidSessionAuthorizationExecution() public void testInvalidSessionAuthorizationExecution() { ClientSession clientSession = defaultClientSessionBuilder() - .principal(Optional.of("user")) + .user(Optional.of("user")) .user(Optional.of("user")) .authorizationUser(Optional.of("user2")) .build(); @@ -163,7 +163,7 @@ public void testInvalidSessionAuthorizationExecution() PERMISSION_DENIED.toErrorCode(), "Access Denied: User user cannot impersonate user user2"); clientSession = defaultClientSessionBuilder() - .principal(Optional.of("user")) + .user(Optional.of("user")) .user(Optional.of("user")) .authorizationUser(Optional.of("user3")) .build(); @@ -171,7 +171,7 @@ public void testInvalidSessionAuthorizationExecution() PERMISSION_DENIED.toErrorCode(), "Access Denied: User user cannot impersonate user user3"); clientSession = defaultClientSessionBuilder() - .principal(Optional.of("user")) + .user(Optional.of("user")) .user(Optional.of("user")) .authorizationUser(Optional.of("charlie")) .build(); @@ -183,7 +183,7 @@ public void testInvalidSessionAuthorizationExecution() public void testSelectCurrentUser() { ClientSession clientSession = defaultClientSessionBuilder() - .principal(Optional.of("user")) + .user(Optional.of("user")) .user(Optional.of("user")) .authorizationUser(Optional.of("alice")) .build(); @@ -198,7 +198,7 @@ public void testSelectCurrentUser() public void testResetSessionAuthorization() { ClientSession clientSession = defaultClientSessionBuilder() - .principal(Optional.of("user")) + .user(Optional.of("user")) .user(Optional.of("user")) .build(); assertResetAuthorizationUser(submitQuery("RESET SESSION AUTHORIZATION", clientSession)); diff --git a/testing/trino-tests/src/test/java/io/trino/execution/TestUserImpersonationAccessControl.java b/testing/trino-tests/src/test/java/io/trino/execution/TestUserImpersonationAccessControl.java index eaabc557816517..bed08169452124 100644 --- a/testing/trino-tests/src/test/java/io/trino/execution/TestUserImpersonationAccessControl.java +++ b/testing/trino-tests/src/test/java/io/trino/execution/TestUserImpersonationAccessControl.java @@ -81,7 +81,7 @@ private QueryError trySelectQuery(String assumedUser) try { ClientSession clientSession = ClientSession.builder() .server(getDistributedQueryRunner().getCoordinator().getBaseUrl()) - .principal(Optional.of("user")) + .user(Optional.of("user")) .user(Optional.of(assumedUser)) .source("source") .timeZone(ZoneId.of("America/Los_Angeles"))