use of io.trino.server.SessionContext in project trino by trinodb.
the class QueuedStatementResource method registerQuery.
private Query registerQuery(String statement, HttpServletRequest servletRequest, HttpHeaders httpHeaders) {
Optional<String> remoteAddress = Optional.ofNullable(servletRequest.getRemoteAddr());
Optional<Identity> identity = Optional.ofNullable((Identity) servletRequest.getAttribute(AUTHENTICATED_IDENTITY));
MultivaluedMap<String, String> headers = httpHeaders.getRequestHeaders();
SessionContext sessionContext = sessionContextFactory.createSessionContext(headers, alternateHeaderName, remoteAddress, identity);
Query query = new Query(statement, sessionContext, dispatchManager, queryInfoUrlFactory);
queryManager.registerQuery(query);
// let authentication filter know that identity lifecycle has been handed off
servletRequest.setAttribute(AUTHENTICATED_IDENTITY, null);
return query;
}
use of io.trino.server.SessionContext 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