<|start_filename|>node_modules/passport-windowsauth/test/validations.tests.js<|end_filename|>
var expect = require('chai').expect;
var Strategy = require('../lib/strategy');

describe('strategy', function () {
  it('should fail if integrated is false and ldap is null', function(){
    expect(function() {
      new Strategy({
        integrated: false
      }, function(){});
    }).to.throw(/ldap url should be provided in order to validate user and passwords/);
  });
});

<|start_filename|>node_modules/passport-negotiate/lib/passport-negotiate/errors/nousererror.js<|end_filename|>
/**
 * `NoUserError` error.
 *
 * @api public
 */
function NoUserError(principal, message) {
  Error.call(this);
  Error.captureStackTrace(this, arguments.callee);
  this.name = 'NoUserError';
  this.principal = principal;
  this.message = message || null;
};

/**
 * Inherit from `Error`.
 */
NoUserError.prototype.__proto__ = Error.prototype;


/**
 * Expose `NoUserError`.
 */
module.exports = NoUserError;


<|start_filename|>node_modules/passport-negotiate/examples/login/passport/setup.js<|end_filename|>
var NegotiateStrategy   = require('passport-negotiate').Strategy;
var User = require('../models/user');

module.exports = function(passport) {

	passport.serializeUser(function(user, done) {
		done(null, user._id);
	});

	passport.deserializeUser(function(id, done) {
		console.log('deserializing user id:',id);
		User.findById(id, function(err, user) {
			done(err, user);
		});
	});

	passport.use('login', 
		// you can enable constrained delegation here but there is considerable setup
		// that must be done for it to work properly. see README
		new NegotiateStrategy({enableConstrainedDelegation:false}, function(principal, done) {
			User.findOne({'principal' : principal}, 
				function(err, user){
					return done(err, user);
				}
			);
		})
	);
};


<|start_filename|>node_modules/passport-negotiate/examples/login/app.js<|end_filename|>
//
// This application demonstrates a simple use of the passport-negotiate strategy.
// The passport-negotiate module, which uses the kerberos module, requires 
// access to a keytab, and the default location /etc/krb5.keytab probably
// requires root access.  You can set the KRB5_KTNAME environment variable
// to point to an approprate location.  The keytab should contain the key
// for the service principal HTTP/your.server@YOUR.REALM. 
//
// Because Negotatiate authentication is "seamless" there is no login page
// in this application.  A user that cannot be authenticated by the underlying
// kerberos platform will not be able to access any part of the application.
// The application also demonstrates that kerberos authentication can
// succeed but still not have an application-level "user" object.
//
// This application consists of two pages (mainly), /home which shows
// the profile and /manageprofile which manages it. New users which have been
// authenticated but for whom there is not user object are forced to create a 
// profile. Profiles can be deleted.
// 
// Of particular interest are passport/setup.js and routes/setup.js
//
// Please configure a mongo db connection in dbConfig.js 
//

var flash = require('connect-flash');
var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var session = require('express-session');
var mongoose = require('mongoose');
var passport = require('passport');

var dbConfig = require('./dbConfig');
mongoose.connect(dbConfig.url);

var app = express();

app.set('views', __dirname + '/views');
app.set('view engine', 'jade');

app.use(favicon(path.join(__dirname, 'public/favicon.ico')));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded());
app.use(cookieParser());
app.use(session({secret:'wUpHucup5'}));
app.use(flash());
app.use(express.static(path.join(__dirname, 'public')));

app.use(passport.initialize());
app.use(passport.session());

var passportSetup = require('./passport/setup');
passportSetup(passport);

var routingSetup = require('./routes/setup');
routingSetup(app, passport);

app.use(function(req, res, next) {
	var err = new Error('Not found');
	err.status = 404;
	next(err);
});

if ('development' === app.get('env')) {
	app.use(function(err, req, res, next){
		res.status(err.status || 500);
		res.render('error',{
			message : err.message
			, error: err
		});
	});
}

app.set('port', process.env.PORT || 3000);

