private SessionHandle getSessionHandle(TOpenSessionReq req, TOpenSessionResp res, String userName)
      throws HiveSQLException, LoginException, IOException {
    final String ipAddress = getIpAddress();

    LOG.info("Creating Hive session handle for user [{}] from IP {}", req.getUsername(), ipAddress);

    TProtocolVersion protocol = getMinVersion(CLIService.SERVER_VERSION,
        req.getClient_protocol());
    final SessionHandle sessionHandle;
    if (cliService.getHiveConf().getBoolVar(ConfVars.HIVE_SERVER2_ENABLE_DOAS) &&
        (userName != null)) {
      String delegationTokenStr = getDelegationToken(userName);
      sessionHandle = cliService.openSessionWithImpersonation(protocol, userName,
          req.getPassword(), ipAddress, req.getConfiguration(), delegationTokenStr);
    } else {
      sessionHandle = cliService.openSession(protocol, userName, req.getPassword(),
          ipAddress, req.getConfiguration());
    }
    res.setServerProtocolVersion(protocol);
    return sessionHandle;
  }
Create a session handle
@param req
@param res
@return
@throws HiveSQLException
@throws LoginException
@throws IOException
service/src/java/org/apache/hive/service/cli/thrift/ThriftCLIService.java