Cannot authenticate using different NTLM credentials in one session using java.net.URLConnection

When I access the 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 () do not work. So, I need to restart the application in order to use different credentials.

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

Looking at the packages using Wireshark, I also noticed that before the first successful authentication, authentication is first performed with the current Windows credentials. But after successful authentication, only the saved credentials are used.

Is there a way to reset or change java.net credentials. Does the authenticator use NTLM after successful authentication?

+4
source share
2 answers

Nope

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

indicates that this is an outstanding error. The author there offers some unpleasant reflection magic to overcome this. This is normal if it is internally and documented as fragile and potentially breaking. Certainly not big

+3
source

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

+1
source

Source: https://habr.com/ru/post/1300440/


All Articles