aboutsummaryrefslogtreecommitdiff
path: root/node_modules/mongodb-core/lib/auth/plain.js
diff options
context:
space:
mode:
authornanalelfe <nargiza.nosirova@mail.utoronto.ca>2016-07-27 12:46:04 +0000
committernanalelfe <nargiza.nosirova@mail.utoronto.ca>2016-07-27 12:46:04 +0000
commit7bee9b7e0968b650b3dbe2e35bf3a0d7d6e5e00e (patch)
tree4e63af46a6e306bfeac1ef4b8bd83e1b45a37257 /node_modules/mongodb-core/lib/auth/plain.js
parent6520aa92a114d65b17b178a952c8985e84afd231 (diff)
Removed some unused modules with prune
Diffstat (limited to 'node_modules/mongodb-core/lib/auth/plain.js')
-rw-r--r--node_modules/mongodb-core/lib/auth/plain.js173
1 files changed, 0 insertions, 173 deletions
diff --git a/node_modules/mongodb-core/lib/auth/plain.js b/node_modules/mongodb-core/lib/auth/plain.js
deleted file mode 100644
index 70210cb..0000000
--- a/node_modules/mongodb-core/lib/auth/plain.js
+++ /dev/null
@@ -1,173 +0,0 @@
-"use strict";
-
-var f = require('util').format
- , crypto = require('crypto')
- , Binary = require('bson').Binary
- , Query = require('../connection/commands').Query
- , MongoError = require('../error');
-
-var AuthSession = function(db, username, password) {
- this.db = db;
- this.username = username;
- this.password = password;
-}
-
-AuthSession.prototype.equal = function(session) {
- return session.db == this.db
- && session.username == this.username
- && session.password == this.password;
-}
-
-/**
- * Creates a new Plain authentication mechanism
- * @class
- * @return {Plain} A cursor instance
- */
-var Plain = function(bson) {
- this.bson = bson;
- this.authStore = [];
-}
-
-/**
- * Authenticate
- * @method
- * @param {{Server}|{ReplSet}|{Mongos}} server Topology the authentication method is being called on
- * @param {[]Connections} connections Connections to authenticate using this authenticator
- * @param {string} db Name of the database
- * @param {string} username Username
- * @param {string} password Password
- * @param {authResultCallback} callback The callback to return the result from the authentication
- * @return {object}
- */
-Plain.prototype.auth = function(server, connections, db, username, password, callback) {
- var self = this;
- // Total connections
- var count = connections.length;
- if(count == 0) return callback(null, null);
-
- // Valid connections
- var numberOfValidConnections = 0;
- var credentialsValid = false;
- var errorObject = null;
-
- // For each connection we need to authenticate
- while(connections.length > 0) {
- // Execute MongoCR
- var execute = function(connection) {
- // Create payload
- var payload = new Binary(f("\x00%s\x00%s", username, password));
-
- // Let's start the sasl process
- var command = {
- saslStart: 1
- , mechanism: 'PLAIN'
- , payload: payload
- , autoAuthorize: 1
- };
-
- // Let's start the process
- server(connection, new Query(self.bson, "$external.$cmd", command, {
- numberToSkip: 0, numberToReturn: 1
- }).toBin(), function(err, r) {
- // server.command("$external.$cmd"
- // , command
- // , { connection: connection }, function(err, r) {
- // Adjust count
- count = count - 1;
-
- // If we have an error
- if(err) {
- errorObject = err;
- } else if(r.result['$err']) {
- errorObject = r.result;
- } else if(r.result['errmsg']) {
- errorObject = r.result;
- } else {
- credentialsValid = true;
- numberOfValidConnections = numberOfValidConnections + 1;
- }
-
- // We have authenticated all connections
- if(count == 0 && numberOfValidConnections > 0) {
- // Store the auth details
- addAuthSession(self.authStore, new AuthSession(db, username, password));
- // Return correct authentication
- callback(null, true);
- } else if(count == 0) {
- if(errorObject == null) errorObject = new MongoError(f("failed to authenticate using mongocr"));
- callback(errorObject, false);
- }
- });
- }
-
- var _execute = function(_connection) {
- process.nextTick(function() {
- execute(_connection);
- });
- }
-
- _execute(connections.shift());
- }
-}
-
-// Add to store only if it does not exist
-var addAuthSession = function(authStore, session) {
- var found = false;
-
- for(var i = 0; i < authStore.length; i++) {
- if(authStore[i].equal(session)) {
- found = true;
- break;
- }
- }
-
- if(!found) authStore.push(session);
-}
-
-/**
- * Remove authStore credentials
- * @method
- * @param {string} db Name of database we are removing authStore details about
- * @return {object}
- */
-Plain.prototype.logout = function(dbName) {
- this.authStore = this.authStore.filter(function(x) {
- return x.db != dbName;
- });
-}
-
-/**
- * Re authenticate pool
- * @method
- * @param {{Server}|{ReplSet}|{Mongos}} server Topology the authentication method is being called on
- * @param {[]Connections} connections Connections to authenticate using this authenticator
- * @param {authResultCallback} callback The callback to return the result from the authentication
- * @return {object}
- */
-Plain.prototype.reauthenticate = function(server, connections, callback) {
- var authStore = this.authStore.slice(0);
- var err = null;
- var count = authStore.length;
- if(count == 0) return callback(null, null);
- // Iterate over all the auth details stored
- for(var i = 0; i < authStore.length; i++) {
- this.auth(server, connections, authStore[i].db, authStore[i].username, authStore[i].password, function(err, r) {
- if(err) err = err;
- count = count - 1;
- // Done re-authenticating
- if(count == 0) {
- callback(err, null);
- }
- });
- }
-}
-
-/**
- * This is a result from a authentication strategy
- *
- * @callback authResultCallback
- * @param {error} error An error object. Set to null if no error present
- * @param {boolean} result The result of the authentication process
- */
-
-module.exports = Plain;