diqiu50 commented on code in PR #10730:
URL: https://github.com/apache/gravitino/pull/10730#discussion_r3085250574
##########
trino-connector/trino-connector/src/main/java/org/apache/gravitino/trino/connector/GravitinoConnector.java:
##########
@@ -90,6 +142,45 @@ public ConnectorMetadata getMetadata(
ConnectorMetadata internalMetadata =
internalConnector.getMetadata(session,
gravitinoTransactionHandle.getInternalHandle());
Preconditions.checkArgument(internalMetadata != null, "Internal metadata
must not be null");
+
+ if (forwardUser) {
+ String credKey =
+ authType == GravitinoAuthProvider.AuthType.OAUTH2
+ ? "oauth2:" +
session.getIdentity().getExtraCredentials().get(oauth2CredentialKey)
+ : "simple:" + session.getUser();
+ UserSession userSession;
+ try {
+ userSession =
+ perUserSessionCache.get(
+ credKey,
+ () -> {
+ GravitinoAdminClient userClient =
+ GravitinoAuthProvider.buildForSession(
+ catalogConnectorContext.getConfig(), session);
+ GravitinoMetalake userMetalake =
+
userClient.loadMetalake(catalogConnectorContext.getMetalake().name());
+ CatalogConnectorMetadata userMetadata =
+ new CatalogConnectorMetadata(userMetalake,
catalogIdentifier);
+ return new UserSession(userClient, userMetadata);
+ });
+ } catch (ExecutionException e) {
+ Throwable cause = e.getCause();
+ LOG.warn(
+ "Failed to create per-user Gravitino client for user '{}': {}",
+ session.getUser(),
+ cause.getMessage());
+ throw new TrinoException(
+ PERMISSION_DENIED,
+ "Failed to authenticate user '"
+ + session.getUser()
+ + "' with Gravitino: "
+ + cause.getMessage(),
+ cause);
+ }
+ return createGravitinoMetadata(
+ userSession.metadata, catalogConnectorContext.getMetadataAdapter(),
internalMetadata);
+ }
Review Comment:
Integration test cover it
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]