var server = app.listen(app.get('port'), function() {
	console.log('Express server listening on port '+ server.address().port);
});


<|start_filename|>node_modules/material-icons/gulpfile.js<|end_filename|>
var config = {
  paths: {
    main: 'src/stylus/material-icons.styl',
    styles: 'src/**/*.styl'
  },
  tasks: {
    clean: {
      fn: function(cb, tools, gulp) {
        tools.del(['css'], cb);
      }
    },
    main: {
      deps: ['clean'],
      src: 'main',
      dest: 'css',
      run: [
        'stylus', 'autoprefixer', 'dest',
        'minifyCss', { rename: {suffix: '.min'} }, 'dest',
        { livereload: {start: true} }
      ]
    },
    watch: {
      styles: 'main'
    },
    default: ['watch', 'main'],
    init: {
      fn: function(cb) {
        // first generate icons.styl
        // manually run 'gulp init' when codepoints are changed
        require('./src/map.js').run(cb);
      }
    }
  },
  tools: {
    del: 'del'
  }
}

var engulf = require('engulf');
engulf.importTools();
engulf.run(config);


<|start_filename|>node_modules/passport-negotiate/examples/login/dbConfig.js<|end_filename|>
/**
 * db configuration.
 */
exports.url = 'mongodb://localhost/loginexample';


<|start_filename|>node_modules/passport-negotiate/examples/login/routes/setup.js<|end_filename|>
var User = require('../models/user');

var authenticateLocation = '/authenticate-negotiate';
var homeLocation = '/home';

// If the kerberos authentication succeeds we set req.session.authenticatedPrincipal.
// This can happen even when "authentication" fails because we don't have a user
// object for this principal. 
function hasAuthenticatedPrincipal(req, res, next) {
	console.log('check for authenticated principal: '+req.session.authenticatedPrincipal);
	if (!req.session.authenticatedPrincipal) {
		res.redirect(authenticateLocation);
		return;
	}
	next();
}

function isAuthenticated(req, res, next) {
	console.log('check for user: ', req.user);
	if (!req.user) {
		res.redirect(authenticateLocation);
		return;
	}
	next();
}

module.exports = function(app, passport) {
	app.get('/', isAuthenticated, function (req, res) {
		res.redirect('/home');
	});
	
	// this is the only url where we authenticate. we cannot use failedRedirect
	// because Negotiate needs to generate 401 with a specific header back to
	// the browser.  However, authentication can succeed but we don't have a
	// user object in our application, in which case we redirect to /manageprofile
	app.get(authenticateLocation, passport.authenticate('login', {
		successRedirect: homeLocation,
		noUserRedirect: '/manageprofile'
	}));
	
	// successful authentication but no user object found will redirect here
	// where we MUST have req.session.authenticatedPrincipal populated from
	// a successful authentication. 
	app.get('/manageprofile', hasAuthenticatedPrincipal, function(req,res) {
		var user = req.user;
		if (!user) {
			// don't do new User() because it will get an id then.
			user = {};
			user.principal = req.session.authenticatedPrincipal;
		}
		console.log('using user:', user);
		res.render('manageprofile', {
			message: req.flash('message'),
			user: user
		});
	});
	
	// on post, we will create the User object, so ensure we have the trusted
	// principal obtained via authentication.
	app.post('/manageprofile', hasAuthenticatedPrincipal, function(req,res) {
		var user = req.user;
		var principal = req.session.authenticatedPrincipal;
			
		if (!user) {
			user = new User();
			user.principal = principal;
			console.log("creating a new user for "+principal);
		}  else {
			console.log("updating existing user for "+principal);
		}

		user.email = req.param('email');
		user.firstName = req.param('firstName');
		user.lastName = req.param('lastName');

		user.save(function(err) {
			if (err) {
				console.log('Error in saving user: '+err);
				throw err;
			}

			console.log('User registration/update successful for principal: '+principal);

			// because we may have created a new user object, re-login
			// this will serialize the new user object to the session
			req.login(user, function() {
				res.redirect(homeLocation);
			});
		});
	});

	app.post('/deleteprofile', isAuthenticated,	function(req, res) {
		User.findOneAndRemove({principal: req.session.authenticatedPrincipal}, 
			function(err) {
				if (err) {
					console.log('Error in deleting user: '+err);
					throw err;
				}
				res.redirect('/signout');
			}
		);
	});
	
	app.get(homeLocation, isAuthenticated, function(req, res) {
		console.log('available credential cache: ', req.session.delegatedCredentialsCache);
		res.render('home', {user : req.user, loggedInAt : req.session.loggedInAt});
	});
	
	app.get('/signout',	function(req,res) {
		req.logout();
		req.session.authenticatedPrincipal = null;
		res.render('signedout');
	});
};


