Android 如何在Worklight中创建特定于用户的会话
我正在使用Worklight 6.1开发一个android应用程序。我使用的是单步身份验证过程。现在,使用单用户ID,多个用户可以登录到应用程序,但我不想这样。我想知道如何检查用户当前是否处于活动状态。而且,如果我使用不同的用户登录,我会得到以下错误。 非法状态:无法更改域“SingleStepAuthRealm”中已登录用户的身份应用程序必须先注销 下面是适配器过程。请看一看Android 如何在Worklight中创建特定于用户的会话,android,ibm-mobilefirst,Android,Ibm Mobilefirst,我正在使用Worklight 6.1开发一个android应用程序。我使用的是单步身份验证过程。现在,使用单用户ID,多个用户可以登录到应用程序,但我不想这样。我想知道如何检查用户当前是否处于活动状态。而且,如果我使用不同的用户登录,我会得到以下错误。 非法状态:无法更改域“SingleStepAuthRealm”中已登录用户的身份应用程序必须先注销 下面是适配器过程。请看一看 function getUserLoginDetails(username, password){
function getUserLoginDetails(username, password){
var input = {
method : 'get',
returnedContentType : 'json',
path : 'webrootPath',
'parameters' : {
'userId' : username,
'password' :password
},
};
var response = WL.Server.invokeHttp(input);
var userIdentity = {
userId: username,
displayName: password,
attributes: {
data: response
}
};
WL.Server.setActiveUser("SingleStepAuthRealm", userIdentity);
return response,userIdentity;
}
在代码下面的authentication configuration.xml中
</customSecurityTest>
<customSecurityTest name="SingleStepAuthAdapter-securityTest">
<test isInternalUserID="true" realm="SingleStepAuthRealm"/>
</customSecurityTest>
<realm loginModule="AuthLoginModule" name="SingleStepAuthRealm">
<className>com.worklight.integration.auth.AdapterAuthenticator</className>
<parameter name="login-function" value="SingleStepAuthAdapter.onAuthRequired"/>
<parameter name="logout-function" value="SingleStepAuthAdapter.onLogout"/>
</realm>
com.worklight.integration.auth.AdapterAuthenticator
请建议
问候,
Saroj在再次设置活动用户之前,尝试先“重置”活动用户,因为您无法“替换”它
首先调用
WL.Server.setActiveUser(“myRealm”,null)
,然后调用WL.Server.setActiveUser(“myRealm”,{…})
,您好,谢谢您的回复。我想避免多个用户使用单个Id登录。如何做到这一点。请建议。谢谢。没有内置的东西可以让你检测已经登录的用户。您需要在后端拥有此功能,或者手动实现,例如通过创建数据库并跟踪登录/注销。