会话超时后失效
Posted
技术标签:
【中文标题】会话超时后失效【英文标题】:Session becomes invalid after timeout 【发布时间】:2015-03-25 19:22:09 【问题描述】:我有一个使用适配器身份验证的 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*/
challengeHandler
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" );
问题:
-
如果在应用程序调用
WL.Client.invokeProcedure
时服务器上的框架调用了onAuthRequired
,为什么我看不到应用程序发出的质询?如果我这样做了,我可以提示用户再次登录。
我是否误解了应该如何处理超时?似乎我正确地使 onLogout
中的会话无效,但是如何提示用户在没有挑战的情况下重新进行身份验证?
【问题讨论】:
【参考方案1】:您很可能正在使用适配器身份验证并且忘记在您的质询处理程序中使用 submitSuccess()。您能否提供有关您的身份验证配置的更多详细信息并粘贴质询处理程序代码?
【讨论】:
你是对的。我正在使用适配器身份验证,而我的 handleChallenge 不使用 submitSuccess()。我实际上把它注释掉了,因为我发现 submitSuccess 导致我的 submitAuthentication 被调用了两次,导致错误Cannot change identity of an already logged in user
。我编辑了问题以包含我的 challengeHandler 并重新添加了 submitSuccess(),但我只是确认它重新引入了两次提交身份验证的问题。也许是我在删除它时尝试修复另一个问题而导致了一个问题。以上是关于会话超时后失效的主要内容,如果未能解决你的问题,请参考以下文章