java 中单点登录缓存_是否可以在Windows上禁用Java的“单点登录”(使用“凭据管理器”中的凭据)?...

小编典典

我一直在寻找与您要求相同的内容。到目前为止,我还没有在JDK上找到实现此目的的方法。

要求对Java

Bug数据库进行增强。查看该报告以了解是否得到了Sun的答复(对报告进行投票,以期尽快解决该问题)。

我最终要做的是覆盖sun.net.www.protocol.http.NTLMAuthentication类。通过查看sun.net.www.protocol.http.HttpURLAuthentication,我发现您唯一需要修改的就是以下结果:

NTLMAuthentication.supportsTransparentAuth()

true在Windows平台和false其他平台上,该方法具有硬编码的返回值。此代码是从Windows 7上安装的JDK中提取的:

static boolean supportsTransparentAuth()

{

return true;

}

该方法说明的是默认情况下是否应使用Windows凭据。如果设置为true, 则不会调用您自定义的Authenticator代码

。参见以下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(), "", scheme, 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源代码,我使用了此Java反编译器。打开位于JDK安装文件夹中的rt.jar,并复制所需的类代码。

然后,我只是更改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

NTLMAuthentication在rt.jar中加载我们的实现。您必须注意不要错过带有的任何默认类加载路径-Xbootclasspath,否则会ClassNotFound出错。

之后,一切正常。

这种方法具有您应注意的重要缺点。

存在安全风险。任何人都可以在启动文件夹中放置其他.class文件,并窃取用户凭据或其他重要信息。

Sun软件包中的代码可能会更改,恕不另行通知,因此与您的更改不兼容。

如果部署此代码,则将违反Sun代码许可证。从文档中:

-Xbootclasspath:bootclasspath指定用分号分隔的目录,JAR存档和ZIP存档列表,以搜索引导类文件。这些代替Java 2

SDK中包含的引导类文件。注意:不应部署使用此选项以覆盖rt.jar中的类的应用程序,因为这样做会违反Java 2 Runtime

Environment二进制代码许可证。

因此,这绝对不适合生产环境。

最后,这是有关引导类路径选项和Java类加载器的绝佳资源:PDF

希望这可以帮助。

2020-09-24

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值