1
votes

I am trying to authenticate my application users with a LDAP module with Worklight. This is working very well with this client code :

var ldapRealmChallengeHandler = WL.Client.createChallengeHandler("LDAPRealm");

function wlCommonInit(){
    WL.Client.login("LDAPRealm");
}

ldapRealmChallengeHandler.isCustomResponse = function(response) {
if (!response || response.responseText === null) {
    return false;
}
var indicatorIdx = response.responseText.search('j_security_check');

if (indicatorIdx >= 0){
    return true;
}  
return false;
};


ldapRealmChallengeHandler.handleChallenge = function(response){
};

ldapRealmChallengeHandler.submitLoginFormCallback = function(response) {
    var isLoginFormResponse = ldapRealmChallengeHandler.isCustomResponse(response);
    if (isLoginFormResponse){
        ldapRealmChallengeHandler.handleChallenge(response);
    } 
    else {
        ldapRealmChallengeHandler.submitSuccess();
        window.location.hash = "classes";
    }
};

submitLoginForm = function(username, password){
        var reqURL = '/j_security_check';
        var options = {};
        options.parameters = {
            j_username : username,
            j_password : password
        };
        options.headers = {};
        ldapRealmChallengeHandler.submitLoginForm(reqURL, options,   ldapRealmChallengeHandler.submitLoginFormCallback);
    }

logout = function(){
    WL.Client.logout('LDAPRealm',{});
    changePage(loginPage);
}

When I log in the first time it works well. However, if I logout, and I try to login a second time, an error appears : "File not found: /apps/services/j_security_check".

I tried several things :

  1. I took the code sample on the Worklight Getting Started website. They have the following code to logout : WL.Client.logout('LDAPRealm',{onSuccess: WL.Client.reloadApp}). If I delete the WL.Client.reloadApp part, the same problem than mine occurs : "/apps/services/j_security_check".

  2. I put the WL.Client.login("LDAPRealm") in the submitForm before calling the server but it's not working.

Why this problem is happening ? Is reload the entire application the only way to solve the problem ? Because it's not really time efficient ...

Thanks a lot for your help.

1
just check whether user session is already validated or not? while logging in second time by using WL.Client.isUserAuthenticated("LDAPRealm") if it is authenticated after logging out also means your logout has some problem. Also you will receive error ` "File not found: /apps/services/j_security_check".` whenever you are submitting form without challengeBluewings
Actually, the value of WL.Client.isUserAuthenticated("LDAPRealm") is true after the logout. However, when I logout, my application received a success event from the server so I don't know what I can do ... All the solutions I have found is to reload the app entirely but I would prefer an other solution ...cmartet
Are you clearing the active user by calling WL.Server.setActiveUser("LDAPRealm", null);Bluewings
Where do I need to call this function ? If I call it in the client side, I have an error : WL.Server is undefinedcmartet
You have to use that in logout function adapter. ASAIK you need to use custom login module to use this. see this SO question for more info.Bluewings

1 Answers

0
votes

You should do a WL.Client.connect instead of WL.Client.login. You are trying to login while you were not challenged yet.