code: private String getClientNameFromCookie(Cookie[] cookies) {
      // Current Cookie Name, Current Cookie Value
      String currName, currValue;
  
      // Following is the main loop which iterates through all the cookies send by the client.
      // The HS2 generated cookies are of the format hive.server2.auth=<value>
      // A cookie which is identified as a hiveserver2 generated cookie is validated
      // by calling signer.verifyAndExtract(). If the validation passes, send the
      // username for which the cookie is validated to the caller. If no client side
      // cookie passes the validation, return null to the caller.
      for (Cookie currCookie : cookies) {
        // Get the cookie name
        currName = currCookie.getName();
        if (!currName.equals(AUTH_COOKIE)) {
          // Not a HS2 generated cookie, continue.
          continue;
        }
        // If we reached here, we have match for HS2 generated cookie
        currValue = currCookie.getValue();
        // Validate the value.
        currValue = signer.verifyAndExtract(currValue);
        // Retrieve the user name, do the final validation step.
        if (currValue != null) {
          String userName = HttpAuthUtils.getUserNameFromCookieToken(currValue);
  
          if (userName == null) {
            LOG.warn("Invalid cookie token " + currValue);
            continue;
          }
          //We have found a valid cookie in the client request.
          if (LOG.isDebugEnabled()) {
            LOG.debug("Validated the cookie for user " + userName);
          }
          return userName;
        }
      }
      // No valid HS2 generated cookies found, return null
      return null;
    }
docs: Retrieves the client name from cookieString. If the cookie does not
  correspond to a valid client, the function returns null.
  @param cookies HTTP Request cookies.
  @return Client Username if cookieString has a HS2 Generated cookie that is currently valid.
  Else, returns null.