private void processSamlToken(String[] rets, Socket socket) throws IOException, SFException
  {
    String targetLine = null;
    String userAgent = null;
    boolean isPost = false;
    for (String line : rets)
    {
      if (line.length() > PREFIX_GET.length() &&
          line.substring(0, PREFIX_GET.length()).equalsIgnoreCase(PREFIX_GET))
      {
        targetLine = line;
      }
      else if (line.length() > PREFIX_POST.length() &&
               line.substring(0, PREFIX_POST.length()).equalsIgnoreCase(PREFIX_POST))
      {
        targetLine = rets[rets.length - 1];
        isPost = true;
      }
      else if (line.length() > PREFIX_USER_AGENT.length() &&
               line.substring(0, PREFIX_USER_AGENT.length()).equalsIgnoreCase(PREFIX_USER_AGENT))
      {
        userAgent = line;
      }
    }
    if (targetLine == null)
    {
      throw new SFException(ErrorCode.NETWORK_ERROR,
                            "Invalid HTTP request. No token is given from the browser.");
    }
    if (userAgent != null)
    {
      logger.debug("{}", userAgent);
    }

    try
    {
      // attempt to get JSON response
      extractJsonTokenFromPostRequest(targetLine);
    }
    catch (IOException ex)
    {
      String parameters = isPost ?
                          extractTokenFromPostRequest(targetLine) :
                          extractTokenFromGetRequest(targetLine);
      try
      {
        URI inputParameter = new URI(parameters);
        for (NameValuePair urlParam : URLEncodedUtils.parse(
            inputParameter, UTF8_CHARSET))
        {
          if ("token".equals(urlParam.getName()))
          {
            this.token = urlParam.getValue();
            break;
          }
        }
      }
      catch (URISyntaxException ex0)
      {
        throw new SFException(ErrorCode.NETWORK_ERROR,
                              String.format(
                                  "Invalid HTTP request. No token is given from the browser. %s, err: %s",
                                  targetLine, ex0));
      }
    }
    if (this.token == null)
    {
      throw new SFException(ErrorCode.NETWORK_ERROR,
                            String.format(
                                "Invalid HTTP request. No token is given from the browser: %s",
                                targetLine));
    }

    returnToBrowser(socket);
  }
private void processSamlToken ( String [ ] rets , Socket socket ) throws IOException , SFException { String targetLine = null ; String userAgent = null ; boolean isPost = false ; for ( String line : rets ) { if ( line . length ( ) > PREFIX_GET . length ( ) && line . substring ( 0 , PREFIX_GET . length ( ) ) . equalsIgnoreCase ( PREFIX_GET ) ) { targetLine = line ; } else if ( line . length ( ) > PREFIX_POST . length ( ) && line . substring ( 0 , PREFIX_POST . length ( ) ) . equalsIgnoreCase ( PREFIX_POST ) ) { targetLine = rets [ rets . length - 1 ] ; isPost = true ; } else if ( line . length ( ) > PREFIX_USER_AGENT . length ( ) && line . substring ( 0 , PREFIX_USER_AGENT . length ( ) ) . equalsIgnoreCase ( PREFIX_USER_AGENT ) ) { userAgent = line ; } } if ( targetLine == null ) { throw new SFException ( ErrorCode . NETWORK_ERROR , "Invalid HTTP request. No token is given from the browser." ) ; } if ( userAgent != null ) { logger . debug ( "{}" , userAgent ) ; } try { extractJsonTokenFromPostRequest ( targetLine ) ; } catch ( IOException ex ) { String parameters = isPost ? extractTokenFromPostRequest ( targetLine ) : extractTokenFromGetRequest ( targetLine ) ; try { URI inputParameter = new URI ( parameters ) ; for ( NameValuePair urlParam : URLEncodedUtils . parse ( inputParameter , UTF8_CHARSET ) ) { if ( "token" . equals ( urlParam . getName ( ) ) ) { this . token = urlParam . getValue ( ) ; break ; } } } catch ( URISyntaxException ex0 ) { throw new SFException ( ErrorCode . NETWORK_ERROR , String . format ( "Invalid HTTP request. No token is given from the browser. %s, err: %s" , targetLine , ex0 ) ) ; } } if ( this . token == null ) { throw new SFException ( ErrorCode . NETWORK_ERROR , String . format ( "Invalid HTTP request. No token is given from the browser: %s" , targetLine ) ) ; } returnToBrowser ( socket ) ; }
Receives SAML token from Snowflake via web browser

@param socket socket
@throws IOException if any IO error occurs
@throws SFException if a HTTP request from browser is invalid