从 IBM Liberty 中的 OSGi bundle访问 LoginContext



我正在尝试从IBM WebSphere Liberty server内部署的OSGi bundle内执行用户身份验证。

如果我尝试

ctx = new LoginContext("system.默认",处理程序(;

ctx.login((;

我得到例外:javax.security.auth.login.LoginException: 无法找到 LoginModule 类: com.ibm.ws.kernel.boot.security.LoginModuleProxy 无法由 ...

如果我使用

ctx = new LoginContext("WSLogin", handler(;

ctx.login((;

如何在 OSGi 捆绑包中正确使用 LoginContext?

实现结果的正确方法非常相似:

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

最新更新