Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronbean committed Jul 22, 2014
0 parents commit cfb9276
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.idea
node_modules
*.iml
101 changes: 101 additions & 0 deletions lib/edir.js
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;
25 changes: 25 additions & 0 deletions package.json
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"
}
}

0 comments on commit cfb9276

Please sign in to comment.