Can't authenticate with different NTLM credentials in one session with java.net.URLConnection

Posted by ndn on Stack Overflow See other posts from Stack Overflow or by ndn
Published on 2010-02-05T16:26:30Z Indexed on 2010/06/09 23:12 UTC
Read the original article Hit count: 370

Filed under:
|
|
|
|

When I access a HTTP server using the standard Java API (java.net.URLConnection), the credentials are "cached" after the first successful authentication, and subsequent calls to Authenticator.setDefault() have no effect. So, I need to restart the application in order to use different credentials.

I don't observe this effect when Basic Authentication is used. But I need to use NTLM for the server I'm accessing, and the Jakarta Commons HttpClient isn't an alternative either because it doesn't support NTLMv2 (see http://oaklandsoftware.com/papers/ntlm.html)

Looking at the packets using Wireshark, I also observe that before the first successful authentication, an authentication with the current Windows credentials is attempted first. But after succesful authentication, only the saved credentials are used.

Is there any way to reset or change the credentials java.net.Authenticator is using after a successful NTLM authentication?

© Stack Overflow or respective owner

Related posts about java

Related posts about Windows