code: private String getUserName(TOpenSessionReq req) throws HiveSQLException {
      String userName = null;
      // Kerberos
      if (isKerberosAuthMode()) {
        userName = hiveAuthFactory.getRemoteUser();
      }
      // Except kerberos, NOSASL
      if (userName == null) {
        userName = TSetIpAddressProcessor.getUserName();
      }
      // Http transport mode.
      // We set the thread local username, in ThriftHttpServlet.
      if (cliService.getHiveConf().getVar(
          ConfVars.HIVE_SERVER2_TRANSPORT_MODE).equalsIgnoreCase("http")) {
        userName = SessionManager.getUserName();
      }
      if (userName == null) {
        userName = req.getUsername();
      }
  
      userName = getShortName(userName);
      String effectiveClientUser = getProxyUser(userName, req.getConfiguration(), getIpAddress());
      LOG.debug("Client's username: " + effectiveClientUser);
      return effectiveClientUser;
    }
docs: Returns the effective username.
  1. If hive.server2.allow.user.substitution = false: the username of the connecting user
  2. If hive.server2.allow.user.substitution = true: the username of the end user,
  that the connecting user is trying to proxy for.
  This includes a check whether the connecting user is allowed to proxy for the end user.
  @param req
  @return
  @throws HiveSQLException