common/src/main/java/HTTPClient/AuthorizationInfo.java
/**
     * Parses the authentication challenge(s) into an array of new info
     * structures for the specified host and port.
     *
     * @param challenge a string containing authentication info. This must
     *                  have the same format as value part of a
     *                  WWW-authenticate response header field, and may
     *                  contain multiple authentication challenges.
     * @param req       the original request.
     * @exception ProtocolException if any error during the parsing occurs.
     */
Parses the authentication challenge(s) into an array of new info
structures for the specified host and port.

@param challenge a string containing authentication info. This must
have the same format as value part of a
WWW-authenticate response header field, and may
contain multiple authentication challenges.
@param req       the original request.
@exception ProtocolException if any error during the parsing occurs.
Parses the authentication challenge ( s ) into an array of new info structures for the specified host and port . @param challenge a string containing authentication info . This must have the same format as value part of a WWW - authenticate response header field and may contain multiple authentication challenges . @param req the original request . @exception ProtocolException if any error during the parsing occurs .
static AuthorizationInfo[] parseAuthString(String challenge, RoRequest req,
					       RoResponse resp)
	    throws ProtocolException
    {
	int    beg = 0,
	       end = 0;
	char[] buf = challenge.toCharArray();
	int    len = buf.length;
	int[]  pos_ref = new int[2];
	AuthorizationInfo auth_arr[] = new AuthorizationInfo[0],
			  curr;
	while (Character.isWhitespace(buf[len-1]))  len--;
	while (true)			
	{
	    beg = Util.skipSpace(buf, beg);
	    if (beg == len)  break;
	    end = Util.findSpace(buf, beg+1);
	    int sts;
	    try
		{ sts = resp.getStatusCode(); }
	    catch (IOException ioe)
		{ throw new ProtocolException(ioe.toString()); }
	    if (sts == 401)
		curr = new AuthorizationInfo(req.getConnection().getHost(),
					     req.getConnection().getPort());
	    else
		curr = new AuthorizationInfo(req.getConnection().getProxyHost(),
					     req.getConnection().getProxyPort());
		if(Log.isEnabled(Log.EXTENDED_INFO))
		{
			Log.write(Log.EXTENDED_INFO, "ExtInfo: [Beg=" + beg + ", End=" + end + ", BufEnd=" + buf[end-1] + "]");
		}
	    /* Hack for schemes like NTLM which don't have any params or cookie.
	     * Mickeysoft, hello? What were you morons thinking here? I suppose
	     * you weren't, as usual, huh?
	     */
	    if (buf[end-1] == ',')
	    {
			if(end > beg)curr.scheme = challenge.substring(beg, end-1);
			else curr.scheme = challenge;
			try
			{
				if(curr.scheme.equalsIgnoreCase("Negotiate"))
				{
					beg = end;
					end = Util.findSpace(buf, beg + 1);
					curr.scheme = challenge.substring(beg, end).trim();
					if (buf[end-1] == ',')
						curr.scheme = curr.scheme.substring(0, curr.scheme.length() - 1);
				}
			}catch(Exception e)
			{
				if(Log.isEnabled(Log.EXTENDED_INFO))
				{
					Log.write(Log.EXTENDED_INFO, "ExtInfo: Exception ignored[1]: ", e);
					end = beg;
				}
			}
			\
			beg = end;
		}
	    else
	    {
			if(end >= beg)curr.scheme = challenge.substring(beg, end);
			else curr.scheme = challenge;
			try
			{
				if(curr.scheme.equalsIgnoreCase("Negotiate"))
				{
					beg = end;
					end = Util.findSpace(buf, beg + 1);
					if(end > challenge.length())
					{ 
						Log.write(Log.EXTENDED_INFO, "ExtInfo: No further challenge information. Assuming NTLM authentication");
						curr.scheme = "NTLM";
						end = beg; 
					}
					else
					{
						curr.scheme = challenge.substring(beg, end).trim();
						if (buf[end-1] == ',')
							curr.scheme = curr.scheme.substring(0, end-1);
					}
				}
			}catch(Exception e)
			{ 
				if(Log.isEnabled(Log.EXTENDED_INFO))
				{
					Log.write(Log.EXTENDED_INFO, "ExtInfo: Exception ignored[2]: ", e);
					Log.write(Log.EXTENDED_INFO, "ExtInfo: Assuming NTLM authentication ");
					curr.scheme = "NTLM";
					end = beg; 
				}
			}
			\
			pos_ref[0] = beg; pos_ref[1] = end;
			Vector params = parseParams(challenge, buf, pos_ref, len, curr);
			beg = pos_ref[0]; end = pos_ref[1];
			if (!params.isEmpty())
			{
				curr.auth_params = new NVPair[params.size()];
				params.copyInto(curr.auth_params);
			}
		}
	    if (curr.realm == null)
		/* Can't do this if we're supposed to allow for broken schemes
		 * such as NTLM, Kerberos, and PEM.
		 *
		throw new ProtocolException("Bad Authentication header "
		    + "format: " + challenge + "\nNo realm value found");
		 */
		curr.realm = "";
	    auth_arr = Util.resizeArray(auth_arr, auth_arr.length+1);
	    auth_arr[auth_arr.length-1] = curr;
		if(Log.isEnabled(Log.EXTENDED_INFO))
		{
			Log.write(Log.EXTENDED_INFO, "ExtInfo: Scheme Processed: " + curr.scheme  + " [Realm:" + curr.realm + "]");
		}
	}
	return auth_arr;
    }
