Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (!req.headers.authorization) {
res.set( 'WWW-Authenticate', 'Negotiate' );
//
console.log('-----response-----');
console.log(res._headers);
res.status(401).send();
} else {
// this code is only for Linux !
var KerberosNative = require('kerberos').Kerberos;
var kerberos = new KerberosNative();
var ActiveDirectory = require('activedirectory');
var ad = new ActiveDirectory({
"url": "ldap://",
"baseDN": "",
"username": "",
"password": ""});
//cut phrase "Negotiate "
var ticket = req.headers.authorization.substring(10);
//init context
kerberos.authGSSServerInit("HTTP", function(err, context) {
//check ticket
kerberos.authGSSServerStep(context, ticket, function(err) {
//in success context contains username
ad.findUser(context.username, function(err, user) {
//get user groups
AuthSession.prototype.equal = function(session) {
return session.db == this.db
&& session.username == this.username
&& session.password == this.password;
}
// Kerberos class
var Kerberos = null;
var MongoAuthProcess = null;
// Try to grab the Kerberos class
try {
Kerberos = require('kerberos').Kerberos
// Authentication process for Mongo
MongoAuthProcess = require('kerberos').processes.MongoAuthProcess
} catch(err) {}
/**
* Creates a new SSPI authentication mechanism
* @class
* @return {SSPI} A cursor instance
*/
var SSPI = function() {
this.authStore = [];
}
/**
* Authenticate
* @method
* @param {{Server}|{ReplSet}|{Mongos}} server Topology the authentication method is being called on
* @param {Pool} pool Connection pool for this topology
var DbCommand = require('../commands/db_command').DbCommand
, utils = require('../utils')
, format = require('util').format;
// Kerberos class
var Kerberos = null;
var MongoAuthProcess = null;
// Try to grab the Kerberos class
try {
Kerberos = require('kerberos').Kerberos
// Authentication process for Mongo
MongoAuthProcess = require('kerberos').processes.MongoAuthProcess
} catch(err) {}
var authenticate = function(db, username, password, authdb, options, callback) {
var numberOfConnections = 0;
var errorObject = null;
// We don't have the Kerberos library
if(Kerberos == null) return callback(new Error("Kerberos library is not installed"));
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 = db.serverConfig.allRawConnections().length;
options['onAll'] = true;
}
var DbCommand = require('../commands/db_command').DbCommand
, utils = require('../utils')
, format = require('util').format;
// Kerberos class
var Kerberos = null;
var MongoAuthProcess = null;
// Try to grab the Kerberos class
try {
Kerberos = require('kerberos').Kerberos
// Authentication process for Mongo
MongoAuthProcess = require('kerberos').processes.MongoAuthProcess
} catch(err) {}
var authenticate = function(db, username, password, authdb, options, callback) {
var numberOfConnections = 0;
var errorObject = null;
var numberOfValidConnections = 0;
var credentialsValid = false;
options = options || {};
// We don't have the Kerberos library
if(Kerberos == null) return callback(new Error("Kerberos library is not installed"));
if(options['connection'] != null) {
//if a connection was explicitly passed on options, then we have only one...
numberOfConnections = 1;
} else {
var DbCommand = require('../commands/db_command').DbCommand
, utils = require('../utils')
, format = require('util').format;
// Kerberos class
var Kerberos = null;
var MongoAuthProcess = null;
// Try to grab the Kerberos class
try {
Kerberos = require('kerberos').Kerberos
// Authentication process for Mongo
MongoAuthProcess = require('kerberos').processes.MongoAuthProcess
} catch(err) {}
var authenticate = function(db, username, password, authdb, options, callback) {
var numberOfConnections = 0;
var errorObject = null;
var numberOfValidConnections = 0;
var credentialsValid = false;
options = options || {};
// We don't have the Kerberos library
if(Kerberos == null) return callback(new Error("Kerberos library is not installed"));
if(options['connection'] != null) {
//if a connection was explicitly passed on options, then we have only one...
numberOfConnections = 1;
} else {
var DbCommand = require('../commands/db_command').DbCommand
, utils = require('../utils')
, format = require('util').format;
// Kerberos class
var Kerberos = null;
var MongoAuthProcess = null;
// Try to grab the Kerberos class
try {
Kerberos = require('kerberos').Kerberos
// Authentication process for Mongo
MongoAuthProcess = require('kerberos').processes.MongoAuthProcess
} catch(err) {}
var authenticate = function(db, username, password, authdb, options, callback) {
var numberOfConnections = 0;
var errorObject = null;
// We don't have the Kerberos library
if(Kerberos == null) return callback(new Error("Kerberos library is not installed"));
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 = db.serverConfig.allRawConnections().length;
options['onAll'] = true;
}
AuthSession.prototype.equal = function(session) {
return session.db == this.db
&& session.username == this.username
&& session.password == this.password;
}
// Kerberos class
var Kerberos = null;
var MongoAuthProcess = null;
// Try to grab the Kerberos class
try {
Kerberos = require('kerberos').Kerberos
// Authentication process for Mongo
MongoAuthProcess = require('kerberos').processes.MongoAuthProcess
} catch(err) {}
/**
* Creates a new GSSAPI authentication mechanism
* @class
* @return {GSSAPI} A cursor instance
*/
var GSSAPI = function() {
this.authStore = [];
}
/**
* Authenticate
* @method
* @param {{Server}|{ReplSet}|{Mongos}} server Topology the authentication method is being called on
* @param {Pool} pool Connection pool for this topology
var DbCommand = require('../commands/db_command').DbCommand
, utils = require('../utils')
, format = require('util').format;
// Kerberos class
var Kerberos = null;
var MongoAuthProcess = null;
// Try to grab the Kerberos class
try {
Kerberos = require('kerberos').Kerberos
// Authentication process for Mongo
MongoAuthProcess = require('kerberos').processes.MongoAuthProcess
} catch(err) {}
var authenticate = function(db, username, password, authdb, options, callback) {
var numberOfConnections = 0;
var errorObject = null;
var numberOfValidConnections = 0;
var credentialsValid = false;
options = options || {};
// We don't have the Kerberos library
if(Kerberos == null) return callback(new Error("Kerberos library is not installed"));
if(options['connection'] != null) {
//if a connection was explicitly passed on options, then we have only one...
numberOfConnections = 1;
} else {
var DbCommand = require('../commands/db_command').DbCommand
, utils = require('../utils')
, format = require('util').format;
// Kerberos class
var Kerberos = null;
var MongoAuthProcess = null;
// Try to grab the Kerberos class
try {
Kerberos = require('kerberos').Kerberos
// Authentication process for Mongo
MongoAuthProcess = require('kerberos').processes.MongoAuthProcess
} catch(err) {}
var authenticate = function(db, username, password, authdb, options, callback) {
var numberOfConnections = 0;
var errorObject = null;
var numberOfValidConnections = 0;
var credentialsValid = false;
options = options || {};
// We don't have the Kerberos library
if(Kerberos == null) return callback(new Error("Kerberos library is not installed"));
if(options['connection'] != null) {
//if a connection was explicitly passed on options, then we have only one...
numberOfConnections = 1;
} else {
var DbCommand = require('../commands/db_command').DbCommand
, utils = require('../utils')
, format = require('util').format;
// Kerberos class
var Kerberos = null;
var MongoAuthProcess = null;
// Try to grab the Kerberos class
try {
Kerberos = require('kerberos').Kerberos
// Authentication process for Mongo
MongoAuthProcess = require('kerberos').processes.MongoAuthProcess
} catch(err) {}
var authenticate = function(db, username, password, authdb, options, callback) {
var numberOfConnections = 0;
var errorObject = null;
var numberOfValidConnections = 0;
var credentialsValid = false;
// We don't have the Kerberos library
if(Kerberos == null) return callback(new Error("Kerberos library is not installed"));
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