node-ldap2json
Advanced tools
Comparing version 0.0.4 to 0.0.5
var ldap = require('ldapjs') | ||
exports.searchInLdap=function(host,usr,pwd,base,cb){ | ||
exports.searchInLdap=function(options,cb){ | ||
var client=ldap.createClient({ | ||
url:'ldap://'+host+':389' | ||
url:'ldap://'+options.host+':389' | ||
}); | ||
var opts = { | ||
//filter: '(!(objectClass=person))', | ||
scope: 'one' | ||
}; | ||
client.bind(usr,pwd,function(e){ | ||
client.bind(options.adminuser,options.pass,function(e){ | ||
if (e) { | ||
@@ -19,3 +18,3 @@ cb(e.message,null); | ||
var items = []; | ||
client.search(base,opts,function(err,res){ | ||
client.search(options.base,opts,function(err,res){ | ||
if (err) { | ||
@@ -71,12 +70,11 @@ cb(e.message,null); | ||
exports.getAllInLdap=function(host,usr,pwd,base,cb){ | ||
exports.getAllInLdap=function(options,cb){ | ||
var client=ldap.createClient({ | ||
url:'ldap://'+host+':389' | ||
url:'ldap://'+options.host+':389' | ||
}); | ||
var opts = { | ||
//filter: '(!(objectClass=person))', | ||
scope: 'sub' | ||
}; | ||
client.bind(usr,pwd,function(e){ | ||
client.bind(options.adminuser,options.adminpass,function(e){ | ||
if (e) { | ||
@@ -87,3 +85,3 @@ cb(e.message,null); | ||
var items = []; | ||
client.search(base,opts,function(err,res){ | ||
client.search(options.base,opts,function(err,res){ | ||
if (err) { | ||
@@ -124,15 +122,48 @@ cb(e.message,null); | ||
exports.tryBind=function(host,usr,pwd,base,cb){ | ||
exports.getUser=function(options,username,password,cb){ | ||
var client=ldap.createClient({ | ||
url:'ldap://'+host+':389' | ||
url:'ldap://'+options.host+':389' | ||
}); | ||
client.bind(usr,pwd,function(e){ | ||
var opts = { | ||
scope: 'sub', | ||
filter: '(&(objectClass=user)(sAMAccountName='+username+'))' | ||
}; | ||
var items=[]; | ||
client.bind(options.adminuser,options.adminpass,function(e){ | ||
if (e) { | ||
cb(e.message); | ||
cb(e.message,null); | ||
return; | ||
} else { | ||
cb(null); | ||
client.search(options.base,opts,function(err,res) { | ||
if (err){ | ||
console.log("hata"+err); | ||
} | ||
res.on('searchEntry', function(entry) { | ||
items.push(entry.object); | ||
}); | ||
res.on('error', function(err) { | ||
cb(err.message,null); | ||
return; | ||
}); | ||
res.on('end', function(result) { | ||
if (items.length>0) { | ||
var userclient=ldap.createClient({url:'ldap://'+options.host+':389'}); | ||
userclient.bind(options.adminuser.split('\\')[0]+'\\'+username,password,function(e){ | ||
if (e){ | ||
cb(e.message,null); | ||
} else { | ||
cb(null,{dn:items[0].distinguishedName,class:items[0].objectClass,username:username,name:items[0].displayName,groups:items[0].memberOf,sid:items[0].objectSid}); | ||
} | ||
}); | ||
} else { | ||
cb('user not found',null); | ||
} | ||
}); | ||
}); | ||
} | ||
}); | ||
} | ||
} | ||
@@ -49,3 +49,3 @@ var | ||
lib.searchInLdap(options.host,options.username,options.password,options.base,function(e,items){ | ||
lib.searchInLdap(options,function(e,items){ | ||
if (e){ | ||
@@ -76,3 +76,3 @@ cb(e,null); | ||
lib.getAllInLdap(options.host,options.username,options.password,options.base,function(e,items){ | ||
lib.getAllInLdap(options,function(e,items){ | ||
if (e){ | ||
@@ -86,5 +86,5 @@ cb(e,null); | ||
exports.checkUser=function(options,cb){ | ||
exports.checkUser=function(options,username,password,cb){ | ||
lib.tryBind(options.host,options.username,options.password,options.base,function(e,items){ | ||
lib.getUser(options,username,password,function(e,items){ | ||
if (e){ | ||
@@ -96,3 +96,2 @@ cb(e,null); | ||
}); | ||
} | ||
} |
{ | ||
"name": "node-ldap2json", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"description": "LDAP2JSON makes a json return from LDAP Tree", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "node ./test/testme.js" | ||
"test": "vows ./test/*.js" | ||
}, | ||
@@ -32,4 +32,4 @@ "repository": { | ||
,"devDependencies": { | ||
"vows": "0.6.x" | ||
"vows": "0.7.x" | ||
} | ||
} |
var | ||
ldap2json = require('../lib/ldap2json') | ||
,vows = require('vows') | ||
,assert = require('assert') | ||
; | ||
@@ -9,4 +10,4 @@ | ||
host : '10.1.60.5', | ||
username : 'bh\\Administrator', | ||
password : 'Genel1234', | ||
adminuser : 'bh\\Administrator', | ||
adminpass : 'Genel1234', | ||
base : 'dc=bh,dc=pvt' | ||
@@ -16,32 +17,28 @@ } | ||
/// FIND A PUBLIC LDAP Server for testing | ||
ldap2json.checkUser(getTreeOptions,function(e){ | ||
if (e){ | ||
console.log("Error : : : : "+e); | ||
} else { | ||
console.log("Authentication OK"); | ||
} | ||
}); | ||
ldap2json.getJson(getTreeOptions,function(e,tree){ | ||
if (e){ | ||
console.log("Error : : : : "+e); | ||
} else { | ||
console.log("Recieved Object: \n"+JSON.stringify(tree)); | ||
} | ||
}) | ||
ldap2json.getSecurityGroups(getTreeOptions,function(e,groups){ | ||
if (e){ | ||
console.log("Error : : : : "+e); | ||
} else { | ||
groups.forEach(function(grp){ | ||
console.log(grp.name); | ||
}); | ||
} | ||
}); | ||
vows.describe('ldap2json').addBatch({ | ||
'CheckUser': { | ||
topic : function(){ | ||
ldap2json.checkUser(getTreeOptions,'serkan','Genel123',this.callback); | ||
}, | ||
'callback':function(e,usr){ | ||
assert.ifError(e); | ||
} | ||
}, | ||
'Get Domain Tree' : { | ||
topic : function() { | ||
ldap2json.getJson(getTreeOptions,this.callback); | ||
}, | ||
'callback':function(e,tree){ | ||
assert.ifError(e); | ||
} | ||
}, | ||
'Get Security Groups' : { | ||
topic : function() { | ||
ldap2json.getSecurityGroups(getTreeOptions,this.callback); | ||
}, | ||
'callback':function(e,groups){ | ||
assert.ifError(e); | ||
} | ||
} | ||
}).export(module); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8593
271