<|start_filename|>node_modules/material-icons/src/map.js<|end_filename|>
#!/usr/bin/env node

/* Maps codepoints to CSS class names */

function run(callback) {
  var fileSystem = require('fs');
  var readLine = require('readline');
  var path = require('path');
  var EOL = require('os').EOL;

  // file paths
  var CODEPOINTS = __dirname + '/codepoints';
  var MAP_FILE_NAME = __dirname + '/stylus/icons.styl';

  // Create a file streaming interface
  var readLineHandle = readLine.createInterface({
    input: fileSystem.createReadStream(CODEPOINTS),
    output: process.stdout,
    terminal: false
  });

  // Read each line by line from the file codepoints file
  var map = '';
  readLineHandle.on('line', function(line) {
    // Match the name, space then any unicode after it
    var nameCodepointPair = line.split(' ');

    // make css class prefix
    var codepoint = nameCodepointPair[1];
    var name = nameCodepointPair[0].toLowerCase().trim()
        .replace(/[^0-9a-z]+/gi, '-')

    // make the css
    map += '.{icon-prefix}-' + name + ':before { content: "\\' + codepoint + '"; }' + EOL;
  });

  readLineHandle.on('close', function() {
    // Once reading has finished here we can write the file
    fileSystem.writeFileSync(MAP_FILE_NAME, map);
    callback();
  });
}

exports.run = run;


<|start_filename|>node_modules/passport-negotiate/lib/passport-negotiate/strategy.js<|end_filename|>
var passport = require('passport-strategy')
    , util = require('util')
	, Kerberos = require('kerberos').Kerberos
	, kerberos = new Kerberos()
	, NoUserError = require('./errors/nousererror');

/**
 * `Strategy` constructor.
 * 
 * Authenticate using Negotiate (rfc4559).
 * 
 * Applications must supply a `verify` callback which accepts an authenticated
 * `principal` and then calls the `done` callback supplying a `user`, which
 * should be set to `false` if the authentication should be denied.
 * If an exception occurred, `err` should be set.
 * 
 * In general, it is unwise to use `failureRedirect` with this strategy, because
 * we need to generate a 401 with a `WWW-Authenticate: Negotiate` header when
 * the auth token is not present, and `failureRedirect` prevents this. The
 * "normal" functioning of a browser-server interaction with Negotiate auth
 * is request->response(401)->re-request-with-Authorization->ok. Instead use
 * `noUserRedirect` which will be used in the following condition:
 * 
 * It is possible for an authentication attempt to succeed, but the `verify`
 * cannot find a `user` object. The provided `verify` callback may want to 
 * supply an "empty" user object and then use additional middleware to
 * handle this case in certain applications. Multiple authentication layers
 * may be used as well to handle this. If `noUserRedirect` is provided in the 
 * options, this will be used instead of failing the authentication.
 * 
 * In any case, if authentication succeeds, the principal will be stored in 
 * req.session.authenticatedPrincipal and/or req.authenticatedPrincipal depending
 * on whether session support is enabled.
 * 
 * `options` can be used to further configure the strategy.
 * 
 * Options:
 *   - `passReqToCallback`  when `true`, `req` is the first argument to the verify callback (default: `false`)
 *   - `servicePrincipalName`  in the form `service@host`.  `service` should pretty much always
 *     be `HTTP` but `host` may need to be specified when CNAMES or load balancers are in use. 
 *     This principal will be looked up in the keytab to establish credentials during authentication.
 *     The keytab will be found in it's default location, or by consulting the KRB5_KTNAME environment
 *     variable.
 *   - `verbose`  include some more verbose logging
 *   - `enableConstrainedDelegation`  when set to `true`, S4U2Proxy constrained delegation
 *     will be initiated and credentials will be stored in a temporary credentials cache.
 *     The name of the cache will be stored in req.session.delegatedCredentialsCache 
 *     and/or req.delegatedCredentialsCache (depending on whether session support is enabled)
 *     This cache will have an expiry which should be monitored and the user's session
 *     should be re-authenticated to refresh it. see README
 * 
 * @param {Object} options
 * @param {Function} verify
 */
