views:

216

answers:

2

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?

+1  A: 

Would HttpClient 4.x + jCIFS 1.3.x be an alternative?

antispam
+1  A: 

Nope

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6626700

indicates this is an outstanding bug. An author in there suggests some nasty reflection magic to get past this. That's ok as long as this is in-house and documented as fragile and potentially breaking. Certainly not great

MJB