简体   繁体   English

无法使用java.net.URLConnection在一个会话中使用不同的NTLM凭据进行身份验证

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

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. 当我使用标准Java API(java.net.URLConnection)访问HTTP服务器时,凭据在第一次成功验证后被“缓存”,并且后续对Authenticator.setDefault()的调用无效。 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 ) 但我需要将NTLM用于我正在访问的服务器,并且Jakarta Commons HttpClient也不是替代方案,因为它不支持NTLMv2(请参阅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. 使用Wireshark查看数据包,我还发现在第一次成功验证之前,首先尝试使用当前Windows凭据进行身份验证。 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? 在成功进行NTLM身份验证后,有没有办法重置或更改java.net.Authenticator正在使用的凭据?

Nope

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

indicates this is an outstanding bug. 表明这是一个突出的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 当然不是很好

HttpClient 4.x + jCIFS 1.3.x可以替代吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM