无法找到登录模块 class:com.sun.security.auth.module.UnixLoginModule

Unable to find LoginModule class: com.sun.security.auth.module.UnixLoginModule

尝试使用 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.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[=12=]0(LoginContext.java:195)
        at javax.security.auth.login.LoginContext.run(LoginContext.java:682)
        at javax.security.auth.login.LoginContext.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 存在于哪个文件中?

如果有人以前遇到过这个问题,请帮忙!

此问题已解决!

让我分享真正的原因以及它是如何解决的?

在单元测试代码中,我为我的测试用例场景将 os.name 系统 属性 值设置为不同的操作系统,如下所示:

System.setProperty("os.name", "Windows");

我正在使用 Windows/Unix/MAC 等设置以上属性值,但我没有重置为原始值。

在同一个项目中,我从 Hadoop API 执行 FileSystem.get(new Configuration());,其中设置了 Kerberose 身份验证。

因此,当执行操作系统名称被更改为其他名称时,它并未重置为原始名称。

解法:

所以在设置方法中,我将原始的 OS 名称收集到其他变量,并且在所有测试用例完成后重置为原始名称,如下所示:

@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");
}

经过上述设置 OS 恢复为原来的名称,一切开始正常工作。

希望这对以后的其他人有帮助!!!