private boolean needsRedirect(HttpServletRequest request,
      HttpServletResponse response) {
    String token = extractBearerToken(request, response);
    // if there is a bearer token; we use to authenticate else we look for
    // the response port header just to make sure we are not generating
    // SAML requests for any random http post requests.
    if (token != null) {
      return false;
    }
    try {
      HiveSamlUtils.validateSamlResponsePort(request);
      return true;
    } catch (HttpSamlAuthenticationException e) {
      LOG.debug("Response port could not be validated: " + e.getMessage());
    }
    return false;
  }
A request needs redirect if it does not have a bearer token and it contains a valid
response port in its header.
service/src/java/org/apache/hive/service/cli/thrift/ThriftHttpServlet.java