You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by "Rowe, David (CAG-CC MIS)" <Da...@conagrafoods.com> on 2003/08/12 23:00:58 UTC

NTLM Auth Code Snippet

public class Authentication
{
    public Authentication() { }

    public static void main(String[] args) throws Exception 
    {
	System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.SimpleLog"); 
	System.setProperty("org.apache.commons.logging.simplelog.log.httpclient.wire", "debug"); 
	System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.commons.httpclient", "debug"); 
    	
      HttpClient client = new HttpClient();
		
	client.getHostConfiguration().setProxy("[our proxy]", 80);
        
      client.getState().setProxyCredentials(null,null,
      	new NTCredentials("[user name]", "[password]", "[our proxy]", "[domain]")
      );
             
      GetMethod get = new GetMethod("http://www.yahoo.com");

      get.setDoAuthentication( true );
      
	int status = client.executeMethod( get );
      
	System.out.println(status + "\n" + get.getResponseBodyAsString());
      
	get.releaseConnection();
    }
}


Supposedly this should Authenticate through the proxy, and output Yahoo!'s website.

If you can see anything that is needed please respond...

David Rowe
ConAgra Foods, Inc.
Web Application Development - Intern
7350 World Communications Drive
Omaha, NE  68122
Phone: (402) 998-2722
David.Rowe2@conagrafoods.com


Re: NTLM Auth Code Snippet

Posted by Oleg Kalnichevski <ol...@apache.org>.
David,
As far as I can tell the code looks all right. My only guess was that
the parameters to NTCredentials constructor might have been messed up,
but that does not seem to be the case.

I just tested the latest snapshot of 2.0 branch and HEAD against Squid
proxy using Basic authentication scheme. No surprises there.
Unfortunately I cannot test HTTP communication via a proxy with NTLM
authentication as I do not have a single one at my disposal (I tried to
configure Squid to use NTLM instead of Basic, but to no avail). I know
HttpClient has been reported to work fine with NTLM proxies on more than
one occasion. So, I would still like to kindly ask you to double-check
the credentials you have been used to authenticate with the proxy. If
you are 100% sure the credentials are fine, send us the complete wire &
debug log. If you happen to have access to the proxy server in question
it would also be worthwhile checking the server logs to see if there are
any clues as to why the authentication has been refused

Oleg

On Tue, 2003-08-12 at 23:00, Rowe, David (CAG-CC MIS) wrote:
> public class Authentication
> {
>     public Authentication() { }
> 
>     public static void main(String[] args) throws Exception 
>     {
> 	System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.SimpleLog"); 
> 	System.setProperty("org.apache.commons.logging.simplelog.log.httpclient.wire", "debug"); 
> 	System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.commons.httpclient", "debug"); 
>     	
>       HttpClient client = new HttpClient();
> 		
> 	client.getHostConfiguration().setProxy("[our proxy]", 80);
>         
>       client.getState().setProxyCredentials(null,null,
>       	new NTCredentials("[user name]", "[password]", "[our proxy]", "[domain]")
>       );
>              
>       GetMethod get = new GetMethod("http://www.yahoo.com");
> 
>       get.setDoAuthentication( true );
>       
> 	int status = client.executeMethod( get );
>       
> 	System.out.println(status + "\n" + get.getResponseBodyAsString());
>       
> 	get.releaseConnection();
>     }
> }
> 
> 
> Supposedly this should Authenticate through the proxy, and output Yahoo!'s website.
> 
> If you can see anything that is needed please respond...
> 
> David Rowe
> ConAgra Foods, Inc.
> Web Application Development - Intern
> 7350 World Communications Drive
> Omaha, NE  68122
> Phone: (402) 998-2722
> David.Rowe2@conagrafoods.com
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-httpclient-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-httpclient-dev-help@jakarta.apache.org
>