We are developing an application using Adapter-based authentication.
We have observed that after user1 logs out, and user2 logs in we are getting an error such as: "user already exist, please logout".
To resolve this issue we need to clear the MobileFirst Server session, when the user2 tries to login.
what are the ways to clear the MobileFirst Server session
Application Config.xml
<staticResources>
<resource id="subscribeServlet" securityTest="SubscribeServlet">
<urlPatterns>/subscribeSMS*;/receiveSMS*;/ussd*</urlPatterns>
</resource>
</staticResources>
<securityTests>
<mobileSecurityTest name="PushApplications">
<testUser realm="pushAppRealm"/>
<testDeviceId provisioningType="none"/>
</mobileSecurityTest>
<customSecurityTest name="SubscribeServlet">
<test realm="SubscribeServlet" isInternalUserID="true"/>
</customSecurityTest>
</securityTests>
<realms>
<realm name="SampleAppRealm" loginModule="StrongDummy">
<className>com.worklight.core.auth.ext.FormBasedAuthenticator</className>
</realm>
<realm name="SubscribeServlet" loginModule="rejectAll">
<className>com.worklight.core.auth.ext.HeaderAuthenticator</className>
</realm>
<realm loginModule="PushAppLoginModule" name="pushAppRealm">
<className>com.worklight.integration.auth.AdapterAuthenticator</className>
<parameter name="login-function" value="pushNotificationAdapter.onAuthRequired"/>
<parameter name="logout-function" value="pushNotificationAdapter.onLogout"/>
</realm>
</realms>
<loginModules>
<loginModule name="StrongDummy" expirationInSeconds="3600">
<className>com.worklight.core.auth.ext.NonValidatingLoginModule</className>
</loginModule>
<loginModule name="requireLogin" expirationInSeconds="3600">
<className>com.worklight.core.auth.ext.SingleIdentityLoginModule</className>
</loginModule>
<loginModule name="rejectAll" expirationInSeconds="3600">
<className>com.worklight.core.auth.ext.RejectingLoginModule</className>
</loginModule>
<loginModule name="PushAppLoginModule" >
<className>com.worklight.core.auth.ext.NonValidatingLoginModule</className>
</loginModule>
</loginModules>
Appliation Descriptor.xml
<displayName>pushNotification</displayName>
<description>pushNotification</description>
<author>
<name>application's author</name>
<email>application author's e-mail</email>
<homepage>http://mycompany.com</homepage>
<copyright>Copyright My Company</copyright>
</author>
<mainFile>index.html</mainFile>
<features/>
<targetCategory>UNDEFINED</targetCategory>
<licenseAppType>APPLICATION</licenseAppType>
<thumbnailImage>common/images/thumbnail.png</thumbnailImage>
<userIdentityRealms>pushAppRealm</userIdentityRealms>
<accessTokenExpiration>3600</accessTokenExpiration>
<android version="1.0">
<worklightSettings include="false"/>
<pushSender key="AIzaSyAxazrxBZ1tDQWhuGRsQR3DLiPzfm-O-V8" senderId="1019918790021"/>
<security>
<encryptWebResources enabled="false"/>
<testWebResourcesChecksum enabled="false" ignoreFileExtensions="png, jpg, jpeg, gif, mp4, mp3"/>
<publicSigningKey/>
<packageName/>
</security>
</android>
when user click on login button
function wlCommonInit() {
WL.Client.connect({
onSuccess : onConnectSuccess,
onFailure : onConnectFailure
});
function onConnectSuccess() {
alert(WL.Client.Push.isSubscribed("myPushh"))
}
function onConnectFailure() {
alert("connection failed")
}
}
$(document).on('click', '#btnSubmitLogin', function () {
var civilId=document.getElementById("txtMbrIdLogin").value;
if(WL.Client.isUserAuthenticated("pushAppRealm")==false){
if(WL.Client.getUserName("pushAppRealm")== null){
alert("user not authenticated");
if(WL.Client.Push.isSubscribed("myPushh")){
alert("user subscribed");
WL.Client.Push.unsubscribe("myPushh", {
onSuccess: function() {
alert("unsubscribe success");
callSubmitAuthentication(civilId,"from QLM");
},
onFailure: function() {
alert("unsubscribe fail")
callSubmitAuthentication(civilId,"from QLM");
}
});
}
else{
alert("user not subscribed");
callSubmitAuthentication(civilId,"from QLM");
}
}else{
WL.Client.logout('pushAppRealm', { onSuccess: function() {
alert("logout"); if(WL.Client.Push.isSubscribed("myPushh")){
alert("user subscribed");
WL.Client.Push.unsubscribe("myPushh", {
onSuccess: function() {
callSubmitAuthentication(civilId,"from QLM");
},
onFailure: function() {
alert("unsubscribe fail")
callSubmitAuthentication(civilId,"from QLM");
}
});
}else{
callSubmitAuthentication(civilId,"from QLM");
} }, onFailure:function() {
alert("Unable to logout");
} });
// callSubmitAuthentication(civilId,"from QLM");
}
}
else if(WL.Client.isUserAuthenticated("pushAppRealm")==true){
if(WL.Client.Push.isSubscribed("myPushh")){
WL.Client.Push.unsubscribe("myPushh", {
onSuccess: function() {
WL.Client.logout('pushAppRealm', { onSuccess: function() {
alert("logout"); callSubmitAuthentication();
}, onFailure:function() {
alert("Unable to logout");
}});
callSubmitAuthentication(civilId,"from QLM");
},
onFailure: function() {
callSubmitAuthentication(civilId,"from QLM");
}
});
}else{
callSubmitAuthentication(civilId,"from QLM");
}
}
});
答案 0 :(得分:1)
我无法回答您的具体情况,但我可以说您提供的代码示例没有任何意义,也不应该有效。
例如:
pushAppRealmChallengeHandler.handleChallenge = function(response) {
if (!response || !response.responseJSON || response.responseText === null) {
return false;
}
if (typeof(response.responseJSON.authRequired) !== 'undefined'){
if(response.responseJSON.authRequired == false){
pushAppRealmChallengeHandler.submitSuccess();
}
}else{
return false;
}
}
如果框架调用handleChallenge
,您必需来回答挑战。是否通过将凭据发送回服务器,submitFailure或submitSuccess。返回true
或false
不是一种选择。此方法没有返回值,它应该收集凭据并将其发送到服务器。
你还有一条线在中间:pushAppRealmChallengeHandler.submitAdapterAuthentication(invocationData,{});
。
每次加载文件时,它都会向服务器发送无效凭据。
我会在这里停下来,但到目前为止,这个样本中的任何内容都没有意义或预计会有效。
采取婴儿步骤。请回到基础知识,研究最简单的示例,阅读所有教程。在每个婴儿步骤后测试您的流量。如果您对特定问题有疑问,我们将随时为您提供帮助。
另外,我还建议您尝试使用MobileFirst Platform v8.0