本文介绍了Worklight注销不会清除活动用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Worklight 6.1并使用challange处理程序来确定我的用户是否已登录。

I am using Worklight 6.1 and am using a challange handler to determine if my user is logged or not.

登录后,我附上以下代码我在我的应用程序中的注销按钮:

Once logged in, I have the following code attached to my logout button in my app:

on(logoutBtn, "click", lang.hitch(this, function() {
    WL.Client.logout('AdapterAuthRealm', { onSuccess:lang.hitch(this, function() {
        this.gotoView("login");
    }), onFailure:lang.hitch(this, function() {
        WL.Logger.error("Unable to logout");
    })});
    return false;
}));

单击它会打开登录视图,但当用户再次尝试登录时,会显示以下错误:

Clicking it opens the login view, but when the user tries to login again, the following error is shown:

"Cannot change identity of an already logged in user in realm 'AdapterAuthRealm'.
The application must logout first."`

根据以下SO问题:

在设置新用户之前,我首先要清除活跃用户:

I will first have to clear the active user before setting a new one:

WL.Server.setActiveUser("AdapterAuthRealm", null);

我实际上期望WL.Client.logout自动执行此操作,但我自己在onLogout函数中执行此操作在我的适配器似乎没有任何影响:

I actually expected WL.Client.logout to do this automaticly, but doing so myself in my onLogout function in my adapter does not seem to have any effect:

<realm loginModule="NonValidatingLoginModule" name="AdapterAuthRealm">
  <className>com.worklight.integration.auth.AdapterAuthenticator</className>
  <parameter name="login-function" value="PortalAdapter.onAuthRequired"/>
  <parameter name="logout-function" value="PortalAdapter.onLogout"/>
</realm>

function onLogout() {
    WL.Logger.info("invoke logout request");
    WL.Server.setActiveUser("AdapterAuthRealm", null);

    var input = {
        method : 'get',
        returnedContentType : 'text/plain',
        path : '/logoutUrl'
    };

    WL.Server.invokeHttp(input);
}

将其添加到我的适配器中的登录功能,如下所示:

Adding it to my login function in my adapter as follows:

var userIdentity = { userId: username, displayName: username, attributes: {}};
WL.Server.setActiveUser("AdapterAuthRealm", null);
WL.Server.setActiveUser("AdapterAuthRealm", userIdentity);

导致我的应用程序的登录/退出请求的infenite循环。

Results in an infenite loop of login / logout requests of my app.

我的问题:


  1. 当/我应该清除我的活动时user?

  2. 使用challange处理程序时,是否允许使用WL.Client.logout方法?


推荐答案


  1. 你的领域应该有一个logout函数,该函数应该指向适用于注销的过程。您可以将其添加为领域的参数。

您可以添加 WL.Server.setActiveUser( AdapterAuthRealm,null; 到适配器中的onLogout()过程

you can add the WL.Server.setActiveUser("AdapterAuthRealm",null); to the onLogout() procedure in adapter

<realm loginModule="loginModule" name="AdapterAuthRealm">
            <className>com.worklight.integration.auth.AdapterAuthenticator</className>
            <parameter name="login-function" value="LoginAdapter.onAuthRequired"/>
            <parameter name="logout-function" value="LoginAdapter.onLogout"/>
        </realm>

2是。你可以使用WL.Client.Logout();`当使用质询处理程序

2 Yes. you can use WL.Client.Logout();` when using challenge handler

这篇关于Worklight注销不会清除活动用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-13 22:51