j_security_check not found worklight

时光怂恿深爱的人放手 提交于 2019-12-11 11:36:40

问题


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:


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



来源:https://stackoverflow.com/questions/23810504/j-security-check-not-found-worklight

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!