session - Worklight: Challenge-handler not working as expected -


i used sample challenge handler comes form based authentication module. modified per requirements. in app, have 1 landing (home) page , have link login page. want function when user click on login button. i face various problems here:

  1. on first click on login button, authenticate wl server unable proceed further execute login function logic.
  2. after first click, have 2nd time click on login button. @ 2nd login click execute login function perfectly.
  3. when log out,either not removing session server or what? execute log-out function code (given below). again after specified session time out, prompts 2nd/3rd time , shows "time out message". although user not loged in again. log-out.

purpose: want app login when user click on log-in button, 1 click. , when log-out or time out, should not keep session active or shows "session timeout" message after specified time again & again.

my challenge handler:

var aahadapprealmchallengehandler = wl.client.createchallengehandler("myapprealm"); var islandingpage=false , islogout=false; aahadapprealmchallengehandler.iscustomresponse = function(response) {     wl.logger.debug("i 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 here >> 2");      var indicatoridx = response.responsetext.search('j_security_check');      var suc = response.responsetext.search('success');      wl.logger.debug("i here >> 3 - indicatoridx =" + indicatoridx + " success =" + suc + "  - islandingpage=" + islandingpage +" islogout=" +islogout);     if (islandingpage){             if (suc >= 0 ){                 wl.logger.debug("i 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 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 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();         }); 

my login function

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);      } } 

log-out function

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 (realms)

<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 

any suggestion please.

thanks

in case of formbasedauthentication need trigger authentication before submitting credentials. therefore need call wl.client.login("realm-name") in app.

in case authentication requires on app startup - call wl.client.login(..) in wlenvinit or wlcommoninit function. in case requires on later stage - call once need it.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

keyboard - C++ GetAsyncKeyState alternative -

android - java.net.UnknownHostException(Unable to resolve host “URL”: No address associated with hostname) -