如何从 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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 12:48:40  来源:igfitidea点击:

How do I access Windows credentials from Java?

javawindowssecuritysingle-sign-on

提问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());

here is some info on the subject

这是有关该主题的一些信息

回答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 类。