static AuthorizationInfo [ ] parseAuthString ( String challenge , RoRequest req , RoResponse resp ) throws ProtocolException { int beg = 0 , end = 0 ; char [ ] buf = challenge . toCharArray ( ) ; int len = buf . length ; int [ ] pos_ref = new int [ 2 ] ; AuthorizationInfo auth_arr [ ] = new AuthorizationInfo [ 0 ] , curr ; while ( Character . isWhitespace ( buf [ len - 1 ] ) ) len -- ; while ( true ) { beg = Util . skipSpace ( buf , beg ) ; if ( beg == len ) break ; end = Util . findSpace ( buf , beg + 1 ) ; int sts ; try { sts = resp . getStatusCode ( ) ; } catch ( IOException ioe ) { throw new ProtocolException ( ioe . toString ( ) ) ; } if ( sts == 401 ) curr = new AuthorizationInfo ( req . getConnection ( ) . getHost ( ) , req . getConnection ( ) . getPort ( ) ) ; else curr = new AuthorizationInfo ( req . getConnection ( ) . getProxyHost ( ) , req . getConnection ( ) . getProxyPort ( ) ) ; if ( Log . isEnabled ( Log . EXTENDED_INFO ) ) { Log . write ( Log . EXTENDED_INFO , "ExtInfo: [Beg=" + beg + ", End=" + end + ", BufEnd=" + buf [ end - 1 ] + "]" ) ; } /* Hack for schemes like NTLM which don't have any params or cookie.
	     * Mickeysoft, hello? What were you morons thinking here? I suppose
	     * you weren't, as usual, huh?
	     */ if ( buf [ end - 1 ] == ',' ) { if ( end > beg ) curr . scheme = challenge . substring ( beg , end - 1 ) ; else curr . scheme = challenge ; try { if ( curr . scheme . equalsIgnoreCase ( "Negotiate" ) ) { beg = end ; end = Util . findSpace ( buf , beg + 1 ) ; curr . scheme = challenge . substring ( beg , end ) . trim ( ) ; if ( buf [ end - 1 ] == ',' ) curr . scheme = curr . scheme . substring ( 0 , curr . scheme . length ( ) - 1 ) ; } } catch ( Exception e ) { if ( Log . isEnabled ( Log . EXTENDED_INFO ) ) { Log . write ( Log . EXTENDED_INFO , "ExtInfo: Exception ignored[1]: " , e ) ; end = beg ; } } beg = end ; } else { if ( end >= beg ) curr . scheme = challenge . substring ( beg , end ) ; else curr . scheme = challenge ; try { if ( curr . scheme . equalsIgnoreCase ( "Negotiate" ) ) { beg = end ; end = Util . findSpace ( buf , beg + 1 ) ; if ( end > challenge . length ( ) ) { Log . write ( Log . EXTENDED_INFO , "ExtInfo: No further challenge information. Assuming NTLM authentication" ) ; curr . scheme = "NTLM" ; end = beg ; } else { curr . scheme = challenge . substring ( beg , end ) . trim ( ) ; if ( buf [ end - 1 ] == ',' ) curr . scheme = curr . scheme . substring ( 0 , end - 1 ) ; } } } catch ( Exception e ) { if ( Log . isEnabled ( Log . EXTENDED_INFO ) ) { Log . write ( Log . EXTENDED_INFO , "ExtInfo: Exception ignored[2]: " , e ) ; Log . write ( Log . EXTENDED_INFO , "ExtInfo: Assuming NTLM authentication " ) ; curr . scheme = "NTLM" ; end = beg ; } } pos_ref [ 0 ] = beg ; pos_ref [ 1 ] = end ; Vector params = parseParams ( challenge , buf , pos_ref , len , curr ) ; beg = pos_ref [ 0 ] ; end = pos_ref [ 1 ] ; if ( ! params . isEmpty ( ) ) { curr . auth_params = new NVPair [ params . size ( ) ] ; params . copyInto ( curr . auth_params ) ; } } if ( curr . realm == null ) /* Can't do this if we're supposed to allow for broken schemes
		 * such as NTLM, Kerberos, and PEM.
		 *
		throw new ProtocolException("Bad Authentication header "
		    + "format: " + challenge + "\nNo realm value found");
		 */ curr . realm = "" ; auth_arr = Util . resizeArray ( auth_arr , auth_arr . length + 1 ) ; auth_arr [ auth_arr . length - 1 ] = curr ; if ( Log . isEnabled ( Log . EXTENDED_INFO ) ) { Log . write ( Log . EXTENDED_INFO , "ExtInfo: Scheme Processed: " + curr . scheme + " [Realm:" + curr . realm + "]" ) ; } } return auth_arr ; }
Parses the authentication challenge(s) into an array of new info
 structures for the specified host and port.
Parses the authentication challenge ( s ) into an array of new info structures for the specified host and port .
// get all challenges // get scheme // @gusbro // Algunos servidores IIS (Win2000) fallan aqui porque ponen el scheme en Negotiate y los par�metros en NTLM // asi que lo chequeamos aca // @gusbro\ // @gusbro // Algunos servidores IIS (Win2000) fallan aqui porque ponen el scheme en Negotiate y los par�metros en NTLM // asi que lo chequeamos aca // @Hack: Si caigo aca tipicamente es porque el AuthString tiene SOLO Negotiate,  // as� que asumo que es NTLM	 // Aparte en este caso dejo Begin = end // @Hack: Si caigo aca tipicamente es porque el AuthString tiene SOLO Negotiate,  // as� que asumo que es NTLM	 // Aparte en este caso dejo Begin = end // @gusbro\