Skip to content
This repository was archived by the owner on Sep 6, 2023. It is now read-only.

Commit d37196f

Browse files
committed
Fixed bug which only allowed 1 instance of ldap node at a time.
1 parent 3681b86 commit d37196f

File tree

3 files changed

+42
-29
lines changed

3 files changed

+42
-29
lines changed

package-lock.json

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

transports/ldap/index.js

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
const ldap = require('./ldap');
1+
const ldapClient = require('./ldap');
22
module.exports = function (RED) {
33
'use strict';
44

55
function ldapNode (n) {
66
RED.nodes.createNode(this, n);
77
let node = this;
8+
let that = this;
89

910
this.options = {
1011
host: n.host || 'ldap://localhost',
@@ -15,14 +16,22 @@ module.exports = function (RED) {
1516

1617
this.connect = function(config, node) {
1718
node.status({ fill:"blue",shape:"dot",text: 'connecting...' });
19+
20+
that.ldapClient = new ldapClient();
21+
that.ldapClient.random = Math.random();
22+
1823
let url = `${config.options.host}:${config.options.port}`;
19-
ldap.connect(url, config.credentials.username, config.credentials.password).then( (res, err) => {
24+
that.ldapClient.connect(url, config.credentials.username, config.credentials.password).then( (res, err) => {
25+
if (err) {
26+
node.status({ fill: 'red', shape: 'dot', text: 'Error'});
27+
node.error(err ? err.toString() : 'Unknown error' );
28+
}
2029
node.status({ fill: 'green', shape: 'dot', text: 'connected' });
2130
});
2231
};
2332

2433
this.on('close', function (done) {
25-
ldap.disconnect();
34+
that.ldapClient.disconnect();
2635
node.status({ });
2736
// if (this.tick) { clearTimeout(this.tick); }
2837
// if (this.check) { clearInterval(this.check); }
@@ -52,15 +61,15 @@ module.exports = function (RED) {
5261
try {
5362
node.status({ fill: 'blue', shape: 'dot', text: 'running update' });
5463

55-
let update = await ldap.update(node.dn, node.operation, node.attribute, node.value);
64+
let update = await this.ldapConfig.ldapClient.update(node.dn, node.operation, node.attribute, node.value);
5665
msg.ldapStatus = update;
5766

5867
node.send(msg);
5968

60-
node.status({});
69+
node.status({ fill: 'green', shape: 'dot', text: 'completed' });
6170
} catch (err) {
6271
node.status({ fill: 'red', shape: 'ring', text: 'failed' });
63-
node.error(err ? err : 'Unknown error' );
72+
node.error(err ? err.toString() : 'Unknown error' );
6473
}
6574
});
6675
}
@@ -72,4 +81,4 @@ module.exports = function (RED) {
7281
}
7382
});
7483
RED.nodes.registerType('ldap-update in', ldapUpdateNode);
75-
};
84+
};

transports/ldap/ldap.js

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
const ldap = require('ldapjs');
22
const uuidParse = require('../tools/uuid-parse');
33

4-
module.exports = {
5-
client: undefined,
6-
defaultAttributes: {
4+
function ldapClient () {
5+
this.client = undefined;
6+
this.defaultAttributes = {
77
user: [
88
'dn', 'userPrincipalName', 'sAMAccountName', 'objectSID', 'mail',
99
'lockoutTime', 'whenCreated', 'pwdLastSet', 'userAccountControl',
@@ -13,8 +13,8 @@ module.exports = {
1313
group: [
1414
'dn', 'cn', 'description'
1515
]
16-
},
17-
baseDn: '',
16+
};
17+
this.baseDn = '';
1818
/**
1919
* @public
2020
* Connect to LDAP server
@@ -24,7 +24,7 @@ module.exports = {
2424
* @param {object} options additional options for ldapjs connection
2525
* @returns {Promise<*>}
2626
*/
27-
connect: async function(url, username, password, options = {}) {
27+
this.connect = async function (url, username, password, options = {}) {
2828
let that = this;
2929
this.client = ldap.createClient({
3030
url,
@@ -43,12 +43,12 @@ module.exports = {
4343
return resolve(conn);
4444
});
4545
});
46-
},
47-
disconnect: function () {
46+
}
47+
this.disconnect = function () {
4848
if (this.client) {
4949
this.client.unbind();
5050
}
51-
},
51+
};
5252
/**
5353
* @public
5454
* Perform an update action on a specific LDAP object
@@ -58,7 +58,7 @@ module.exports = {
5858
* @param {null|string} value Value of the change
5959
* @returns {Promise<*>}
6060
*/
61-
update: async function (dn, operation, attribute, value = null) {
61+
this.update = async function (dn, operation, attribute, value = null) {
6262
let that = this;
6363
let changeObj = {
6464
operation,
@@ -76,14 +76,14 @@ module.exports = {
7676
return resolve({ success: true });
7777
});
7878
});
79-
},
79+
};
8080
/**
8181
* @public
8282
* @param {string} dn base dn for the search
8383
* @param {object} userOpts additional user options for search query
8484
* @returns {Promise<array(object)>}
8585
*/
86-
search: async function (dn, userOpts) {
86+
this.search = async function (dn, userOpts) {
8787
let opts = {
8888
// filter: '&(dn=CN=Jordan Vohwinkel,OU=Test,OU=Users,OU=NTech,OU=BOE Companies,DC=Corp,DC=BOETeams,DC=com)',
8989
filter: 'cn=Jordan Vohwinkel',
@@ -114,18 +114,22 @@ module.exports = {
114114
res.on('end', function(result) { return resolve(that.results); });
115115
})
116116
});
117-
},
117+
};
118118
/**
119119
* @private
120120
* Default search entry parser.
121121
* @param {object} item Item returned from AD
122122
* @param {object} raw Raw return object
123123
* @param {function} callback Callback when parsing is complete
124124
*/
125-
onSearchEntry: function(item, raw, callback) {
125+
this.onSearchEntry = function (item, raw, callback) {
126126
if (raw.hasOwnProperty('objectSid')) item.objectSid = uuidParse.unparse(raw.objectSid);
127127
if (raw.hasOwnProperty("objectGUID")) entry.objectGUID = uuidParse.unparse(raw.objectGUID);
128128
if (raw.hasOwnProperty("mS-DS-ConsistencyGuid")) entry['mS-DS-ConsistencyGuid'] = uuidParse.unparse(raw['mS-DS-ConsistencyGuid']);
129129
callback(item);
130-
}
131-
};
130+
};
131+
132+
return this;
133+
}
134+
135+
module.exports = ldapClient;

0 commit comments

Comments
 (0)