Javascript LDAP JS,节点JS查找以字符串模式传递的用户
我目前正在Angular JS应用程序中使用LDAP JS进行身份验证,一切正常 我现在正在构建一个新视图,我的要求是:Javascript LDAP JS,节点JS查找以字符串模式传递的用户,javascript,angularjs,node.js,ldap,ldap-query,Javascript,Angularjs,Node.js,Ldap,Ldap Query,我目前正在Angular JS应用程序中使用LDAP JS进行身份验证,一切正常 我现在正在构建一个新视图,我的要求是: 我有一个文本框,管理员将在其中写入可能是LDAP中存在的用户id的几个字母 我想在typeahead/suggestions上显示LDAP中存在的应用程序匹配ID。我知道typeahead是如何工作的,所以这不是一个问题。问题是如何在search()方法中为uid传递rejex或模式匹配之类的东西 我的示例代码如下: function GetAllLDAPUser(dnF
- 我有一个文本框,管理员将在其中写入可能是LDAP中存在的用户id的几个字母
- 我想在typeahead/suggestions上显示LDAP中存在的应用程序匹配ID。我知道typeahead是如何工作的,所以这不是一个问题。问题是如何在
方法中为search()
传递rejex或模式匹配之类的东西uid
function GetAllLDAPUser(dnFilter, res) {
client.search('uid=**WHAT-PATTERN-CAN-I-PASS-HERE**' + dnFilter, opts, function(err, result) {
result.on('searchEntry', function(entry) {
// I usually read entry.object or entry.raw here , that works
});
result.on('end', function(result) {
.......
});
}
}
}
所以问题是我应该通过什么来代替
WHAT-PATTERN-CAN-I-PASS-HERE
结果:
假设我键入
an
。typeahead将显示所有以an
开头的用户id,如ana
、anamon
、analisa
等。我已经编写了最终解决方案并关闭了
对于模式匹配,我们需要处理传递给搜索方法的option对象中的“filter”字段。所以我最后做了如下的事情:
var dnFilter = 'ou=People,o=Intra,dc=YOURCOMPANY,dc=com'; //depends on your LDAP settings.
var query;
var matchedUsers = [];
query.LDAPName = "dummy"; //some name which resides in LDAP
//You can even have one simple variable rather than having this query object.
opts = {
scope: 'sub',
filter: (shcDisplayName = '+ query.LDAPName + ')
'
};
//Do not use 'shcDisplayName' , this will be any variable stored in your LDAP object. You need get
//the structure of LDAP end point you are working on. For me, I had one variable 'shcDisplayName'
//on which I wanted to play so I am using this variable in my filter.
client.search(dnFilter, opts, function(err, result) {
result.on('searchEntry', function(entry) {
matchedUsers.push({
'Name': entry.object.shcDisplayName,
'Id': entry.object.uid
});
}
result.on('end', function(result) {
if (matchedUsers.length) { //if any match was found.
//send the json result back
res.json(matchedUsers);
//if you want to send json back, do not use res.send() otherwise you will end up getting
//circular reference error.
}
}
result.on('error', function(ex) {
//Handle errors here if any
});
});
}
}