-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit cfb9276
Showing
3 changed files
with
129 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.idea | ||
node_modules | ||
*.iml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
'use strict'; | ||
|
||
var _ = require('lodash'); | ||
var Ldap = require('lderp').Ldap; | ||
var util = require('util'); | ||
|
||
function EdirLdap(host, options, zombieUsername, zombiePassword) { | ||
options = options || {}; | ||
Ldap.call(this, host, options); | ||
this.name = 'edir'; | ||
// this.defaultAttributes = ['ACL', 'cn', 'dn', 'givenName', 'groupMembership', 'loginDisabled', 'loginTime', 'mail', 'objectClass', 'sn', 'telephoneNumber', 'uid']; | ||
this.usernameAttribute = options.usernameAttribute || 'cn'; | ||
this.zombieUsername = options.zombieUsername || ''; | ||
this.zombiePassword = options.zombiePassword || ''; | ||
} | ||
|
||
util.inherits(EdirLdap, Ldap); | ||
|
||
EdirLdap.prototype.bindAsZombie = function (zombieUsername, zombiePassword) { | ||
return Ldap.prototype.bindAsUser.call(this, buildDn(zombieUsername || this.zombieUsername), zombiePassword || this.zombiePassword); | ||
}; | ||
|
||
var buildDn = function (cn) { | ||
return 'cn=' + cn + ',' + config.baseDn; | ||
}; | ||
|
||
var buildObjectClass = function () { | ||
return [ | ||
'inetOrgPerson', | ||
'organizationalPerson', | ||
'Person', | ||
'ndsLoginProperties', | ||
'Top' | ||
]; | ||
}; | ||
|
||
EdirLdap.prototype.buildUserEntry = function (options) { | ||
var entry = _.clone(options); | ||
entry.objectClass = buildObjectClass(); | ||
entry.uid = entry.cn; | ||
return entry; | ||
}; | ||
|
||
EdirLdap.prototype.createUser = function (options) { | ||
return Ldap.prototype.createUser.call(this, buildDn(options.cn), options); | ||
}; | ||
|
||
EdirLdap.prototype.deleteUser = function (cn) { | ||
return Ldap.prototype.deleteUser.call(this, buildDn(cn)); | ||
}; | ||
|
||
EdirLdap.prototype.findAllEmailAddressless = function (startsWith) { | ||
return Ldap.prototype._search.call(this, '(&(cn=' + startsWith + '*)(!(cn=*@*)))'); | ||
}; | ||
|
||
EdirLdap.prototype.modifyUser = function (cn, options) { | ||
var self = this; | ||
var newCn = options.cn || options.username || null; | ||
var newUserPassword = options.userPassword || options.password || null; | ||
var newSn = options.sn || options.firstname || null; | ||
var newGivenName = options.givenName || options.lastname || null; | ||
var newMail = options.mail || options.email || null; | ||
return findUser(cn) | ||
.then(function (user) { | ||
self.user = user; | ||
if (!!newCn) { | ||
var newDn = buildDn(newCn); | ||
return self._client.modifyDNAsync(user.dn, newDn) | ||
.then(function () { | ||
return newDn; | ||
}) | ||
} | ||
else { | ||
return user.dn; | ||
} | ||
}) | ||
.then(function (dn) { | ||
var changes = []; | ||
if (!!newCn) { | ||
changes.push(self.buildLdapChangeObject('replace', {uid: newCn})); // keeping UID and CN in sync | ||
} | ||
if (!!newUserPassword) { | ||
changes.push(self.buildLdapChangeObject('replace', {userPassword: newUserPassword})); | ||
} | ||
if (!!newSn) { | ||
changes.push(self.buildLdapChangeObject('replace', {sn: newSn})); | ||
} | ||
if (!!newGivenName) { | ||
changes.push(self.buildLdapChangeObject('replace', {givenName: newGivenName})); | ||
} | ||
if (!!newMail) { | ||
changes.push(self.buildLdapChangeObject('replace', {mail: newMail})); | ||
} | ||
return self._client.modifyAsync(dn, changes); | ||
}) | ||
.then(function (r) { | ||
return r; | ||
}) | ||
}; | ||
|
||
module.exports = EdirLdap; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"name": "lderp-edir", | ||
"description": "eDirectory extension for lderp", | ||
"version": "0.0.1", | ||
"keywords": [ | ||
"ldap", | ||
"promise", | ||
"edirectory" | ||
], | ||
"homepage": "https://github.com/beardon/lderp-edir", | ||
"bugs": { | ||
"url": "https://github.com/beardon/lderp-edir/issues", | ||
"email": "[email protected]" | ||
}, | ||
"author": { | ||
"name": "Aaron Bean", | ||
"email": "[email protected]", | ||
"url": "https://github.com/aaronbean" | ||
}, | ||
"main": "./lib/edir", | ||
"dependencies": { | ||
"lderp": "0.0.3", | ||
"lodash": "^2.4.1" | ||
} | ||
} |