1
1
const ldap = require ( 'ldapjs' ) ;
2
2
const uuidParse = require ( '../tools/uuid-parse' ) ;
3
3
4
- module . exports = {
5
- client : undefined ,
6
- defaultAttributes : {
4
+ function ldapClient ( ) {
5
+ this . client = undefined ;
6
+ this . defaultAttributes = {
7
7
user : [
8
8
'dn' , 'userPrincipalName' , 'sAMAccountName' , 'objectSID' , 'mail' ,
9
9
'lockoutTime' , 'whenCreated' , 'pwdLastSet' , 'userAccountControl' ,
@@ -13,8 +13,8 @@ module.exports = {
13
13
group : [
14
14
'dn' , 'cn' , 'description'
15
15
]
16
- } ,
17
- baseDn : '' ,
16
+ } ;
17
+ this . baseDn = '' ;
18
18
/**
19
19
* @public
20
20
* Connect to LDAP server
@@ -24,7 +24,7 @@ module.exports = {
24
24
* @param {object } options additional options for ldapjs connection
25
25
* @returns {Promise<*> }
26
26
*/
27
- connect : async function ( url , username , password , options = { } ) {
27
+ this . connect = async function ( url , username , password , options = { } ) {
28
28
let that = this ;
29
29
this . client = ldap . createClient ( {
30
30
url,
@@ -43,12 +43,12 @@ module.exports = {
43
43
return resolve ( conn ) ;
44
44
} ) ;
45
45
} ) ;
46
- } ,
47
- disconnect : function ( ) {
46
+ }
47
+ this . disconnect = function ( ) {
48
48
if ( this . client ) {
49
49
this . client . unbind ( ) ;
50
50
}
51
- } ,
51
+ } ;
52
52
/**
53
53
* @public
54
54
* Perform an update action on a specific LDAP object
@@ -58,7 +58,7 @@ module.exports = {
58
58
* @param {null|string } value Value of the change
59
59
* @returns {Promise<*> }
60
60
*/
61
- update : async function ( dn , operation , attribute , value = null ) {
61
+ this . update = async function ( dn , operation , attribute , value = null ) {
62
62
let that = this ;
63
63
let changeObj = {
64
64
operation,
@@ -76,14 +76,14 @@ module.exports = {
76
76
return resolve ( { success : true } ) ;
77
77
} ) ;
78
78
} ) ;
79
- } ,
79
+ } ;
80
80
/**
81
81
* @public
82
82
* @param {string } dn base dn for the search
83
83
* @param {object } userOpts additional user options for search query
84
84
* @returns {Promise<array(object)> }
85
85
*/
86
- search : async function ( dn , userOpts ) {
86
+ this . search = async function ( dn , userOpts ) {
87
87
let opts = {
88
88
// filter: '&(dn=CN=Jordan Vohwinkel,OU=Test,OU=Users,OU=NTech,OU=BOE Companies,DC=Corp,DC=BOETeams,DC=com)',
89
89
filter : 'cn=Jordan Vohwinkel' ,
@@ -114,18 +114,22 @@ module.exports = {
114
114
res . on ( 'end' , function ( result ) { return resolve ( that . results ) ; } ) ;
115
115
} )
116
116
} ) ;
117
- } ,
117
+ } ;
118
118
/**
119
119
* @private
120
120
* Default search entry parser.
121
121
* @param {object } item Item returned from AD
122
122
* @param {object } raw Raw return object
123
123
* @param {function } callback Callback when parsing is complete
124
124
*/
125
- onSearchEntry : function ( item , raw , callback ) {
125
+ this . onSearchEntry = function ( item , raw , callback ) {
126
126
if ( raw . hasOwnProperty ( 'objectSid' ) ) item . objectSid = uuidParse . unparse ( raw . objectSid ) ;
127
127
if ( raw . hasOwnProperty ( "objectGUID" ) ) entry . objectGUID = uuidParse . unparse ( raw . objectGUID ) ;
128
128
if ( raw . hasOwnProperty ( "mS-DS-ConsistencyGuid" ) ) entry [ 'mS-DS-ConsistencyGuid' ] = uuidParse . unparse ( raw [ 'mS-DS-ConsistencyGuid' ] ) ;
129
129
callback ( item ) ;
130
- }
131
- } ;
130
+ } ;
131
+
132
+ return this ;
133
+ }
134
+
135
+ module . exports = ldapClient ;
0 commit comments