2013-05-14 34 views
0

我使用了附带基于表单的验证模块的示例质询处理程序。我按照我的要求对其进行了修改。在我的应用程序中,我有一个着陆(主页)页面,其中有链接到登录页面。现在我希望它在用户点击登录按钮时起作用。 我在这里遇到的各种问题:工作灯:质询处理程序未按预期工作

  1. 在上登录按钮第一次点击,它确实与WL 服务器进行身份验证,但随后无法继续还用于执行登录 功能逻辑。
  2. 第一次点击后,我必须第二次点击 登录按钮。在第二次登录时,请点击它完美地执行登录功能 。
  3. 当我注销时,要么是不是 从服务器删除会话或什么?它只执行注销 功能代码(在下面给出)。但是,在指定的会话 超时后,它会提示第二次/第三次并显示“超时消息”。 虽然用户没有再次进入。他已经注销了。

目的:我想应用程序只能登录时对数的按钮,但只需点击一下用户点击。当我注销或超时时,它不应该使会话保持活动状态,或者再次在指定的时间后再显示“会话超时”消息&。

我的质询处理程序:

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(国度)

<realm loginModule="Strongme" name="myAppRealm"> 
      <className>com.worklight.core.auth.ext.FormBasedAuthenticator</className> 
      <parameter name="login-page" value="login.html" /> 
     </realm> 

Worklight.properties

serverSessionTimeout=5 

任何建议请。

感谢

+0

你能提供任何有关你正在使用的服务器的反馈吗?网络跟踪有助于理解封面下面发生的事情(如Wireshark和TCPMon)。 – Mike 2013-05-16 15:26:09

+0

@Mike,感谢您的回复至少:)。我正在使用IBM WAS v8,WL Server 5.0.5,Oracle和Windows操作系统。对于跟踪日志,我应该共享设备日志吗?我可以打印来自挑战处理程序的isCustomResponse&handleChallenge功能的所有“响应”。或任何你需要WAS日志? – AAhad 2013-05-16 15:46:43

回答

2

在FormBasedAuthentication的情况下,你需要的其实之前提交凭据来触发认证。因此,您需要在应用程序中调用WL.Client.login(“realm-name”)。

如果身份验证在应用程序启动时立即需要 - 请在您的wlEnvInit或wlCommonInit函数中调用WL.Client.login(..)。如果需要在后期阶段 - 请在需要时调用它。