Skip to content

Commit

Permalink
Added option searchScope
Browse files Browse the repository at this point in the history
Allow users to specify the scope if they wish. Default is still 'sub'.
  • Loading branch information
vesse committed Aug 22, 2013
1 parent eba724b commit aba95c5
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/ldapauth.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ var format = require('util').format;
* adminPassword {String} Password for adminDn.
* searchBase {String} The base DN from which to search for users by
* username. E.g. 'ou=users,o=example.com'
* searchScope {String} Optional, default 'sub'. Scope of the search, one
* of 'base', 'one', or 'sub'.
* searchFilter {String} LDAP search filter with which to find a user by
* username, e.g. '(uid={{username}})'. Use the literal '{{username}}'
* to have the given username be interpolated in for the LDAP
Expand Down Expand Up @@ -60,6 +62,8 @@ function LdapAuth(opts) {

this.log = opts.log4js && opts.log4js.getLogger('ldapauth');

this.opts.searchScope || (this.opts.searchScope = 'sub')

if (opts.cache) {
var Cache = require('./cache');
this.userCache = new Cache(100, 300, this.log, 'user');
Expand Down Expand Up @@ -136,7 +140,7 @@ LdapAuth.prototype._findUser = function (username, callback) {
return callback(err);

var searchFilter = self.opts.searchFilter.replace(/{{username}}/g, username);
var opts = {filter: searchFilter, scope: 'sub'};
var opts = {filter: searchFilter, scope: self.opts.searchScope};
if (self.opts.searchAttributes) {
opts.attributes = self.opts.searchAttributes;
}
Expand Down

0 comments on commit aba95c5

Please sign in to comment.