hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oleg Kalnichevski <ol...@apache.org>
Subject Re: NTLM proxy auth
Date Tue, 14 Mar 2006 16:26:07 GMT
On Tue, 2006-03-14 at 11:02 -0500, Wagner, John (MED US) wrote:
> Hi,
> 
> I am trying to access the web through our corporate proxy server with
> uses NTLM.  I have not been able to authenticate - receive 407 error.
> Attached is the code I'm using.  When viewing the proxy logs, they said
> that I was not passing any credentials to the proxy server and that is
> why I failed. 

John,

It is going to be pretty easy to tell if that is indeed the case if you
turn on the context/wire logging:

http://jakarta.apache.org/commons/httpclient/logging.html

If you need help interpreting the log, feel free to post it to this
list. You might want to remove security sensitive data (such as user
credentials) from the log prior to posting it

Oleg

>  Where did I go wrong?
> 
> import java.util.*;
> import java.io.*;
> 
> import org.apache.commons.httpclient.*;
> import org.apache.commons.httpclient.methods.*;
> import org.apache.commons.httpclient.params.HttpMethodParams;
> import org.apache.commons.httpclient.auth.*;
> 
> public class HttpClientNTLM {
>  
>   private static String url = "http://www.google.com/";
> 
>   public static void main(String[] args) {
>     // Create an instance of HttpClient.
>     HttpClient client = new HttpClient();
> 
>     String NTUser=username;
>     String NTPwd=password;
>     String NTDomain=domain;
> 
>     client.getHostConfiguration().setHost("www.google.com");
>     client.getHostConfiguration().setProxy(proxy host, 8080);
>    
>     List authPrefs = new ArrayList();
>     authPrefs.add(AuthPolicy.NTLM);
> 
>     client.getState().setProxyCredentials(
>             new AuthScope(null, 8080, null),
>             new NTCredentials(NTUser, NTPwd, "", NTDomain));
>    
>     client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY,
> authPrefs);
> 
>     // Create a method instance.
>     GetMethod method = new GetMethod(url);
>    
>     // Provide custom retry handler is necessary
>     method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
>       new DefaultHttpMethodRetryHandler(3, false));
> 
>     try {
>       // Execute the method.
>       int statusCode = client.executeMethod(method);
> 
>       if (statusCode != HttpStatus.SC_OK) {
>         System.err.println("Method failed: " + method.getStatusLine());
>       }
> 
>       // Read the response body.
>       byte[] responseBody = method.getResponseBody();
> 
>       // Deal with the response.
>       // Use caution: ensure correct character encoding and is not
> binary data
>       System.out.println(new String(responseBody));
> 
>     } catch (HttpException e) {
>       System.err.println("Fatal protocol violation: " + e.getMessage());
>       e.printStackTrace();
>     } catch (IOException e) {
>       System.err.println("Fatal transport error: " + e.getMessage());
>       e.printStackTrace();
>     } finally {
>       // Release the connection.
>       method.releaseConnection();
>     } 
>   }
> }
> 
> 
> -------------------------------------------------------------------------------
> This message and any included attachments are from Siemens Medical Solutions
> USA, Inc. and are intended only for the addressee(s). 
> The information contained herein may include trade secrets or privileged or
> otherwise confidential information.  Unauthorized review, forwarding, printing,
> copying, distributing, or using such information is strictly prohibited and may
> be unlawful.  If you received this message in error, or have reason to believe
> you are not authorized to receive it, please promptly delete this message and
> notify the sender by e-mail with a copy to Central.SecurityOffice@shs.siemens.com
> 
> Thank you


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-dev-help@jakarta.apache.org


Mime
View raw message