You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by "Harri T." <ha...@gmail.com> on 2014/09/12 08:42:20 UTC

NTLMv2 sample code

Hi! Could someone provide me with a sample code for accessing NTLMv2 
authenticated service with HttpClient?

The page https://hc.apache.org/httpcomponents-client-4.3.x/ntlm.html has 
only sample code based on JCIFS.

Harri

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


Re: NTLMv2 sample code

Posted by "Harri T." <ha...@gmail.com>.
I finally got Negotiate NTLM authentication work with this piece of 
code: https://gist.github.com/moberwasserlechner/4690931

Harri

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


Re: NTLMv2 sample code

Posted by "Harri T." <ha...@gmail.com>.
On 12.9.2014 19:17, Harri T. wrote:
> Does HttpClient support NTLMSSP? If it does not, do you know some
> other Java library supporting NTLMSSP?

If I've understood right there's no Java HTTP client library supporting 
SPNEGO with NTLM: http://stackoverflow.com/a/6807008/2158271

Harri


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


Re: NTLMv2 sample code

Posted by "Harri T." <ha...@gmail.com>.
On 12.9.2014 14:09, Harri T. wrote:
> I captured network traffic when accessed with IE:
> 
>    IE                                        IIS
> 1 |--------------- GET /path --------------->|
> - |<--- 401, WWW-Authenticate: Negotiate ----|
> 2 |------ GET /path, NTLMSSP_NEGOTIATE ----->|
> - |<-------- 401, NTLMSSP_CHALLENGE ---------|
> 3 |--------- GET /path, NTLMSSP_AUTH ------->|
> - |<--------------- 200, OK -----------------|
> 
> Then I captured traffic when accessed with HttpClient and the requests 
> 2 and 3 aren't send at all.

Hi! Does HttpClient support NTLMSSP? If it does not, do you know some 
other Java library supporting NTLMSSP?

Harri

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


Re: NTLMv2 sample code

Posted by "Harri T." <ha...@gmail.com>.
On 12.9.2014 11:04, Oleg Kalnichevski wrote:
> http://hc.apache.org/httpcomponents-client-ga/httpclient/examples/org/apache/http/examples/client/ClientAuthentication.java
> 
> Oner just needs to provide NTCredentials instead of 
> UsernamePasswordCredentials.

Hi! I changed credentials to

  new NTCredentials(username, password, host, domain)

but the authentication fails (HTTP 401). I'm not familiar with NTLM 
authentication methods. Maybe this is not NTMLv2 but some other Windows 
based authentication method. I captured network traffic when accessed 
with IE:

  IE                                        IIS
1 |--------------- GET /path --------------->|
- |<--- 401, WWW-Authenticate: Negotiate ----|
2 |------ GET /path, NTLMSSP_NEGOTIATE ----->|
- |<-------- 401, NTLMSSP_CHALLENGE ---------|
3 |--------- GET /path, NTLMSSP_AUTH ------->|
- |<--------------- 200, OK -----------------|

Then I captured traffic when accessed with HttpClient and the requests 2 
and 3 aren't send at all.

Harri

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


Re: NTLMv2 sample code

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Fri, 2014-09-12 at 09:42 +0300, Harri T. wrote:
> Hi! Could someone provide me with a sample code for accessing NTLMv2 
> authenticated service with HttpClient?
> 
> The page https://hc.apache.org/httpcomponents-client-4.3.x/ntlm.html has 
> only sample code based on JCIFS.
> 
> Harri
> 

NTLMv2 auth is no different than other auth methods supported by
HttpClient

http://hc.apache.org/httpcomponents-client-ga/httpclient/examples/org/apache/http/examples/client/ClientAuthentication.java

Oner just needs to provide NTCredentials instead of
UsernamePasswordCredentials.

Oleg



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