我目前在Angular JS应用程序中使用LDAP JS进行身份验证,一切正常。
我现在正在构建一个新视图,我的要求是:
uid
方法中为search()
传递rejex或模式匹配项。我的示例代码在这里:
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
。预先输入将显示以an
开头的所有用户ID,例如ana
,anamon
,analisa
等。
答案 0 :(得分:-1)
我已写完最终解决方案并关闭the issue on the project's repository
对于模式匹配,我们需要使用'过滤器'我们传递给搜索方法的选项对象中的字段。所以我最终做了类似下面的事情:
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
});
});
}
}