我正在尝试使用带有Worklight的LDAP模块对我的应用程序用户进行身份验证。 这对于此客户端代码非常有用:
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);
}
当我第一次登录时效果很好。但是,如果我注销,并且我尝试第二次登录,则会出现错误:"找不到文件:/ apps / services / j_security_check"。
我尝试了几件事:
我在Worklight入门网站上获取了代码示例。他们有以下代码注销: WL.Client.logout(' LDAPRealm',{onSuccess:WL.Client.reloadApp})。 如果我删除WL.Client.reloadApp部分,则会出现与我相同的问题:" / apps / services / j_security_check"。
我在调用服务器之前将WL.Client.login(" LDAPRealm")放在submitForm中,但是它没有工作。
为什么会出现这个问题? 重装整个应用程序是解决问题的唯一方法吗?因为它不是真正节省时间......
非常感谢你的帮助。
答案 0 :(得分:0)
您应该使用WL.Client.connect而不是WL.Client.login。您正试图在没有受到质疑的情况下登录。