Skip to content

Commit

Permalink
Rename principal to user in ClientSession
Browse files Browse the repository at this point in the history
This matches the naming in other parts of the code
  • Loading branch information
wendigo committed Sep 26, 2024
1 parent 0f32e3b commit 0991726
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
public class ClientSession
{
private final URI server;
private final Optional<String> principal;
private final Optional<String> user;
private final Optional<String> sessionUser;
private final Optional<String> authorizationUser;
private final String source;
Expand Down Expand Up @@ -77,7 +77,7 @@ public static ClientSession stripTransactionId(ClientSession session)

private ClientSession(
URI server,
Optional<String> principal,
Optional<String> user,
Optional<String> sessionUser,
Optional<String> authorizationUser,
String source,
Expand All @@ -100,7 +100,7 @@ private ClientSession(
Optional<String> 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, "sessionUser is null");
this.authorizationUser = requireNonNull(authorizationUser, "authorizationUser is null");
this.source = requireNonNull(source, "source is null");
Expand Down Expand Up @@ -156,9 +156,9 @@ public URI getServer()
return server;
}

public Optional<String> getPrincipal()
public Optional<String> getUser()
{
return principal;
return user;
}

public Optional<String> getSessionUser()
Expand Down Expand Up @@ -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)
Expand All @@ -299,7 +299,7 @@ public String toString()
public static final class Builder
{
private URI server;
private Optional<String> principal = Optional.empty();
private Optional<String> user = Optional.empty();
private Optional<String> sessionUser = Optional.empty();
private Optional<String> authorizationUser = Optional.empty();
private String source;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -368,9 +368,9 @@ public Builder authorizationUser(Optional<String> authorizationUser)
return this;
}

public Builder principal(Optional<String> principal)
public Builder user(Optional<String> user)
{
this.principal = principal;
this.user = user;
return this;
}

Expand Down Expand Up @@ -486,7 +486,7 @@ public ClientSession build()
{
return new ClientSession(
server,
principal,
user,
sessionUser,
authorizationUser,
source,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,7 @@ StatementClient startQuery(String sql, Map<String, String> sessionPropertiesOver

ClientSession session = ClientSession.builder()
.server(httpUri)
.principal(user)
.user(user)
.user(sessionUser.get())
.authorizationUser(Optional.ofNullable(authorizationUser.get()))
.source(source)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ protected QueryRunner createQueryRunner()
public void testSetSessionAuthorizationToSelf()
{
ClientSession clientSession = defaultClientSessionBuilder()
.principal(Optional.of("user"))
.user(Optional.of("user"))
.sessionUser(Optional.of("user"))
.build();
assertThat(submitQuery("SET SESSION AUTHORIZATION user", clientSession).getSetAuthorizationUser().get()).isEqualTo("user");
Expand All @@ -69,13 +69,13 @@ public void testSetSessionAuthorizationToSelf()
public void testValidSetSessionAuthorization()
{
ClientSession clientSession = defaultClientSessionBuilder()
.principal(Optional.of("user"))
.user(Optional.of("user"))
.sessionUser(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"))
.sessionUser(Optional.of("user2"))
.build();
assertThat(submitQuery("SET SESSION AUTHORIZATION bob", clientSession).getSetAuthorizationUser().get()).isEqualTo("bob");
Expand All @@ -85,7 +85,7 @@ public void testValidSetSessionAuthorization()
public void testInvalidSetSessionAuthorization()
{
ClientSession clientSession = defaultClientSessionBuilder()
.principal(Optional.of("user"))
.user(Optional.of("user"))
.sessionUser(Optional.of("user"))
.build();
assertError(submitQuery("SET SESSION AUTHORIZATION user2", clientSession),
Expand All @@ -107,19 +107,19 @@ public void testInvalidSetSessionAuthorization()
public void testInvalidTransitiveSetSessionAuthorization()
{
ClientSession clientSession = defaultClientSessionBuilder()
.principal(Optional.of("user"))
.user(Optional.of("user"))
.sessionUser(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"))
.sessionUser(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"))
.sessionUser(Optional.of("user"))
.build();
assertThat(submitQuery("SET SESSION AUTHORIZATION alice", clientSession).getSetAuthorizationUser().get()).isEqualTo("alice");
Expand All @@ -131,21 +131,21 @@ public void testInvalidTransitiveSetSessionAuthorization()
public void testValidSessionAuthorizationExecution()
{
ClientSession clientSession = defaultClientSessionBuilder()
.principal(Optional.of("user"))
.user(Optional.of("user"))
.sessionUser(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"))
.sessionUser(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);
Expand All @@ -155,23 +155,23 @@ public void testValidSessionAuthorizationExecution()
public void testInvalidSessionAuthorizationExecution()
{
ClientSession clientSession = defaultClientSessionBuilder()
.principal(Optional.of("user"))
.user(Optional.of("user"))
.sessionUser(Optional.of("user"))
.authorizationUser(Optional.of("user2"))
.build();
assertError(submitQuery("SELECT 1+1", clientSession),
PERMISSION_DENIED.toErrorCode(), "Access Denied: User user cannot impersonate user user2");

clientSession = defaultClientSessionBuilder()
.principal(Optional.of("user"))
.user(Optional.of("user"))
.sessionUser(Optional.of("user"))
.authorizationUser(Optional.of("user3"))
.build();
assertError(submitQuery("SELECT 1+1", clientSession),
PERMISSION_DENIED.toErrorCode(), "Access Denied: User user cannot impersonate user user3");

clientSession = defaultClientSessionBuilder()
.principal(Optional.of("user"))
.user(Optional.of("user"))
.sessionUser(Optional.of("user"))
.authorizationUser(Optional.of("charlie"))
.build();
Expand All @@ -183,7 +183,7 @@ public void testInvalidSessionAuthorizationExecution()
public void testSelectCurrentUser()
{
ClientSession clientSession = defaultClientSessionBuilder()
.principal(Optional.of("user"))
.user(Optional.of("user"))
.sessionUser(Optional.of("user"))
.authorizationUser(Optional.of("alice"))
.build();
Expand All @@ -198,7 +198,7 @@ public void testSelectCurrentUser()
public void testResetSessionAuthorization()
{
ClientSession clientSession = defaultClientSessionBuilder()
.principal(Optional.of("user"))
.user(Optional.of("user"))
.sessionUser(Optional.of("user"))
.build();
assertResetAuthorizationUser(submitQuery("RESET SESSION AUTHORIZATION", clientSession));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ private QueryError trySelectQuery(String sessionUser)
try {
ClientSession clientSession = ClientSession.builder()
.server(getDistributedQueryRunner().getCoordinator().getBaseUrl())
.principal(Optional.of("user"))
.user(Optional.of("user"))
.sessionUser(Optional.of(sessionUser))
.source("source")
.timeZone(ZoneId.of("America/Los_Angeles"))
Expand Down

0 comments on commit 0991726

Please sign in to comment.