admin管理员组文章数量:1431426
I am trying to use the search method of Ldap.js in my node.js code. But it doesn't work. Here is my code:
searchFunc : function (){
console.log('inside search');
client.bind('cn=Manager,dc=foo,dc=', kredito231, function(err) {
if (err) {
console.log(err);
client.unbind();
return;
}
var opts = {
filter: (('Email=*@foo'))
} ;
//This search works correct:
//client.search( 'cn=x,ou=users' + ',' + 'dc=foo,dc=', function(err,res){
//This one doesn't work. But everything is done according api
client.search('dc=foo,dc=', opts, function(err, res) {
res.on('searchEntry', function(entry) {
console.log('hit');
console.log('entry: ' + JSON.stringify(entry.object));
});
res.on('searchReference', function(referral) {
console.log('referral: ' + referral.uris.join());
});
res.on('error', function(err) {
console.log('searchFailed') ;
console.error('error: ' + err.message);
});
res.on('end', function(result) {
console.log('4') ;
console.log('status: ' + result.status);
});
});
});
}
When I use the search method by with dn name
, it returns the correct object with its attributes (res.on('searchEntry', function(entry)
part executed, because it can find the record in Ldap). But when I use client.search('dc=foo,dc=', opts, function(err, res)
with opt defined above, it always goes to branch 4: res.on('end', function(result)
and never returns an error status of 0.
API documentation of Ldap.
I am trying to use the search method of Ldap.js in my node.js code. But it doesn't work. Here is my code:
searchFunc : function (){
console.log('inside search');
client.bind('cn=Manager,dc=foo,dc=', kredito231, function(err) {
if (err) {
console.log(err);
client.unbind();
return;
}
var opts = {
filter: (('Email=*@foo.'))
} ;
//This search works correct:
//client.search( 'cn=x,ou=users' + ',' + 'dc=foo,dc=', function(err,res){
//This one doesn't work. But everything is done according api
client.search('dc=foo,dc=', opts, function(err, res) {
res.on('searchEntry', function(entry) {
console.log('hit');
console.log('entry: ' + JSON.stringify(entry.object));
});
res.on('searchReference', function(referral) {
console.log('referral: ' + referral.uris.join());
});
res.on('error', function(err) {
console.log('searchFailed') ;
console.error('error: ' + err.message);
});
res.on('end', function(result) {
console.log('4') ;
console.log('status: ' + result.status);
});
});
});
}
When I use the search method by with dn name
, it returns the correct object with its attributes (res.on('searchEntry', function(entry)
part executed, because it can find the record in Ldap). But when I use client.search('dc=foo,dc=', opts, function(err, res)
with opt defined above, it always goes to branch 4: res.on('end', function(result)
and never returns an error status of 0.
API documentation of Ldap.
Share Improve this question edited May 6, 2019 at 22:16 BSMP 4,8078 gold badges35 silver badges45 bronze badges asked Aug 7, 2014 at 10:56 DanialDanial 7031 gold badge11 silver badges26 bronze badges 1- Try to give filter: (&('Email=*@foo.')). – Balwant Kumar Singh Commented Feb 11, 2015 at 9:05
2 Answers
Reset to default 2This does not work for dc=foo,dc=
because that entry in the LDAP directory does not have the attribute Email
and hence your filter does not match. The entry 'cn=x,ou=users,dc=foo,dc='
in LDAP directory probably has this attribute which is why it works.
In the following way we can able to search user data
function searchUser() {
var opts = {
filter: '(objectClass=*)', //simple search
// filter: '(&(uid=2)(sn=John))',// and search
// filter: '(|(uid=2)(sn=John)(cn=Smith))', // or search
scope: 'sub',
attributes: ['sn']
};
client.search('ou=users,ou=system', opts, function (err, res) {
if (err) {
console.log("Error in search " + err)
} else {
res.on('searchEntry', function (entry) {
console.log('entry: ' + JSON.stringify(entry.object));
});
res.on('searchReference', function (referral) {
console.log('referral: ' + referral.uris.join());
});
res.on('error', function (err) {
console.error('error: ' + err.message);
});
res.on('end', function (result) {
console.log('status: ' + result.status);
});
}
});
}
本文标签: javascriptSearch in LdapjsStack Overflow
版权声明:本文标题:javascript - Search in Ldap.js - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745556815a2663237.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论