如何从 Java 访问 Windows 凭据?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1126684/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I access Windows credentials from Java?
提问by findango
How do I (or can I?) retrieve the cached credentials for the currently logged-in Windows user in Java? I want to reuse these credentials in some other GSS-API calls. Specifically, I'm answering an SPNEGO challenge from IIS.
我如何(或者我可以?)为当前登录的 Windows 用户在 Java 中检索缓存的凭据?我想在其他一些 GSS-API 调用中重用这些凭据。具体来说,我正在回答来自 IIS 的 SPNEGO 挑战。
Thanks.
谢谢。
回答by northpole
assuming you are using JAVA 5:
假设您使用的是 JAVA 5:
com.sun.security.auth.module.NTSystem NTSystem = new com.sun.security.auth.module.NTSystem();
System.out.println(NTSystem.getName());
回答by Pat Gonzalez
If IIS has Integrated Windows Authentication turned on, then you can still access the protected page by using the http://spnego.sourceforge.net/api/net/sourceforge/spnego/SpnegoHttpURLConnection.htmlclass. This open source project's "credential delegation" tutorial also uses the SpnegoHttpURLConnection class.
如果 IIS 已打开集成 Windows 身份验证,则您仍然可以使用http://spnego.sourceforge.net/api/net/sourceforge/spnego/SpnegoHttpURLConnection.html类访问受保护的页面。这个开源项目的“凭证委托”教程也使用了 SpnegoHttpURLConnection 类。