大佬教程收集整理的这篇文章主要介绍了Windows上的Java的“单一登录”(使用来自“凭据管理器”的凭据)是否被禁用?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
Authenticator.setDefault()
的实例将被完全忽视“.
这与我观察到的一致:在Windows系统上设置主机X的http或httpS连接总是从“Windows Vault”的“Windows凭据”传递主机X的凭据,如我的Windows 7“凭据管理器”控制面板页面.
但是,在我的用例中,我不想使用Windows可能存储的任何凭据,而是总是希望使用我在代码中明确指定的凭据.
有没有办法来覆盖记录的行为,即有没有办法忽略Windows存储的凭据?
有一个Java Bug数据库增强的请求.看看report,看看是否从Sun获得回应(投票支持报告,希望能够很快得到修正).
我最终做的是覆盖sun.net.www.protocol.http.NTLMAuthentication类.通过查看sun.net.www.protocol.http.httpURLAuthentication,我发现你唯一需要修改的是以下结果:
NTLMAuthentication.supportsTransparentAuth()
该方法具有硬编码的返回值,在Windows平台上为true,否则为false.此代码是从安装在Windows 7上的JDK中提取的:
static Boolean supportsTransparentAuth() { return true; }
该方法告诉的是,默认情况下应该使用Windows凭据.如果设置为true,则不会调用您的自定义验证码.看到这个httpURLConnection类的片段:
//Declared as a member variable of httpURLConnection private Boolean tryTransparentNTLMServer = NTLMAuthentication.supportsTransparentAuth(); //Inside of getServerAuthentication method. passwordAuthentication a = null; if (!tryTransparentNTLMServer) { //If set to false,this will call Authenticator.requestpasswordAuthentication(). a = privilegedrequestpasswordAuthentication(url.getHost(),addr,port,url.getProtocol(),"",scheR_512_11845@e,url,requestorType.SERVER); } /* If we are not trying transparent authentication then * we need to have a passwordAuthentication instance. For * transparent authentication (Windows only) the username * and password will be picked up from the current logged * on users credentials. */ if (tryTransparentNTLMServer || (!tryTransparentNTLMServer && a != null)) { //If set to true or if Authenticator did not return any credentials,use Windows credentials. //NTLMAuthentication constructor,if receives a == null will fetch current looged user credentials. ret = new NTLMAuthentication(false,url1,a); }
要获得NTLMAuthentication源代码,我使用了this Java decompiler.打开的rt.jar位于JDK安装文件夹中并复制了所需的类代码.
然后,我简单地更改了supportsTransparentAuth来返回false.但是,如果此方法首先检查系统属性,然后基于该属性返回true或false,那将是非常需要的.
要编译它,我刚把java文件放在sun / net / www / protocol / http文件夹结构下运行:
javac NTLMAuthentication.java
然后运行我的应用程序:
java -Xbootclasspath:"path/to/your/sun/net/www/protocol/http/classes;normal/JDK/boot/directories"
这将告诉JVM在rt.jar之前加载NTLMAuthentication的实现.你必须小心,不要错过任何使用-Xbootclasspath的默认类加载路径,否则会出现ClassnotFound错误.
之后,一切工作都很好.
这种方法有重要的缺点,你应该注意.
>有安全隐患任何人都可以在您的引导文件夹中放置不同的.class文件,并窃取用户凭据或其他重要信息.
> Sun软件包的代码可以更改,恕不另行通知,因此与您的更改不兼容.
>如果您部署此代码,则会违反Sun代码许可.从documentation:
所以这绝对不适合生产环境.
最后,这是一个引导类路径选项和java类加载器的优秀源:PDF
希望这可以帮助.
以上是大佬教程为你收集整理的Windows上的Java的“单一登录”(使用来自“凭据管理器”的凭据)是否被禁用?全部内容,希望文章能够帮你解决Windows上的Java的“单一登录”(使用来自“凭据管理器”的凭据)是否被禁用?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。