我有一个使用适配器身份验证的 MobileFirst Platform 6.3 应用程序。用户必须能够在会话中多次登录和注销,切换凭据(即以“userA”身份登录、注销、以“userB”身份登录、注销等)。只要会话保持活动状态,所有这些都可以正常工作。
如果我将我的应用程序置于后台 20-30 分钟,我将在我的服务器日志中看到我的logout-function
(onLogout) 被调用。我假设会话超时时框架正在调用它。我的 onLogout 调用WL.Server.setActiveUser("RealmName", null)
,所以这应该使会话无效,它似乎确实这样做了。
当用户将应用程序带回前台并尝试调用受保护的过程时,就会出现问题。我从服务器日志中看到我的login-function
(onAuthRequired) 被框架调用。消息参数未定义。headers 参数包含类似
{"Cookie":["WL_PERSISTENT_COOKIE=5a39bf15-b217-40c2-97eb-c6622213e799; JSESSIONID=00003dozYVeiAYXJYzoQf_oG6BI:5702d236-4455-4e22-bf0c-132459018524"],"Host":["192.168.1.64:10080"],"WL-Instance-Id":["4rjpubf76afnvs9l61gtkf197t"],"X-Requested-With":["XMLHttpRequest"],"Content-Length":["198"],"x-wl-clientlog-deviceId":["DE67FB50-5ABD-4418-A39D-69058144454F"],"x-wl-clientlog-model":["iPad5,4"],"User-Agent":["Mozilla/5.0 (iPad; CPU OS 8_2 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Mobile/12D508/Worklight/6.3.0.0 (358300384)"],"x-wl-clientlog-osversion":["8.2"],"x-wl-clientlog-appname":["Greenwell"],"Connection":["keep-alive"],"x-wl-device-id":["B405CAA3-4EE6-4581-9004-5AA8AA950E0A"],"x-wl-clientlog-appversion":["1.2.1"],"x-wl-app-version":["1.2.1"],"Accept-Language":["en-US"],"x-wl-analytics-tracking-id":["5A9D03E9-42FA-41E7-9FFD-69C4EE89EF95"],"Authorization":["{\"wl_deviceNoProvisioningRealm\":{\"ID\":{\"token\":\"q0dhk0eutb0gi53ak2mltrlbkv\",\"app\":{\"id\":\"GreenwellBanking\",\"version\":\"1.2.1\"},\"device\":{\"id\":\"B405CAA3-4EE6-4581-9004-5AA8AA950E0A\",\"os\":\"8.2\",\"model\":\"iPad5,4\",\"environment\":\"ipad\"},\"custom\":{}}}}"],"Accept-Encoding":["gzip, deflate"],"x-wl-app-details":["{\"applicationDetails\":{\"platformVersion\":\"6.3.0.0\",\"nativeVersion\":\"1889110191\",\"skinName\":\"default\",\"skinChecksum\":2615010882,\"skinLoaderChecksum\":\"(null)\"}}"],"Content-Type":["application/x-www-form-urlencoded; charset=UTF-8"],"Accept":["text/javascript, text/html, application/xml, text/xml, */*"],"x-wl-clientlog-env":["ipad"]}.
调用的成功处理程序和失败处理程序都不会WL.Client.invokeProcedure
被调用。日志中似乎有响应显示 authRequired: true。
2015-03-25 10:44:16.937 Greenwell[649:305965] [DEBUG] [NONE] fetching offers
2015-03-25 10:44:16.964 Greenwell[649:305965] [DEBUG] [NONE] Request [/apps/services/api/GreenwellBanking/ipad/query]
2015-03-25 10:44:16.967 Greenwell[649:305968] [DEBUG] [WL_AFHTTPCLIENTWRAPPER_PACKAGE] +[WLAFHTTPClientWrapper requestWithURL:] in WLAFHTTPClientWrapper.m:37 :: Request url is http://192.168.1.64:10080/GreenwellBanking/apps/services/api/GreenwellBanking/ipad/query
2015-03-25 10:44:16.977 Greenwell[649:305968] [DEBUG] [WL_AFHTTPCLIENTWRAPPER_PACKAGE] -[WLAFHTTPClientWrapper start] in WLAFHTTPClientWrapper.m:182 :: Starting the request with URL http://192.168.1.64:10080/GreenwellBanking/apps/services/api/GreenwellBanking/ipad/query
2015-03-25 10:44:17.116 Greenwell[649:286631] [DEBUG] [WL_AFHTTPCLIENTWRAPPER_PACKAGE] -[WLAFHTTPClientWrapper requestFinished:] in WLAFHTTPClientWrapper.m:195 :: Request Success
2015-03-25 10:44:17.119 Greenwell[649:286631] [DEBUG] [WL_AFHTTPCLIENTWRAPPER_PACKAGE] -[WLAFHTTPClientWrapper requestFinished:] in WLAFHTTPClientWrapper.m:196 :: Response Status Code : 200
2015-03-25 10:44:17.122 Greenwell[649:286631] [DEBUG] [WL_AFHTTPCLIENTWRAPPER_PACKAGE] -[WLAFHTTPClientWrapper requestFinished:] in WLAFHTTPClientWrapper.m:197 :: Response Content : /*-secure-
{"errorMessage":null,"isSuccessful":true,"authRequired":true}*/
挑战处理程序
var challengeHandler = WL.Client.createChallengeHandler("CaasAuthRealm");
challengeHandler.isCustomResponse = function(response) {
if (!response || !response.responseJSON || response.responseText === null) {
return false;
}
if (typeof(response.responseJSON.authRequired) !== 'undefined'){
return true;
} else {
return false;
}
}
challengeHandler.handleChallenge = function (response) {
var authRequired = response.responseJSON.authRequired;
console.log("Handling Challenge - authRequired = " + authRequired);
if (authRequired) {
challengeHandler.submitFailure("Bad credentials");
$.mobile.changePage("login.html", {transition: "slide"});
} else {
challengeHandler.submitSuccess();
if (Model.getInstance().username == "wcmaas-anonymous") {
$.mobile.changePage( "landing.html", { transition: "flip", reverse: true } );
} else {
$.mobile.changePage( "home.html", { transition: "flip" } );
}
}
}
问题:
- 如果
onAuthRequired
在应用程序调用时由服务器上的框架调用WL.Client.invokeProcedure
,为什么我没有看到向应用程序发出的质询?如果我这样做了,我可以提示用户再次登录。 - 我是否误解了应该如何处理超时?似乎我正确地使会话无效
onLogout
,但是如何提示用户在没有挑战的情况下重新进行身份验证?