Kerberos:来自密钥表文件javax.security.auth.login.LoginException的<user>登录失败:无法从用户

时间:2017-05-10 21:48:43

标签: java eclipse maven hadoop kerberos

我有一个java程序,它使用kerberos keytab文件安全地登录我的hadoop服务器。我使用下面的代码来配置所有内容,它在Eclipse IDE中完美运行,但是当我通过Maven创建一个可执行jar,并在命令行上运行时,它不起作用。我看到它能够读取keytab文件,但无法检索指定用户id的密码,从而导致错误。有什么建议吗?

Configuration conf = new Configuration();
conf.set("hadoop.security.authentication", "kerberos");
UserGroupInformation.setConfiguration(conf);
URL file = this.getClass().getClassLoader().getResource("file.keytab");
UserGroupInformation.loginUserFromKeytab("xyzUser", file.getPath());

我的keytab文件保存在根文件夹中,我已将其作为资源标记添加到我的pom.xml中。下面是我正在测试我的jar文件的命令:

java -jar myjar-0.0.1-SNAPSHOT-jar-with-dependencies.jar

1 个答案:

答案 0 :(得分:0)

确保keytab文件位于当前目录中,而不是类路径中。