forked from feedhenry/Node.js-Smoke-Test-App
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fhldap.js
55 lines (47 loc) · 1.51 KB
/
fhldap.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
var util = require('util');
var async = require('async');
// See https://github.com/jeremycx/node-LDAP for instructions on how to use the LDAP module
var LDAP = require('LDAP');
var ldap;
// Initialize our LDAP connection
function init(callback){
if(ldap) return callback(undefined, ldap);
// Change these as appropriate for your ldap server
ldap = new LDAP({ uri: 'ldap://fh-ldap.me'});
ldap.open(function(err){
return callback(err, ldap);
});
};
exports.ldapMember = function(uid, callback) {
init(function(err, ldap){
if(err) return callback(err);
// Change these as appropriate for your domain
var search_options = {
base: 'dc=example,dc=com',
filter: '(uid=' + uid + ')'
};
ldap.search(search_options, function(err, memberDetails) {
if (err) return callback(err);
callback(err, memberDetails[0]);
});
});
};
exports.ldapGroupMembers = function(group, callback) {
init(function(err, ldap){
if(err) return callback(err);
// Change these as appropriate for your domain
var search_options = {
base: 'dc=example,dc=com',
scope: '',
filter: '(cn=' + group + ')',
attrs: ''
};
ldap.search(search_options, function(err, groupDetails) {
if (err) return callback(err);
// Search for each members details
async.map(groupDetails[0].memberUid, exports.ldapMember, function(err, membersDetails){
return callback(err, membersDetails);
});
});
});
};