/* (non-Javadoc) * @see org.apache.hive.service.cli.ICLIService#getInfo(org.apache.hive.service.cli.SessionHandle, java.util.List) */ @Override public GetInfoValue getInfo(SessionHandle sessionHandle, GetInfoType getInfoType) throws HiveSQLException { GetInfoValue infoValue = sessionManager.getSession(sessionHandle).getInfo(getInfoType); LOG.debug(sessionHandle + ": getInfo()"); return infoValue; }
private void setUserName(final TProtocol in) { TTransport transport = in.getTransport(); if (transport instanceof TSaslServerTransport) { String userName = ((TSaslServerTransport) transport).getSaslServer().getAuthorizationID(); SessionManager.setUserName(userName); } }
@Override public void renewDelegationToken( SessionHandle sessionHandle, HiveAuthFactory authFactory, String tokenStr) throws HiveSQLException { sessionManager.getSession(sessionHandle).renewDelegationToken(authFactory, tokenStr); LOG.info(sessionHandle + ": renewDelegationToken()"); }
/* (non-Javadoc) * @see org.apache.hive.service.cli.ICLIService#getSchemas(org.apache.hive.service.cli.SessionHandle, java.lang.String, java.lang.String) */ @Override public OperationHandle getSchemas( SessionHandle sessionHandle, String catalogName, String schemaName) throws HiveSQLException { OperationHandle opHandle = sessionManager.getSession(sessionHandle).getSchemas(catalogName, schemaName); LOG.debug(sessionHandle + ": getSchemas()"); return opHandle; }
/* (non-Javadoc) * @see org.apache.hive.service.cli.ICLIService#closeOperation(org.apache.hive.service.cli.OperationHandle) */ @Override public void closeOperation(OperationHandle opHandle) throws HiveSQLException { sessionManager .getOperationManager() .getOperation(opHandle) .getParentSession() .closeOperation(opHandle); LOG.debug(opHandle + ": closeOperation"); }
/* (non-Javadoc) * @see org.apache.hive.service.cli.ICLIService#openSession(java.lang.String, java.lang.String, java.util.Map) */ @Override public SessionHandle openSession( String username, String password, Map<String, String> configuration) throws HiveSQLException { SessionHandle sessionHandle = sessionManager.openSession( SERVER_VERSION, username, password, null, configuration, false, null); LOG.debug(sessionHandle + ": openSession()"); return sessionHandle; }
/* (non-Javadoc) * @see org.apache.hive.service.cli.ICLIService#getPrimaryKeys(org.apache.hive.service.cli.SessionHandle) */ @Override public OperationHandle getPrimaryKeys( SessionHandle sessionHandle, String catalog, String schema, String table) throws HiveSQLException { OperationHandle opHandle = sessionManager.getSession(sessionHandle).getPrimaryKeys(catalog, schema, table); LOG.debug(sessionHandle + ": getPrimaryKeys()"); return opHandle; }
/** Execute statement asynchronously on the server. This is a non-blocking call */ @Override public OperationHandle executeStatementAsync( SessionHandle sessionHandle, String statement, Map<String, String> confOverlay) throws HiveSQLException { OperationHandle opHandle = sessionManager.getSession(sessionHandle).executeStatementAsync(statement, confOverlay); LOG.debug(sessionHandle + ": executeStatementAsync()"); return opHandle; }
/* (non-Javadoc) * @see org.apache.hive.service.cli.ICLIService#openSession(java.lang.String, java.lang.String, java.util.Map) */ @Override public SessionHandle openSessionWithImpersonation( String username, String password, Map<String, String> configuration, String delegationToken) throws HiveSQLException { SessionHandle sessionHandle = sessionManager.openSession( SERVER_VERSION, username, password, null, configuration, true, delegationToken); LOG.debug(sessionHandle + ": openSession()"); return sessionHandle; }
/** Used to restore session */ public void createSessionWithSessionHandle( SessionHandle sessionHandle, String username, String password, Map<String, String> configuration) throws HiveSQLException { sessionManager.createSession( sessionHandle, SERVER_VERSION, username, password, null, configuration, false, null); LOG.debug(sessionHandle + ": createSessionWithSessionHandle()"); }
@Override public String getDelegationToken( SessionHandle sessionHandle, HiveAuthFactory authFactory, String owner, String renewer) throws HiveSQLException { String delegationToken = sessionManager.getSession(sessionHandle).getDelegationToken(authFactory, owner, renewer); LOG.info( sessionHandle + ": getDelegationToken()" + " owner: " + owner + ", renewer: " + renewer); return delegationToken; }
/* (non-Javadoc) * @see org.apache.hive.service.cli.ICLIService#getResultSetMetadata(org.apache.hive.service.cli.OperationHandle) */ @Override public TableSchema getResultSetMetadata(OperationHandle opHandle) throws HiveSQLException { TableSchema tableSchema = sessionManager .getOperationManager() .getOperation(opHandle) .getParentSession() .getResultSetMetadata(opHandle); LOG.debug(opHandle + ": getResultSetMetadata()"); return tableSchema; }
/** @deprecated Use {@link #openSession(TProtocolVersion, String, String, String, Map)} */ @Deprecated public SessionHandle openSession( TProtocolVersion protocol, String username, String password, Map<String, String> configuration) throws HiveSQLException { SessionHandle sessionHandle = sessionManager.openSession(protocol, username, password, null, configuration, false, null); LOG.debug(sessionHandle + ": openSession()"); return sessionHandle; }
@Override public RowSet fetchResults( OperationHandle opHandle, FetchOrientation orientation, long maxRows, FetchType fetchType) throws HiveSQLException { RowSet rowSet = sessionManager .getOperationManager() .getOperation(opHandle) .getParentSession() .fetchResults(opHandle, orientation, maxRows, fetchType); LOG.debug(opHandle + ": fetchResults()"); return rowSet; }
public SessionHandle openSessionWithImpersonation( TProtocolVersion protocol, String username, String password, String ipAddress, Map<String, String> configuration, String delegationToken) throws HiveSQLException { SessionHandle sessionHandle = sessionManager.openSession( protocol, username, password, ipAddress, configuration, true, delegationToken); LOG.debug(sessionHandle + ": openSession()"); return sessionHandle; }
/* (non-Javadoc) * @see org.apache.hive.service.cli.ICLIService#getTables(org.apache.hive.service.cli.SessionHandle, java.lang.String, java.lang.String, java.lang.String, java.util.List) */ @Override public OperationHandle getTables( SessionHandle sessionHandle, String catalogName, String schemaName, String tableName, List<String> tableTypes) throws HiveSQLException { OperationHandle opHandle = sessionManager .getSession(sessionHandle) .getTables(catalogName, schemaName, tableName, tableTypes); LOG.debug(sessionHandle + ": getTables()"); return opHandle; }
/* (non-Javadoc) * @see org.apache.hive.service.cli.ICLIService#getOperationStatus(org.apache.hive.service.cli.OperationHandle) */ @Override public OperationStatus getOperationStatus(OperationHandle opHandle) throws HiveSQLException { Operation operation = sessionManager.getOperationManager().getOperation(opHandle); /** * If this is a background operation run asynchronously, we block for a duration determined by a * step function, before we return However, if the background operation is complete, we return * immediately. */ if (operation.shouldRunAsync()) { HiveConf conf = operation.getParentSession().getHiveConf(); long maxTimeout = HiveConf.getTimeVar( conf, HiveConf.ConfVars.HIVE_SERVER2_LONG_POLLING_TIMEOUT, TimeUnit.MILLISECONDS); final long elapsed = System.currentTimeMillis() - operation.getBeginTime(); // A step function to increase the polling timeout by 500 ms every 10 sec, // starting from 500 ms up to HIVE_SERVER2_LONG_POLLING_TIMEOUT final long timeout = Math.min(maxTimeout, (elapsed / TimeUnit.SECONDS.toMillis(10) + 1) * 500); try { operation.getBackgroundHandle().get(timeout, TimeUnit.MILLISECONDS); } catch (TimeoutException e) { // No Op, return to the caller since long polling timeout has expired LOG.trace(opHandle + ": Long polling timed out"); } catch (CancellationException e) { // The background operation thread was cancelled LOG.trace(opHandle + ": The background operation was cancelled", e); } catch (ExecutionException e) { // The background operation thread was aborted LOG.warn(opHandle + ": The background operation was aborted", e); } catch (InterruptedException e) { // No op, this thread was interrupted // In this case, the call might return sooner than long polling timeout } } OperationStatus opStatus = operation.getStatus(); LOG.debug(opHandle + ": getOperationStatus()"); return opStatus; }
/* (non-Javadoc) * @see org.apache.hive.service.cli.ICLIService#getCrossReference(org.apache.hive.service.cli.SessionHandle) */ @Override public OperationHandle getCrossReference( SessionHandle sessionHandle, String primaryCatalog, String primarySchema, String primaryTable, String foreignCatalog, String foreignSchema, String foreignTable) throws HiveSQLException { OperationHandle opHandle = sessionManager .getSession(sessionHandle) .getCrossReference( primaryCatalog, primarySchema, primaryTable, foreignCatalog, foreignSchema, foreignTable); LOG.debug(sessionHandle + ": getCrossReference()"); return opHandle; }
private void setIpAddress(Socket socket) { SessionManager.setIpAddress(socket.getInetAddress().toString()); }
/* (non-Javadoc) * @see org.apache.hive.service.cli.ICLIService#closeSession(org.apache.hive.service.cli.SessionHandle) */ @Override public void closeSession(SessionHandle sessionHandle) throws HiveSQLException { sessionManager.closeSession(sessionHandle); LOG.debug(sessionHandle + ": closeSession()"); }
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String clientUserName = null; String clientIpAddress; boolean requireNewCookie = false; try { if (hiveConf.getBoolean(ConfVars.HIVE_SERVER2_XSRF_FILTER_ENABLED.varname, false)) { boolean continueProcessing = Utils.doXsrfFilter(request, response, null, null); if (!continueProcessing) { LOG.warn("Request did not have valid XSRF header, rejecting."); return; } } // If the cookie based authentication is already enabled, parse the // request and validate the request cookies. if (isCookieAuthEnabled) { clientUserName = validateCookie(request); requireNewCookie = (clientUserName == null); if (requireNewCookie) { LOG.info("Could not validate cookie sent, will try to generate a new cookie"); } } // If the cookie based authentication is not enabled or the request does // not have a valid cookie, use the kerberos or password based authentication // depending on the server setup. if (clientUserName == null) { // For a kerberos setup if (isKerberosAuthMode(authType)) { String delegationToken = request.getHeader(HIVE_DELEGATION_TOKEN_HEADER); // Each http request must have an Authorization header if ((delegationToken != null) && (!delegationToken.isEmpty())) { clientUserName = doTokenAuth(request, response); } else { clientUserName = doKerberosAuth(request); } } // For password based authentication else { clientUserName = doPasswdAuth(request, authType); } } LOG.debug("Client username: "******"Client IP Address: " + clientIpAddress); // Set the thread local ip address SessionManager.setIpAddress(clientIpAddress); // get forwarded hosts address String forwarded_for = request.getHeader(X_FORWARDED_FOR); if (forwarded_for != null) { LOG.debug("{}:{}", X_FORWARDED_FOR, forwarded_for); List<String> forwardedAddresses = Arrays.asList(forwarded_for.split(",")); SessionManager.setForwardedAddresses(forwardedAddresses); } else { SessionManager.setForwardedAddresses(Collections.<String>emptyList()); } // Generate new cookie and add it to the response if (requireNewCookie && !authType.equalsIgnoreCase(HiveAuthFactory.AuthTypes.NOSASL.toString())) { String cookieToken = HttpAuthUtils.createCookieToken(clientUserName); Cookie hs2Cookie = createCookie(signer.signCookie(cookieToken)); if (isHttpOnlyCookie) { response.setHeader("SET-COOKIE", getHttpOnlyCookieHeader(hs2Cookie)); } else { response.addCookie(hs2Cookie); } LOG.info("Cookie added for clientUserName " + clientUserName); } super.doPost(request, response); } catch (HttpAuthenticationException e) { LOG.error("Error: ", e); // Send a 401 to the client response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); if (isKerberosAuthMode(authType)) { response.addHeader(HttpAuthUtils.WWW_AUTHENTICATE, HttpAuthUtils.NEGOTIATE); } response.getWriter().println("Authentication Error: " + e.getMessage()); } finally { // Clear the thread locals SessionManager.clearUserName(); SessionManager.clearIpAddress(); SessionManager.clearProxyUserName(); SessionManager.clearForwardedAddresses(); } }
/* (non-Javadoc) * @see org.apache.hive.service.cli.ICLIService#getTableTypes(org.apache.hive.service.cli.SessionHandle) */ @Override public OperationHandle getTableTypes(SessionHandle sessionHandle) throws HiveSQLException { OperationHandle opHandle = sessionManager.getSession(sessionHandle).getTableTypes(); LOG.debug(sessionHandle + ": getTableTypes()"); return opHandle; }