无法在使用 java.net.URLConnection 的一个会话中使用不同的 NTLM 凭据进行身份验证
当我使用标准 Java API (java.net.URLConnection) 访问 HTTP 服务器时,凭据在第一次成功身份验证后被“缓存”,并且后续调用 Authenticator.setDefault() 不起作用。因此,我需要重新启动应用程序才能使用不同的凭据。
使用基本身份验证时,我没有观察到这种效果。但我需要对我访问的服务器使用 NTLM,并且 Jakarta Commons HttpClient 也不是替代方案,因为它不支持 NTLMv2(请参阅 http://oaklandsoftware.com/papers/ntlm.html)
使用 Wireshark 查看数据包,我还观察到,在第一次成功身份验证之前,使用当前的身份验证首先尝试 Windows 凭据。但身份验证成功后,仅使用保存的凭据。
在成功进行 NTLM 身份验证后,是否有任何方法可以重置或更改 java.net.Authenticator 正在使用的凭据?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不
https://bugs.java.com/bugdatabase/view_bug?bug_id=6626700
表示这是一个突出的错误。那里的一位作者建议使用一些令人讨厌的反射魔法来克服这个问题。只要这是内部的并且被记录为脆弱且可能会损坏就可以。当然不是很好
Nope
https://bugs.java.com/bugdatabase/view_bug?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
HttpClient 4.x + jCIFS 1.3.x 是替代方案吗?
Would HttpClient 4.x + jCIFS 1.3.x be an alternative?