Session Worklight:质询处理程序未按预期工作

Session Worklight:质询处理程序未按预期工作,session,authentication,timeout,ibm-mobilefirst,Session,Authentication,Timeout,Ibm Mobilefirst,我使用了基于表单的身份验证模块附带的示例质询处理程序。我按照我的要求修改了它。在我的应用程序中,我有一个登录(主页)页面,在那里我有一个登录页面的链接。现在我想让它在用户点击登录按钮时运行我在这里面临各种问题: var aahadAppRealmChallengeHandler = WL.Client.createChallengeHandler("myAppRealm"); var isLandingPage=false , islogout=false; aahadAppRealmChall

我使用了基于表单的身份验证模块附带的示例质询处理程序。我按照我的要求修改了它。在我的应用程序中,我有一个登录(主页)页面,在那里我有一个登录页面的链接。现在我想让它在用户点击登录按钮时运行我在这里面临各种问题:

var aahadAppRealmChallengeHandler = WL.Client.createChallengeHandler("myAppRealm");
var isLandingPage=false , islogout=false;
aahadAppRealmChallengeHandler.isCustomResponse = function(response) {
    WL.Logger.debug("I am here >> 1");
    if (!response || response.responseText === null) {  return false;    }
    var indicatorIdx = response.responseText.search('j_security_check');
    if (indicatorIdx >= 0){ WL.Logger.debug("return true "); return true; }  
    else { 
        if(isLandingPage && $.trim($('#fldloginUserID').val()) !="" && $.trim($('#fldloginUserPassword').val()) !="" ) {
             WL.Logger.debug("WL.Client.isUserAuthenticated()=" + WL.Client.isUserAuthenticated("myAppRealm"));
             if(WL.Client.isUserAuthenticated("myAppRealm")) {       WL.Logger.debug("return false ");  return false;           }
             else {  WL.Logger.debug("return true "); return true;          }
         } 
        WL.Logger.debug("return false ");  return false;
    }
};
aahadAppRealmChallengeHandler.handleChallenge = function(response) {
     WL.Logger.debug("I am here >> 2");
     var indicatorIdx = response.responseText.search('j_security_check');
     var suc = response.responseText.search('success');
     WL.Logger.debug("I am here >> 3 - indicatorIdx =" + indicatorIdx + " Success =" + suc + "  - isLandingPage=" + isLandingPage +" islogout=" +islogout);
    if (isLandingPage){
            if (suc >= 0 ){
                WL.Logger.debug("I am here >> 4 - isLandingPage=" + isLandingPage +" suc="+suc);
                var reqURL = '/j_security_check';           var options = {};
                options.parameters = {
                    j_username : $.trim($('#fldloginUserID').val().toLowerCase()),
                    j_password : $.trim($('#fldloginUserPassword').val())
                };
                options.headers = {};
                aahadAppRealmChallengeHandler.submitLoginForm(reqURL, options, aahadAppRealmChallengeHandler.submitLoginFormCallback);
            }else {
                WL.Logger.debug("I am here >> 5");
                WL.SimpleDialog.show(DialogMessages_en.SessionExpired_Tile, DialogMessages_en.SessionExpired_Description ,
                    [ { text : 'Close', handler : function () {                 
                        if(busyIndicator.isVisible())   
                            busyIndicator.hide();
                         isLandingPage = false; userLogout();islogout=true;
                        $.mobile.changePage("#landingPage" , { transition: "slide"});   
                    } } ]);
            }
    }
     else {
         WL.Logger.debug("I am here >> 6 - isLandingPage=" + isLandingPage +" re-Login Again");
         if(indicatorIdx < 1) {
                var reqURL = '/j_security_check';       var options = {};
                options.parameters = {
                    j_username : $.trim($('#fldloginUserID').val().toLowerCase()),
                    j_password : $.trim($('#fldloginUserPassword').val())
                };
                options.headers = {};
                aahadAppRealmChallengeHandler.submitLoginForm(reqURL, options, aahadAppRealmChallengeHandler.submitLoginFormCallback); 
         }
     }
};
aahadAppRealmChallengeHandler.submitLoginFormCallback = function(response) {
    var isLoginFormResponse = aahadAppRealmChallengeHandler.isCustomResponse(response);
    if (isLoginFormResponse){  isLandingPage=false; aahadAppRealmChallengeHandler.handleChallenge(response);  } 
    else {isLandingPage=true;  aahadAppRealmChallengeHandler.submitSuccess(); WL.Logger.debug("aahadAppRealmChallengeHandler.submitSuccess()");       }
};
$('#logindone').bind('click', function () {
    WL.Logger.debug(" Button Clicked -Before isLandingPage=" +isLandingPage);  
    isLandingPage=true;  
            var reqURL = '/j_security_check';       var options = {};
            options.parameters = {
                j_username : $.trim($('#fldloginUserID').val().toLowerCase()),
                j_password : $.trim($('#fldloginUserPassword').val())
            };
            options.headers = {};
            aahadAppRealmChallengeHandler.submitLoginForm(reqURL, options, aahadAppRealmChallengeHandler.submitLoginFormCallback);
            loginAuthenticateUser();        
});
  • 在第一次单击登录按钮时,它会向WL进行身份验证 服务器,但无法继续执行登录 函数逻辑
  • 第一次点击后,我必须第二次点击 登录按钮。在第二次登录时,单击它执行登录功能 非常好
  • 当我注销时,它也不是 从服务器上删除会话还是什么?它只执行注销 功能代码(如下所示)。但是在指定的会话之后 超时,提示第二次/第三次并显示“超时消息”。 虽然用户没有再次登录。他已经注销了
  • 目的:我希望应用程序仅在用户单击“登录”按钮时登录,但只需单击一次。当我注销或超时时,它不应该保持会话活动,或者在指定的时间后再次显示“会话超时”消息

    我的挑战处理者:

    var aahadAppRealmChallengeHandler = WL.Client.createChallengeHandler("myAppRealm");
    var isLandingPage=false , islogout=false;
    aahadAppRealmChallengeHandler.isCustomResponse = function(response) {
        WL.Logger.debug("I am here >> 1");
        if (!response || response.responseText === null) {  return false;    }
        var indicatorIdx = response.responseText.search('j_security_check');
        if (indicatorIdx >= 0){ WL.Logger.debug("return true "); return true; }  
        else { 
            if(isLandingPage && $.trim($('#fldloginUserID').val()) !="" && $.trim($('#fldloginUserPassword').val()) !="" ) {
                 WL.Logger.debug("WL.Client.isUserAuthenticated()=" + WL.Client.isUserAuthenticated("myAppRealm"));
                 if(WL.Client.isUserAuthenticated("myAppRealm")) {       WL.Logger.debug("return false ");  return false;           }
                 else {  WL.Logger.debug("return true "); return true;          }
             } 
            WL.Logger.debug("return false ");  return false;
        }
    };
    aahadAppRealmChallengeHandler.handleChallenge = function(response) {
         WL.Logger.debug("I am here >> 2");
         var indicatorIdx = response.responseText.search('j_security_check');
         var suc = response.responseText.search('success');
         WL.Logger.debug("I am here >> 3 - indicatorIdx =" + indicatorIdx + " Success =" + suc + "  - isLandingPage=" + isLandingPage +" islogout=" +islogout);
        if (isLandingPage){
                if (suc >= 0 ){
                    WL.Logger.debug("I am here >> 4 - isLandingPage=" + isLandingPage +" suc="+suc);
                    var reqURL = '/j_security_check';           var options = {};
                    options.parameters = {
                        j_username : $.trim($('#fldloginUserID').val().toLowerCase()),
                        j_password : $.trim($('#fldloginUserPassword').val())
                    };
                    options.headers = {};
                    aahadAppRealmChallengeHandler.submitLoginForm(reqURL, options, aahadAppRealmChallengeHandler.submitLoginFormCallback);
                }else {
                    WL.Logger.debug("I am here >> 5");
                    WL.SimpleDialog.show(DialogMessages_en.SessionExpired_Tile, DialogMessages_en.SessionExpired_Description ,
                        [ { text : 'Close', handler : function () {                 
                            if(busyIndicator.isVisible())   
                                busyIndicator.hide();
                             isLandingPage = false; userLogout();islogout=true;
                            $.mobile.changePage("#landingPage" , { transition: "slide"});   
                        } } ]);
                }
        }
         else {
             WL.Logger.debug("I am here >> 6 - isLandingPage=" + isLandingPage +" re-Login Again");
             if(indicatorIdx < 1) {
                    var reqURL = '/j_security_check';       var options = {};
                    options.parameters = {
                        j_username : $.trim($('#fldloginUserID').val().toLowerCase()),
                        j_password : $.trim($('#fldloginUserPassword').val())
                    };
                    options.headers = {};
                    aahadAppRealmChallengeHandler.submitLoginForm(reqURL, options, aahadAppRealmChallengeHandler.submitLoginFormCallback); 
             }
         }
    };
    aahadAppRealmChallengeHandler.submitLoginFormCallback = function(response) {
        var isLoginFormResponse = aahadAppRealmChallengeHandler.isCustomResponse(response);
        if (isLoginFormResponse){  isLandingPage=false; aahadAppRealmChallengeHandler.handleChallenge(response);  } 
        else {isLandingPage=true;  aahadAppRealmChallengeHandler.submitSuccess(); WL.Logger.debug("aahadAppRealmChallengeHandler.submitSuccess()");       }
    };
    $('#logindone').bind('click', function () {
        WL.Logger.debug(" Button Clicked -Before isLandingPage=" +isLandingPage);  
        isLandingPage=true;  
                var reqURL = '/j_security_check';       var options = {};
                options.parameters = {
                    j_username : $.trim($('#fldloginUserID').val().toLowerCase()),
                    j_password : $.trim($('#fldloginUserPassword').val())
                };
                options.headers = {};
                aahadAppRealmChallengeHandler.submitLoginForm(reqURL, options, aahadAppRealmChallengeHandler.submitLoginFormCallback);
                loginAuthenticateUser();        
    });
    
    注销功能

    function loginAuthenticateUser() {
         WL.Logger.debug("Calling loginAuthenticateUser()....");
         busyIndicator.show();
         if ($.trim( $("#fldloginUserID").val()) !="" && $.trim( $("#fldloginUserPassword").val()) !="") {
                authenticateLDAPUsers( $.trim( $("#fldloginUserID").val().toLowerCase() ) , $.trim( $("#fldloginUserPassword").val() ));
         }else {
                if(busyIndicator.isVisible())   
                    busyIndicator.hide();
           simpleDialogDemo(DialogMessages_en.LoginFailed_MsgTitle , DialogMessages_en.LoginFailed_MsgDescription);
         }
    }
    
    function userLogout() {
          WL.Logger.debug("Logout....");
          WL.TabBar.setVisible(false);
          WL.Client.logout('myAppRealm', {onSuccess: function(){}  });  
          $.mobile.changePage("#landingPage" , { transition: "slide"});
          var options = {onSuccess: function() {WL.Logger.debug("collection closed");}, onFailure: function() { WL.Logger.debug("collection closing failed"); } };
          WL.JSONStore.closeAll(options);
    }
    
    authenticationConfig.xml(领域)

    请提供任何建议。


    谢谢

    如果是基于表单的身份验证,您需要在实际提交凭据之前触发身份验证。因此,您需要在应用程序中调用WL.Client.login(“域名”)


    如果身份验证需要在应用程序启动时立即执行,请在wlEnvInit或wlCommonInit函数中调用WL.Client.login(..)。如果后期需要,请在需要时致电。

    您能否提供有关您使用的服务器的任何反馈?网络跟踪有助于了解封面下的情况(如Wireshark和TCPMon)。@Mike,至少感谢您的回复:)。我使用的是IBM WAS v8、WL Server 5.0.5、Oracle和Windows操作系统。对于跟踪日志,我应该共享设备日志吗?我可以打印挑战处理程序的isCustomResponse和handleChallenge函数中的所有“响应”。或者你需要的是日志?
    serverSessionTimeout=5