code: SessionHandle getSessionHandle(TOpenSessionReq req, TOpenSessionResp res)
        throws HiveSQLException, LoginException, IOException {
      String userName = getUserName(req);
      String ipAddress = getIpAddress();
      TProtocolVersion protocol = getMinVersion(CLIService.SERVER_VERSION,
          req.getClient_protocol());
      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;
    }
docs: Create a session handle
  @param req
  @param res
  @return
  @throws HiveSQLException
  @throws LoginException
  @throws IOException