Search in sources :

Example 1 with SessionContext

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;
}
Also used : SessionContext(io.trino.server.SessionContext) Identity(io.trino.spi.security.Identity)

Example 2 with SessionContext

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());
}
Also used : SelectedRole(io.trino.spi.security.SelectedRole) SessionContext(io.trino.server.SessionContext)

Aggregations

SessionContext (io.trino.server.SessionContext)2 Identity (io.trino.spi.security.Identity)1 SelectedRole (io.trino.spi.security.SelectedRole)1