创建LoginContext(JAAS)时未配置LoginModules错误

问题描述 投票:2回答:2

创建了LoginContext对象并传递了名称,并使用该条目创建了.conf文件。我在代码中设置了系统属性“ java.security.auth.login.config”,并带有指向conf文件的相对/绝对路径。执行代码时,出现以下错误。

javax.security.auth.login.LoginException:未为示例配置LoginModule。

任何线索为什么配置没有被提取?我想念什么吗?

感谢您的任何帮助。

以上代码

System.setProperty("java.security.auth.login.config","sampleConfig.conf");
loginContext = new LoginContext("Sample", new CustomCallbackHandler());
loginContext.login();

sampleConfig.conf

Sample {
   com.sun.security.auth.module.Krb5LoginModule required;
};

该文件似乎没有被拾取。即使更改了文件名/文件路径/或在conf文件中进行了任何语法更改,我仍然只看到先前的错误。

请注意,这是在OSGI捆绑软件中完成的。

有帮助吗?

java osgi kerberos jaas
2个回答
0
投票
将此URL插入为System.setProperty("java.security.auth.login.config",<URL>);中的值。

如果您的配置文件是OSGi-Framework的一部分,请使用Framework-Bundle(id:0),否则请使用包含配置文件的捆绑软件。

编辑

也许使用Configuration对象而不是配置文件。

请参阅我对问题的回答:In jaas can we use an object of javax.security.auth.login.Configuration class as an alternative to LoginModule configuration using .config files

public LoginContext(String name, Subject subject, CallbackHandler callbackHandler, Configuration config) throws LoginException


0
投票
© www.soinside.com 2019 - 2024. All rights reserved.