use of io.trino.security.SecurityContext in project trino by trinodb.
the class Session method beginTransactionId.
public Session beginTransactionId(TransactionId transactionId, TransactionManager transactionManager, AccessControl accessControl) {
requireNonNull(transactionId, "transactionId is null");
checkArgument(this.transactionId.isEmpty(), "Session already has an active transaction");
requireNonNull(transactionManager, "transactionManager is null");
requireNonNull(accessControl, "accessControl is null");
validateSystemProperties(accessControl, this.systemProperties);
// Now that there is a transaction, the catalog name can be resolved to a connector, and the catalog properties can be validated
ImmutableMap.Builder<String, Map<String, String>> connectorProperties = ImmutableMap.builder();
for (Entry<String, Map<String, String>> catalogEntry : this.catalogProperties.entrySet()) {
String catalogName = catalogEntry.getKey();
Map<String, String> catalogProperties = catalogEntry.getValue();
if (catalogProperties.isEmpty()) {
continue;
}
CatalogName catalog = transactionManager.getCatalogName(transactionId, catalogName).orElseThrow(() -> new TrinoException(NOT_FOUND, "Session property catalog does not exist: " + catalogName));
validateCatalogProperties(Optional.of(transactionId), accessControl, catalog, catalogProperties);
connectorProperties.put(catalogName, catalogProperties);
}
ImmutableMap.Builder<String, SelectedRole> connectorRoles = ImmutableMap.builder();
for (Entry<String, SelectedRole> entry : identity.getCatalogRoles().entrySet()) {
String catalogName = entry.getKey();
SelectedRole role = entry.getValue();
if (transactionManager.getCatalogName(transactionId, catalogName).isEmpty()) {
throw new TrinoException(NOT_FOUND, "Catalog for role does not exist: " + catalogName);
}
if (role.getType() == SelectedRole.Type.ROLE) {
accessControl.checkCanSetCatalogRole(new SecurityContext(transactionId, identity, queryId), role.getRole().orElseThrow(), catalogName);
}
connectorRoles.put(catalogName, role);
}
return new Session(queryId, Optional.of(transactionId), clientTransactionSupport, Identity.from(identity).withConnectorRoles(connectorRoles.buildOrThrow()).build(), source, catalog, schema, path, traceToken, timeZoneKey, locale, remoteUserAddress, userAgent, clientInfo, clientTags, clientCapabilities, resourceEstimates, start, systemProperties, connectorProperties.buildOrThrow(), sessionPropertyManager, preparedStatements, protocolHeaders);
}
Aggregations