How do I access Windows credentials from Java?

痴心易碎 提交于 2019-12-28 04:14:47

问题


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.

Thanks.


回答1:


assuming you are using 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




回答2:


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.html class. This open source project's "credential delegation" tutorial also uses the SpnegoHttpURLConnection class.



来源:https://stackoverflow.com/questions/1126684/how-do-i-access-windows-credentials-from-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!