hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oleg Kalnichevski <ol...@apache.org>
Subject Re: Issues accessing NTLM server using HTTPClient 4.1
Date Fri, 11 Nov 2011 08:17:21 GMT
On Thu, Nov 10, 2011 at 06:40:59AM -0800, Srivatsan wrote:
> 
> Have a similar issue. With the code below - authentication is unsuccessful
> when using the credentials of a local user. By local user, the domain name /
> realm is the host itself. However, authentication is successful with the
> same credentials when accessed from browser.
> 
>                 DefaultHttpClient httpclient = new DefaultHttpClient();
> 		List<String> authpref = new ArrayList<String>(); 
> 		authpref.add(AuthPolicy.NTLM);
> 		httpclient.getParams().setParameter(AuthPNames.TARGET_AUTH_PREF,
> authpref); 
> 		NTCredentials creds = new NTCredentials("uid", "pwd", "ip", "domain");
> 		httpclient.getCredentialsProvider().setCredentials(AuthScope.ANY, creds);
> 		HttpHost target = new HttpHost(<IP>, 80, "http");
> 		// Make sure the same context is used to execute logically related
> requests
> 		HttpContext localContext = new BasicHttpContext();
> 		// Execute a cheap method first. This will trigger NTLM authentication
> 		HttpGet httpget = new HttpGet(<URL>);
> 		HttpResponse response;
> 		try {
> 			response = httpclient.execute(target, httpget, localContext);
> 			System.out.println("Status Code:" +
> response1.getStatusLine().getStatusCode());
> 			BufferedReader isr = new BufferedReader (new
> InputStreamReader(response.getEntity().getContent()));
> 			while (isr.readLine() != null) {
> 				System.out.println("Content is: ********" + isr.readLine());
> 			}
> 			HttpEntity entity = response1.getEntity();
> 			EntityUtils.consume(entity);			
> 		} catch (ClientProtocolException e) {
> 			// TODO Auto-generated catch block
> 			e.printStackTrace();
> 		} catch (IOException e) {
> 			// TODO Auto-generated catch block
> 			e.printStackTrace();
> 		}
> 
> Added the HTTP wire log.
> http://old.nabble.com/file/p32819071/localuser-nabble.txt
> localuser-nabble.txt 
> 
> Any pointers, please?
> 

I see nothing unusual in the HTTP session log. The three-way NTLM message exchange seems normal.
You can try using CIFS as an alternative NTLN engine and see if that makes any difference
[1]. If that does not help, there must be something wrong with the credentials.

Oleg

[1] http://hc.apache.org/httpcomponents-client-ga/ntlm.html


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


Mime
View raw message