问题
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 :
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".
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