function Strategy(options, verify) {
	if (typeof options === 'function') {
		verify = options;
		options = {};
	}
	
	if (!verify) {
		throw new Error('negotiate authentication strategy requires a verify function');
	}

	passport.Strategy.call(this);
	
	this.name = 'negotiate';
	this._verify = verify;
	this._passReqToCallback = options.passReqToCallback;
	this._servicePrincipalName = options.servicePrincipalName;
	this._verbose = options.verbose;
	this._enableConstrainedDelegation = options.enableConstrainedDelegation;
}

util.inherits(Strategy, passport.Strategy);

/**
 * Options: in addition to the general passport options allowed in the authenticate middleware method:
 *   - `noUserRedirect`  url to redirect to if authentication succeeds but no user object is provided by `verify` callback
 *     see notes in strategy constructor
 * @param req  An Express request object
 * @param options  An object. See above.
 */
Strategy.prototype.authenticate = function(req, options) {
	var auth = req.get("authorization");
	
	if (!auth) {
		// this will generate a 401 and WWW-Authenticate: Negotiate header
		return this.fail('Negotiate');
	}
	
	var self = this;
	
	if (auth.lastIndexOf('Negotiate ', 0) !== 0) {
		self.error('Malformed authentication token: '+auth);
		return;
	}
	
	auth = auth.substring("Negotiate ".length);
	
	function failIfError(err, step) {
		if (err) {
			console.error("authentication failed at operation '"+step+"' with error: "+err);
			self.error(err);
			return 1;
		}
		return 0;
	}

	var servicePrincipalName = this._servicePrincipalName || "HTTP";

	kerberos.authGSSServerInit(servicePrincipalName, this._enableConstrainedDelegation, function(err, context) {
		if (!failIfError(err, 'init')) { 
			kerberos.authGSSServerStep(context, auth, function(err) {
				if (!failIfError(err, 'step')) {
					// context will be wiped when we "clean" below,
					// so stash the returned values in the session
					var principal = context.username;

					if (req.session)
					    req.session.authenticatedPrincipal = principal;
					req.authenticatedPrincipal = principal;
					if (self._enableConstrainedDelegation) {
					    if (req.session)
					        req.session.delegatedCredentialsCache = context.delegatedCredentialsCache;
					    req.delegatedCredentialsCache = context.delegatedCredentialsCache;
					}
					
					kerberos.authGSSServerClean(context, function(err) {
						function verified(err, user, info) {
							if (err) { return self.error(err); }
							if (!user) { 
								if (options.noUserRedirect) {
									if (self._verbose) {
										console.log("redirecting to: "+options.noUserRedirect);
									}
									return self.redirect(options.noUserRedirect);
								}
								// FIXME: it is not clear that calling fail with an Error object is correct
								return self.fail(new NoUserError(principal));
							}
							self.success(user, info);
						}

						if (!failIfError(err), 'clean') {
							if (self._passReqToCallback) {
								self._verify(req, principal, verified);
							} else {
								self._verify(principal, verified);
							}
						}
					});
				}
			});
		}
	});	
};

module.exports = Strategy;
