modifyDN touchups
This commit is contained in:
parent
17d2d4e5cb
commit
c8ea58fc60
42
README.md
42
README.md
|
@ -1,4 +1,44 @@
|
||||||
Docs coming soon.
|
ldapjs makes the LDAP protocol a first class citizen in node.js.
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
For full docs, head on over to <http://ldapjs.org>.
|
||||||
|
|
||||||
|
var ldap = require('ldapjs');
|
||||||
|
|
||||||
|
var server = ldap.createServer();
|
||||||
|
|
||||||
|
server.bind('cn=root', function(req, res, next) {
|
||||||
|
if (req.credentials !== 'secret')
|
||||||
|
return next(new ldap.InvalidCredentialsError());
|
||||||
|
|
||||||
|
res.end();
|
||||||
|
});
|
||||||
|
|
||||||
|
server.search('dc=example', function(req, res, next) {
|
||||||
|
var obj = {
|
||||||
|
dn: req.dn.toString(),
|
||||||
|
attributes: {
|
||||||
|
objectclass: 'helloworld',
|
||||||
|
cn: 'hello',
|
||||||
|
sn: 'world'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if (req.filter.matches(obj))
|
||||||
|
res.send(obj);
|
||||||
|
|
||||||
|
res.end();
|
||||||
|
});
|
||||||
|
|
||||||
|
server.listen(1389, function() {
|
||||||
|
console.log('ldapjs listening at ' + server.url);
|
||||||
|
});
|
||||||
|
|
||||||
|
To run that, assuming you've got the [OpenLDAP](http://www.openldap.org/) client on
|
||||||
|
your system:
|
||||||
|
|
||||||
|
$ ldapsearch -H ldap://localhost:1389 -x -D cn=root -w secret -b dc=example objectclass=*
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
|
|
|
@ -52,7 +52,7 @@ Then there's a few things to note:
|
||||||
name_, or _dn_ for short. A dn is comprised of attributes that lead to that
|
name_, or _dn_ for short. A dn is comprised of attributes that lead to that
|
||||||
node in the tree, as shown above (the syntax is foo=bar, ...).
|
node in the tree, as shown above (the syntax is foo=bar, ...).
|
||||||
* The root of the tree is at the right of the _dn_, which is inverted from a
|
* The root of the tree is at the right of the _dn_, which is inverted from a
|
||||||
filesystem hierarchy, if that wasn't already obvious.
|
filesystem hierarchy.
|
||||||
* Every entry in the tree is an _instance of_ an _objectclass_.
|
* Every entry in the tree is an _instance of_ an _objectclass_.
|
||||||
* An _objectclass_ is a schema concept; think of it like a table in a
|
* An _objectclass_ is a schema concept; think of it like a table in a
|
||||||
traditional ORM.
|
traditional ORM.
|
||||||
|
@ -501,16 +501,16 @@ Here's a few new things:
|
||||||
extend this little project with groups? We probably want those under a
|
extend this little project with groups? We probably want those under a
|
||||||
different part of the tree.
|
different part of the tree.
|
||||||
* We did some really minimal schema enforcement by:
|
* We did some really minimal schema enforcement by:
|
||||||
** Checking that the leaf RDN (relative distinguished name) was a _cn_
|
+ Checking that the leaf RDN (relative distinguished name) was a _cn_
|
||||||
attribute.
|
attribute.
|
||||||
** We then did `req.toObject()`. As mentioned before, each of the req/res
|
+ We then did `req.toObject()`. As mentioned before, each of the req/res
|
||||||
objects have special APIs that make sense for that operation. Without getting
|
objects have special APIs that make sense for that operation. Without getting
|
||||||
into the details, the LDAP add operation on the wire doesn't look like a JS
|
into the details, the LDAP add operation on the wire doesn't look like a JS
|
||||||
object, and we want to support both the LDAP nerd that wants to see what
|
object, and we want to support both the LDAP nerd that wants to see what
|
||||||
got sent, and the "easy" case. So use `.toObject()`. Note we also filtered
|
got sent, and the "easy" case. So use `.toObject()`. Note we also filtered
|
||||||
out to the `attributes` portion of the object since that's all we're really
|
out to the `attributes` portion of the object since that's all we're really
|
||||||
looking at.
|
looking at.
|
||||||
** Lastly, we did a super minimal check to see if the entry was of type
|
+ Lastly, we did a super minimal check to see if the entry was of type
|
||||||
`unixUser`. Frankly for this case, it's kind of useless, but it does illustrate
|
`unixUser`. Frankly for this case, it's kind of useless, but it does illustrate
|
||||||
one point: attribute names are case-insensitive, so ldapjs converts them all to
|
one point: attribute names are case-insensitive, so ldapjs converts them all to
|
||||||
lower case (note the client sent _objectClass_ over the wire).
|
lower case (note the client sent _objectClass_ over the wire).
|
||||||
|
|
|
@ -49,9 +49,7 @@ function ModifyDNRequest(options) {
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
this.__defineGetter__('type', function() { return 'ModifyDNRequest'; });
|
this.__defineGetter__('type', function() { return 'ModifyDNRequest'; });
|
||||||
this.__defineGetter__('_dn', function() {
|
this.__defineGetter__('_dn', function() { return self.entry; });
|
||||||
return self.entry ? self.entry.toString() : '';
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
util.inherits(ModifyDNRequest, LDAPMessage);
|
util.inherits(ModifyDNRequest, LDAPMessage);
|
||||||
module.exports = ModifyDNRequest;
|
module.exports = ModifyDNRequest;
|
||||||
|
@ -63,8 +61,8 @@ ModifyDNRequest.prototype._parse = function(ber) {
|
||||||
this.entry = dn.parse(ber.readString());
|
this.entry = dn.parse(ber.readString());
|
||||||
this.newRdn = dn.parse(ber.readString());
|
this.newRdn = dn.parse(ber.readString());
|
||||||
this.deleteOldRdn = ber.readBoolean();
|
this.deleteOldRdn = ber.readBoolean();
|
||||||
if (ber.peek() === Ber.OctetString)
|
if (ber.peek() === 0x80)
|
||||||
this.newSuperior = ber.readString();
|
this.newSuperior = dn.parse(ber.readString(0x80));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
|
@ -36,7 +36,7 @@ test('new with args', function(t) {
|
||||||
deleteOldRdn: true
|
deleteOldRdn: true
|
||||||
});
|
});
|
||||||
t.ok(req);
|
t.ok(req);
|
||||||
t.equal(req.dn, 'cn=foo, o=test');
|
t.equal(req.dn.toString(), 'cn=foo, o=test');
|
||||||
t.equal(req.newRdn.toString(), 'cn=foo2');
|
t.equal(req.newRdn.toString(), 'cn=foo2');
|
||||||
t.equal(req.deleteOldRdn, true);
|
t.equal(req.deleteOldRdn, true);
|
||||||
t.end();
|
t.end();
|
||||||
|
@ -51,7 +51,7 @@ test('parse', function(t) {
|
||||||
|
|
||||||
var req = new ModifyDNRequest();
|
var req = new ModifyDNRequest();
|
||||||
t.ok(req._parse(new BerReader(ber.buffer)));
|
t.ok(req._parse(new BerReader(ber.buffer)));
|
||||||
t.equal(req.dn, 'cn=foo, o=test');
|
t.equal(req.dn.toString(), 'cn=foo, o=test');
|
||||||
t.equal(req.newRdn.toString(), 'cn=foo2');
|
t.equal(req.newRdn.toString(), 'cn=foo2');
|
||||||
t.equal(req.deleteOldRdn, true);
|
t.equal(req.deleteOldRdn, true);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue