Fix examples/inmemory.js

Fixes mcavage/node-ldapjs#138: user can't bind with inmemory example

In addition to fixing the userPassword authentication code, the
authorize function has been changed so any user may search after a
successful bind.
This commit is contained in:
Patrick Mooney 2013-10-23 21:55:43 -05:00
parent 6c00badd95
commit eee489089a
1 changed files with 5 additions and 3 deletions

View File

@ -4,7 +4,9 @@ var ldap = require('../lib/index');
///--- Shared handlers
function authorize(req, res, next) {
if (!req.connection.ldap.bindDN.equals('cn=root'))
/* Any user may search after bind, only cn=root has full power */
var isSearch = (req instanceof ldap.SearchRequest);
if (!req.connection.ldap.bindDN.equals('cn=root') && !isSearch)
return next(new ldap.InsufficientAccessRightsError());
return next();
@ -43,10 +45,10 @@ server.bind(SUFFIX, function(req, res, next) {
if (!db[dn])
return next(new ldap.NoSuchObjectError(dn));
if (!dn[dn].userpassword)
if (!db[dn].userpassword)
return next(new ldap.NoSuchAttributeError('userPassword'));
if (db[dn].userpassword !== req.credentials)
if (db[dn].userpassword.indexOf(req.credentials) === -1)
return next(new ldap.InvalidCredentialsError());
res.end();