我正在尝试在OSGi bundle
内部署的IBM WebSphere Liberty server
内执行用户身份验证。
如果我尝试
ctx =新的LoginContext(“system.DEFAULT”,处理程序);
ctx.login();
我得到了例外: javax.security.auth.login.LoginException:无法找到LoginModule类:com.ibm.ws.kernel.boot.security.LoginModuleProxy无法找到...
如果我使用
,也会发生同样的情况ctx =新的LoginContext(“WSLogin”,处理程序);
ctx.login();
如何在OSGi包中正确使用LoginContext?
答案 0 :(得分:0)
实现结果的正确方法非常相似:
final LoginContext ctx = new LoginContext("WSLogin",WSCallbackHandlerFactory.getInstance().getCallbackHandler(username, password));
ctx.login();
在前面的实现中,错误是由于在创建登录上下文之前更改了调用加载器。 错误的代码是:
final LoginContext ctx;
ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
ctx = new LoginContext("RealmUsersRoles", handler);
} finally {
Thread.currentThread().setContextClassLoader(oldClassLoader);
}