尝试使用Kerberose身份验证访问HDFS位置,但收到以下错误消息:
java.io.IOException: failure to login
at org.apache.hadoop.security.UserGroupInformation.loginUserFromSubject(UserGroupInformation.java:839)
at org.apache.hadoop.security.UserGroupInformation.getLoginUser(UserGroupInformation.java:775)
at org.apache.hadoop.security.UserGroupInformation.getCurrentUser(UserGroupInformation.java:648)
at org.apache.hadoop.fs.FileSystem$Cache$Key.<init>(FileSystem.java:2859)
at org.apache.hadoop.fs.FileSystem$Cache$Key.<init>(FileSystem.java:2851)
at org.apache.hadoop.fs.FileSystem$Cache.get(FileSystem.java:2714)
at org.apache.hadoop.fs.FileSystem.get(FileSystem.java:382)
at org.apache.hadoop.fs.FileSystem.get(FileSystem.java:181)
at com.xyz.module.submodule.common.utils.HDFSPropertyLookup.loadProperties(HDFSPropertyLookup.java:75)
at com.xyz.module.submodule.common.utils.HDFSPropertyLookup.initialize(HDFSPropertyLookup.java:37)
at com.xyz.module.submodule.common.utils.HDFSPropertyLookupTest.initializePropertiesFile(HDFSPropertyLookupTest.java:16)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141)
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)
Caused by: javax.security.auth.login.LoginException: unable to find LoginModule class: com.sun.security.auth.module.UnixLoginModule
at javax.security.auth.login.LoginContext.invoke(LoginContext.java:794)
at javax.security.auth.login.LoginContext.access$000(LoginContext.java:195)
at javax.security.auth.login.LoginContext$4.run(LoginContext.java:682)
at javax.security.auth.login.LoginContext$4.run(LoginContext.java:680)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.login.LoginContext.invokePriv(LoginContext.java:680)
at javax.security.auth.login.LoginContext.login(LoginContext.java:587)
at org.apache.hadoop.security.UserGroupInformation.loginUserFromSubject(UserGroupInformation.java:813)
... 31 more
原因:找不到LoginModule class: com.sun.security.auth.module.UnixLoginModule
。
想知道哪个.jar
文件com.sun.security.auth.module.UnixLoginModule
存在?
如果之前有人可能遇到过这个问题,那么请提供帮助!
答案 0 :(得分:1)
此问题已得到解决!
让我分享一下真正的原因以及它是如何解决的?
在单元测试代码中,我将os.name
系统属性值设置为我的测试用例场景的不同操作系统,如下所示:
System.setProperty("os.name", "Windows");
我在Windows / Unix / MAC等设置上面的属性值,但我错过了重置为原始值。
在同一个项目中我从Hadoop API执行FileSystem.get(new Configuration());
,其中设置了Kerberose身份验证。
因此,虽然执行操作系统名称已更改为其他名称,但未重置为原始名称。
<强>解决方案:强>
因此在设置方法中,我将原始操作系统名称收集到其他变量中,并在所有测试用例完成后重置为原始名称,如下所示:
@BeforeClass
public static void setup() throws IOException {
System.setProperty("os.name.orig", System.getProperty("os.name"));
}
// other test case methods continue...
@AfterClass
public static void clearProperties() throws IOException {
System.setProperty("os.name", System.getProperty("os.name.orig"));
System.clearProperty("os.name.orig");
}
经过上述设置后,操作系统又恢复原状,一切正常。
希望这将有助于其他人!!!