是否可以从jaas.conf中的类路径引用keytab? [英] Is it possible to reference a keytab from the classpath in jaas.conf?

查看:680
本文介绍了是否可以从jaas.conf中的类路径引用keytab?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以从jaas.conf中的类路径引用键表?

Is it possible to reference a keytab from the classpath in jaas.conf?

我尝试了以下操作,但似乎无济于事:

I have tried the below, but nothing seems to work:

Client{
keyTab=classpath: /mykeytab.keytab
}

Client{
keyTab=file: /mykeytab.keytab
}

Client{
keyTab=file: resources/mykeytab.keytab
}


推荐答案

据我所知,除了绝对路径外,无法使用其他任何东西jaas.conf文件中的密钥表。

As far as I know, it is not possible to use anything but an absolute path to a keytab in the jaas.conf file.

Krb5LoginModule.java 中,(例如,从 Krb5LoginModule.java在github.com

if (useKeyTab) {
  ktab = (keyTabName == null)
           ? KeyTab.getInstance()
           : KeyTab.getInstance(new File(keyTabName));

然后 .getInstance()代码将在实例化的 File 对象上使用 .getPath()(请参见 KeyTab.java )。

And the .getInstance() code will use the .getPath() on the instantiated File object (see KeyTab.java).

因此,基本方法中没有什么可以搜索类路径。另外,请参见此处也是有关密钥表配置的问题

Consequently, there is nothing in the basic approach that will search the classpath. Also, see this question here about keytab configuration as well.

话虽如此,但未在OP的配置文件中显示,可以将类从通常的 com.sun.security.authmodule.Krb5LoginModule更改为自定义模块。然后,在此自定义模块中,可以执行诸如在 initialize <中使用的 Map< String,?> 参数中设置条目的操作。 Krb5LoginModule 的/ code>方法。

That said, and not shown in the OP's configuration file, it is possible to change the class from the usual "com.sun.security.authmodule.Krb5LoginModule" to a custom module. In this custom module, one can then do things such as setting entries in the Map<String,?> parameter that is used in the initialize method of the Krb5LoginModule.

我们已经实现了这种方法以允许进行各种设置在我们的客户端应用程序中定义,而不是试图让我们的用户在客户端上编辑jaas.conf文件。因此,我们使用一个自定义模块,该模块使用Composite方法封装了 Krb5LoginModule,但将所有所需的选项都设置到了 Map`中。

We have implemented such an approach to allow the various settings to be defined in our client application rather than trying to have our users edit a jaas.conf file on the client. So, we use a custom module that uses a Composition approach encapsulating a Krb5LoginModule, but sets all of the desired options into theMap`.

它类似于:

Map<String, String> mOpts = new HashMap<>(); // options

mOpts.put("doNotPrompt", Boolean.TRUE.toString());
mOpts.put("useTicketCache", Boolean.FALSE.toString());
mOpts.put("useKeyTab", Boolean.TRUE.toString());
mOpts.put("keyTab", options.getKeytabPath().toString());
mOpts.put("principal", PrincipalUtils.getDefaultPrincipal().getName());

krb5LM.initialize(_subject, options.getCallbackHandler(), mSS, mOpts);

//
// attempt to authenticate the user
//
krb5LM.login();

可以在类路径中搜索所需的文件名,然后将找到的文件传递给地图。在上面的类似示例中,选项对象已将键标签从用户的偏好设置中拉出并进行了验证。但是,不必拥有一个特定的预浏览文件,而是可以实现对类路径的搜索。

It is possible to search the classpath for a desired filename and then pass the found file to the Map. In the quasi-example above, the options object has pulled the keytab from the user's preferences and validated it. But rather than having a specific pre-browsed file, one could implement a search of the classpath.

这篇关于是否可以从jaas.conf中的类路径引用keytab?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