Skip to content

Commit

Permalink
Merge remote-tracking branch 'm4tty/791-fix-alternative'
Browse files Browse the repository at this point in the history
  • Loading branch information
christkv committed Dec 10, 2012
2 parents 4a901c0 + afbd258 commit dfbd15b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 15 deletions.
32 changes: 21 additions & 11 deletions lib/mongodb/connection/repl_set.js
Expand Up @@ -463,17 +463,27 @@ function connectToHost (host, auths, replset, cb) {

var pending = auths.length;

for(var i = 0; i < auths.length; i++) {
var auth = auths[i];
var options = { authdb: auth.authdb };
var username = auth.username;
var password = auth.password;
replset.db.authenticate(username, password, options, function() {
--pending;
if(0 === pending) {
return complete();
}
});
var connections = server.allRawConnections();
var pendingAuthConn = connections.length;
for(var x = 0; x <connections.length; x++) {
var connection = connections[x];
var authDone = false;
for(var i = 0; i < auths.length; i++) {
var auth = auths[i];
var options = { authdb: auth.authdb, connection: connection };
var username = auth.username;
var password = auth.password;
replset.db.authenticate(username, password, options, function() {
--pending;
if(0 === pending) {
authDone = true;
--pendingAuthConn;
if(0 === pendingAuthConn) {
return complete();
}
}
});
}
}
});
}
Expand Down
16 changes: 12 additions & 4 deletions lib/mongodb/db.js
Expand Up @@ -634,14 +634,22 @@ Db.prototype.authenticate = function(username, password, options, callback) {
// the default db to authenticate against is 'this'
// if authententicate is called from a retry context, it may be another one, like admin
var authdb = options.authdb ? options.authdb : self.databaseName;

// Push the new auth if we have no previous record
// Get the amount of connections in the pool to ensure we have authenticated all comments
var numberOfConnections = this.serverConfig.allRawConnections().length;

var numberOfConnections = 0;
var errorObject = null;

if (options['connection' != null]) {
//if a connection was explicitly passed on options, then we have only one...
numberOfConnections = 1;
} else {
// Get the amount of connections in the pool to ensure we have authenticated all comments
numberOfConnections = this.serverConfig.allRawConnections().length;
options['onAll'] = true;
}

// Execute all four
this._executeQueryCommand(DbCommand.createGetNonceCommand(self), {onAll:true}, function(err, result, connection) {
this._executeQueryCommand(DbCommand.createGetNonceCommand(self), options, function(err, result, connection) {
// Execute on all the connections
if(err == null) {
// Nonce used to make authentication request with md5 hash
Expand Down

0 comments on commit dfbd15b

Please sign in to comment.