2017-04-23 20:02:26 +02:00
|
|
|
/* eslint prefer-spread: "off" */
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const Crypto = require('crypto');
|
|
|
|
const jju = require('jju');
|
|
|
|
const Error = require('http-errors');
|
|
|
|
const Logger = require('./logger');
|
2017-04-17 15:12:31 +02:00
|
|
|
const load_plugins = require('./plugin-loader').load_plugins;
|
2014-09-02 01:09:08 +02:00
|
|
|
|
2017-04-23 20:02:26 +02:00
|
|
|
module.exports = Auth;
|
2014-09-02 01:09:08 +02:00
|
|
|
|
|
|
|
function Auth(config) {
|
2017-04-23 20:02:26 +02:00
|
|
|
let self = Object.create(Auth.prototype);
|
|
|
|
self.config = config;
|
|
|
|
self.logger = Logger.logger.child({sub: 'auth'});
|
|
|
|
self.secret = config.secret;
|
2014-11-12 12:14:37 +01:00
|
|
|
|
2017-04-23 20:02:26 +02:00
|
|
|
let plugin_params = {
|
2014-11-12 12:14:37 +01:00
|
|
|
config: config,
|
2017-04-23 20:02:26 +02:00
|
|
|
logger: self.logger,
|
|
|
|
};
|
2014-11-12 12:14:37 +01:00
|
|
|
|
|
|
|
if (config.users_file) {
|
|
|
|
if (!config.auth || !config.auth.htpasswd) {
|
|
|
|
// b/w compat
|
2017-04-23 20:02:26 +02:00
|
|
|
config.auth = config.auth || {};
|
|
|
|
config.auth.htpasswd = {file: config.users_file};
|
2014-11-12 12:14:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-23 20:02:26 +02:00
|
|
|
self.plugins = load_plugins(config, config.auth, plugin_params, function(p) {
|
|
|
|
return p.authenticate || p.allow_access || p.allow_publish;
|
|
|
|
});
|
2014-11-12 12:14:37 +01:00
|
|
|
|
|
|
|
self.plugins.unshift({
|
2016-11-07 18:15:38 +01:00
|
|
|
verdaccio_version: '1.1.0',
|
2015-04-08 22:54:59 +02:00
|
|
|
|
2014-11-12 12:14:37 +01:00
|
|
|
authenticate: function(user, password, cb) {
|
|
|
|
if (config.users != null
|
|
|
|
&& config.users[user] != null
|
|
|
|
&& (Crypto.createHash('sha1').update(password).digest('hex')
|
|
|
|
=== config.users[user].password)
|
|
|
|
) {
|
2017-04-23 20:02:26 +02:00
|
|
|
return cb(null, [user]);
|
2014-11-12 12:14:37 +01:00
|
|
|
}
|
|
|
|
|
2017-04-23 20:02:26 +02:00
|
|
|
return cb();
|
2014-11-12 12:14:37 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
adduser: function(user, password, cb) {
|
|
|
|
if (config.users && config.users[user])
|
2017-04-23 20:02:26 +02:00
|
|
|
return cb( Error[403]('this user already exists') );
|
2014-11-12 12:14:37 +01:00
|
|
|
|
2017-04-23 20:02:26 +02:00
|
|
|
return cb();
|
2014-11-12 12:14:37 +01:00
|
|
|
},
|
2017-04-23 20:02:26 +02:00
|
|
|
});
|
2014-11-12 12:14:37 +01:00
|
|
|
|
2015-04-08 22:54:59 +02:00
|
|
|
function allow_action(action) {
|
2017-04-23 20:02:26 +02:00
|
|
|
return function(user, pkg, cb) {
|
|
|
|
let ok = pkg[action].reduce(function(prev, curr) {
|
|
|
|
if (user.groups.indexOf(curr) !== -1) return true;
|
|
|
|
return prev;
|
|
|
|
}, false);
|
2015-04-08 22:54:59 +02:00
|
|
|
|
2017-04-23 20:02:26 +02:00
|
|
|
if (ok) return cb(null, true);
|
2015-04-08 22:54:59 +02:00
|
|
|
|
|
|
|
if (user.name) {
|
2017-04-23 20:02:26 +02:00
|
|
|
cb( Error[403]('user ' + user.name + ' is not allowed to ' + action + ' package ' + pkg.name) );
|
2015-04-08 22:54:59 +02:00
|
|
|
} else {
|
2017-04-23 20:02:26 +02:00
|
|
|
cb( Error[403]('unregistered users are not allowed to ' + action + ' package ' + pkg.name) );
|
2015-04-08 22:54:59 +02:00
|
|
|
}
|
2017-04-23 20:02:26 +02:00
|
|
|
};
|
2015-04-08 22:54:59 +02:00
|
|
|
}
|
|
|
|
|
2014-11-12 12:14:37 +01:00
|
|
|
self.plugins.push({
|
|
|
|
authenticate: function(user, password, cb) {
|
2017-04-23 20:02:26 +02:00
|
|
|
return cb( Error[403]('bad username/password, access denied') );
|
2014-11-12 12:14:37 +01:00
|
|
|
},
|
|
|
|
|
2015-04-08 22:54:59 +02:00
|
|
|
add_user: function(user, password, cb) {
|
2017-04-23 20:02:26 +02:00
|
|
|
return cb( Error[409]('registration is disabled') );
|
2014-11-12 12:14:37 +01:00
|
|
|
},
|
2015-04-08 22:54:59 +02:00
|
|
|
|
|
|
|
allow_access: allow_action('access'),
|
|
|
|
allow_publish: allow_action('publish'),
|
2017-04-23 20:02:26 +02:00
|
|
|
});
|
2014-11-12 12:14:37 +01:00
|
|
|
|
2017-04-23 20:02:26 +02:00
|
|
|
return self;
|
2014-09-02 01:09:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Auth.prototype.authenticate = function(user, password, cb) {
|
2017-04-23 20:02:26 +02:00
|
|
|
let plugins = this.plugins.slice(0)
|
2014-11-12 12:14:37 +01:00
|
|
|
|
|
|
|
;(function next() {
|
2017-04-23 20:02:26 +02:00
|
|
|
let p = plugins.shift();
|
2015-04-08 22:54:59 +02:00
|
|
|
|
|
|
|
if (typeof(p.authenticate) !== 'function') {
|
2017-04-23 20:02:26 +02:00
|
|
|
return next();
|
2015-04-08 22:54:59 +02:00
|
|
|
}
|
|
|
|
|
2014-11-12 12:14:37 +01:00
|
|
|
p.authenticate(user, password, function(err, groups) {
|
2017-04-23 20:02:26 +02:00
|
|
|
if (err) return cb(err);
|
2014-11-16 13:37:50 +01:00
|
|
|
if (groups != null && groups != false)
|
2017-04-23 20:02:26 +02:00
|
|
|
return cb(err, authenticatedUser(user, groups));
|
|
|
|
next();
|
|
|
|
});
|
|
|
|
})();
|
|
|
|
};
|
2014-09-02 01:09:08 +02:00
|
|
|
|
|
|
|
Auth.prototype.add_user = function(user, password, cb) {
|
2017-04-23 20:02:26 +02:00
|
|
|
let self = this;
|
|
|
|
let plugins = this.plugins.slice(0)
|
2014-11-12 12:14:37 +01:00
|
|
|
|
|
|
|
;(function next() {
|
2017-04-23 20:02:26 +02:00
|
|
|
let p = plugins.shift();
|
|
|
|
let n = 'adduser';
|
2014-11-12 12:14:37 +01:00
|
|
|
if (typeof(p[n]) !== 'function') {
|
2017-04-23 20:02:26 +02:00
|
|
|
n = 'add_user';
|
2014-11-12 12:14:37 +01:00
|
|
|
}
|
|
|
|
if (typeof(p[n]) !== 'function') {
|
2017-04-23 20:02:26 +02:00
|
|
|
next();
|
2014-11-12 12:14:37 +01:00
|
|
|
} else {
|
|
|
|
p[n](user, password, function(err, ok) {
|
2017-04-23 20:02:26 +02:00
|
|
|
if (err) return cb(err);
|
|
|
|
if (ok) return self.authenticate(user, password, cb);
|
|
|
|
next();
|
|
|
|
});
|
2014-11-12 12:14:37 +01:00
|
|
|
}
|
2017-04-23 20:02:26 +02:00
|
|
|
})();
|
|
|
|
};
|
2014-09-02 01:09:08 +02:00
|
|
|
|
2015-04-08 22:54:59 +02:00
|
|
|
Auth.prototype.allow_access = function(package_name, user, callback) {
|
2017-04-23 20:02:26 +02:00
|
|
|
let plugins = this.plugins.slice(0);
|
|
|
|
let pkg = Object.assign({name: package_name},
|
2015-04-08 22:54:59 +02:00
|
|
|
this.config.get_package_spec(package_name))
|
|
|
|
|
|
|
|
;(function next() {
|
2017-04-23 20:02:26 +02:00
|
|
|
let p = plugins.shift();
|
2015-04-08 22:54:59 +02:00
|
|
|
|
|
|
|
if (typeof(p.allow_access) !== 'function') {
|
2017-04-23 20:02:26 +02:00
|
|
|
return next();
|
2015-04-08 22:54:59 +02:00
|
|
|
}
|
|
|
|
|
2017-04-23 20:02:26 +02:00
|
|
|
p.allow_access(user, pkg, function(err, ok) {
|
|
|
|
if (err) return callback(err);
|
|
|
|
if (ok) return callback(null, ok);
|
|
|
|
next(); // cb(null, false) causes next plugin to roll
|
|
|
|
});
|
|
|
|
})();
|
|
|
|
};
|
2015-04-08 22:54:59 +02:00
|
|
|
|
|
|
|
Auth.prototype.allow_publish = function(package_name, user, callback) {
|
2017-04-23 20:02:26 +02:00
|
|
|
let plugins = this.plugins.slice(0);
|
|
|
|
let pkg = Object.assign({name: package_name},
|
2015-04-08 22:54:59 +02:00
|
|
|
this.config.get_package_spec(package_name))
|
|
|
|
|
|
|
|
;(function next() {
|
2017-04-23 20:02:26 +02:00
|
|
|
let p = plugins.shift();
|
2015-04-08 22:54:59 +02:00
|
|
|
|
2015-04-21 18:41:50 +02:00
|
|
|
if (typeof(p.allow_publish) !== 'function') {
|
2017-04-23 20:02:26 +02:00
|
|
|
return next();
|
2015-04-08 22:54:59 +02:00
|
|
|
}
|
|
|
|
|
2017-04-23 20:02:26 +02:00
|
|
|
p.allow_publish(user, pkg, function(err, ok) {
|
|
|
|
if (err) return callback(err);
|
|
|
|
if (ok) return callback(null, ok);
|
|
|
|
next(); // cb(null, false) causes next plugin to roll
|
|
|
|
});
|
|
|
|
})();
|
|
|
|
};
|
2015-04-08 22:54:59 +02:00
|
|
|
|
2014-11-16 13:37:50 +01:00
|
|
|
Auth.prototype.basic_middleware = function() {
|
2017-04-23 20:02:26 +02:00
|
|
|
let self = this;
|
2014-11-12 12:14:37 +01:00
|
|
|
return function(req, res, _next) {
|
2017-04-23 20:02:26 +02:00
|
|
|
req.pause();
|
2014-11-12 12:14:37 +01:00
|
|
|
function next(err) {
|
2017-04-23 20:02:26 +02:00
|
|
|
req.resume();
|
2014-11-12 12:14:37 +01:00
|
|
|
// uncomment this to reject users with bad auth headers
|
2017-04-23 20:02:26 +02:00
|
|
|
// return _next.apply(null, arguments)
|
2014-11-12 12:14:37 +01:00
|
|
|
|
|
|
|
// swallow error, user remains unauthorized
|
|
|
|
// set remoteUserError to indicate that user was attempting authentication
|
2017-04-23 20:02:26 +02:00
|
|
|
if (err) req.remote_user.error = err.message;
|
|
|
|
return _next();
|
2014-11-12 12:14:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (req.remote_user != null && req.remote_user.name !== undefined)
|
2017-04-23 20:02:26 +02:00
|
|
|
return next();
|
|
|
|
req.remote_user = buildAnonymousUser();
|
2014-11-12 12:14:37 +01:00
|
|
|
|
2017-04-23 20:02:26 +02:00
|
|
|
let authorization = req.headers.authorization;
|
|
|
|
if (authorization == null) return next();
|
2014-11-12 12:14:37 +01:00
|
|
|
|
2017-04-23 20:02:26 +02:00
|
|
|
let parts = authorization.split(' ');
|
2014-11-12 12:14:37 +01:00
|
|
|
|
|
|
|
if (parts.length !== 2)
|
2017-04-23 20:02:26 +02:00
|
|
|
return next( Error[400]('bad authorization header') );
|
2014-11-12 12:14:37 +01:00
|
|
|
|
2017-04-23 20:02:26 +02:00
|
|
|
let scheme = parts[0];
|
2014-11-24 20:46:37 +01:00
|
|
|
if (scheme === 'Basic') {
|
2017-04-23 20:02:26 +02:00
|
|
|
var credentials = new Buffer(parts[1], 'base64').toString();
|
2014-11-24 20:46:37 +01:00
|
|
|
} else if (scheme === 'Bearer') {
|
2017-04-23 20:02:26 +02:00
|
|
|
var credentials = self.aes_decrypt(new Buffer(parts[1], 'base64')).toString('utf8');
|
|
|
|
if (!credentials) return next();
|
2014-11-24 20:46:37 +01:00
|
|
|
} else {
|
2017-04-23 20:02:26 +02:00
|
|
|
return next();
|
2014-11-24 20:46:37 +01:00
|
|
|
}
|
|
|
|
|
2017-04-23 20:02:26 +02:00
|
|
|
let index = credentials.indexOf(':');
|
|
|
|
if (index < 0) return next();
|
2014-11-12 12:14:37 +01:00
|
|
|
|
2017-04-23 20:02:26 +02:00
|
|
|
let user = credentials.slice(0, index);
|
|
|
|
let pass = credentials.slice(index + 1);
|
2014-11-12 12:14:37 +01:00
|
|
|
|
2014-11-16 13:37:50 +01:00
|
|
|
self.authenticate(user, pass, function(err, user) {
|
|
|
|
if (!err) {
|
2017-04-23 20:02:26 +02:00
|
|
|
req.remote_user = user;
|
|
|
|
next();
|
2014-11-12 12:14:37 +01:00
|
|
|
} else {
|
2017-04-23 20:02:26 +02:00
|
|
|
req.remote_user = buildAnonymousUser();
|
|
|
|
next(err);
|
2014-11-12 12:14:37 +01:00
|
|
|
}
|
2017-04-23 20:02:26 +02:00
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
2014-09-02 01:09:08 +02:00
|
|
|
|
2014-11-16 13:37:50 +01:00
|
|
|
Auth.prototype.bearer_middleware = function() {
|
2017-04-23 20:02:26 +02:00
|
|
|
let self = this;
|
2014-11-16 13:37:50 +01:00
|
|
|
return function(req, res, _next) {
|
2017-04-23 20:02:26 +02:00
|
|
|
req.pause();
|
2015-03-28 19:25:53 +01:00
|
|
|
function next(_err) {
|
2017-04-23 20:02:26 +02:00
|
|
|
req.resume();
|
|
|
|
return _next.apply(null, arguments);
|
2014-11-16 13:37:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (req.remote_user != null && req.remote_user.name !== undefined)
|
2017-04-23 20:02:26 +02:00
|
|
|
return next();
|
|
|
|
req.remote_user = buildAnonymousUser();
|
2014-11-16 13:37:50 +01:00
|
|
|
|
2017-04-23 20:02:26 +02:00
|
|
|
let authorization = req.headers.authorization;
|
|
|
|
if (authorization == null) return next();
|
2014-11-16 13:37:50 +01:00
|
|
|
|
2017-04-23 20:02:26 +02:00
|
|
|
let parts = authorization.split(' ');
|
2014-11-16 13:37:50 +01:00
|
|
|
|
|
|
|
if (parts.length !== 2)
|
2017-04-23 20:02:26 +02:00
|
|
|
return next( Error[400]('bad authorization header') );
|
2014-11-16 13:37:50 +01:00
|
|
|
|
2017-04-23 20:02:26 +02:00
|
|
|
let scheme = parts[0];
|
|
|
|
let token = parts[1];
|
2014-11-16 13:37:50 +01:00
|
|
|
|
|
|
|
if (scheme !== 'Bearer')
|
2017-04-23 20:02:26 +02:00
|
|
|
return next();
|
2014-11-16 13:37:50 +01:00
|
|
|
|
|
|
|
try {
|
2017-04-23 20:02:26 +02:00
|
|
|
var user = self.decode_token(token);
|
2014-11-16 13:37:50 +01:00
|
|
|
} catch(err) {
|
2017-04-23 20:02:26 +02:00
|
|
|
return next(err);
|
2014-11-16 13:37:50 +01:00
|
|
|
}
|
2014-11-12 12:14:37 +01:00
|
|
|
|
2017-04-23 20:02:26 +02:00
|
|
|
req.remote_user = authenticatedUser(user.u, user.g);
|
|
|
|
req.remote_user.token = token;
|
|
|
|
next();
|
|
|
|
};
|
|
|
|
};
|
2014-11-16 13:37:50 +01:00
|
|
|
|
|
|
|
Auth.prototype.cookie_middleware = function() {
|
2017-04-23 20:02:26 +02:00
|
|
|
let self = this;
|
2014-11-12 12:14:37 +01:00
|
|
|
return function(req, res, _next) {
|
2017-04-23 20:02:26 +02:00
|
|
|
req.pause();
|
2015-03-28 19:25:53 +01:00
|
|
|
function next(_err) {
|
2017-04-23 20:02:26 +02:00
|
|
|
req.resume();
|
|
|
|
return _next();
|
2014-11-12 12:14:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (req.remote_user != null && req.remote_user.name !== undefined)
|
2017-04-23 20:02:26 +02:00
|
|
|
return next();
|
2014-11-12 12:14:37 +01:00
|
|
|
|
2017-04-23 20:02:26 +02:00
|
|
|
req.remote_user = buildAnonymousUser();
|
2014-11-12 12:14:37 +01:00
|
|
|
|
2017-04-23 20:02:26 +02:00
|
|
|
let token = req.cookies.get('token');
|
|
|
|
if (token == null) return next();
|
2014-11-12 12:14:37 +01:00
|
|
|
|
2017-04-23 20:02:26 +02:00
|
|
|
/* try {
|
2014-11-24 20:46:37 +01:00
|
|
|
var user = self.decode_token(token, 60*60)
|
2014-11-16 13:37:50 +01:00
|
|
|
} catch(err) {
|
|
|
|
return next()
|
|
|
|
}
|
2014-11-12 12:14:37 +01:00
|
|
|
|
2017-04-23 20:02:26 +02:00
|
|
|
req.remote_user = authenticatedUser(user.u, user.g)
|
2014-11-16 13:37:50 +01:00
|
|
|
req.remote_user.token = token
|
2014-11-24 20:46:37 +01:00
|
|
|
next()*/
|
2017-04-23 20:02:26 +02:00
|
|
|
let credentials = self.aes_decrypt(new Buffer(token, 'base64')).toString('utf8');
|
|
|
|
if (!credentials) return next();
|
2014-11-24 20:46:37 +01:00
|
|
|
|
2017-04-23 20:02:26 +02:00
|
|
|
let index = credentials.indexOf(':');
|
|
|
|
if (index < 0) return next();
|
2014-11-24 20:46:37 +01:00
|
|
|
|
2017-04-23 20:02:26 +02:00
|
|
|
let user = credentials.slice(0, index);
|
|
|
|
let pass = credentials.slice(index + 1);
|
2014-11-24 20:46:37 +01:00
|
|
|
|
|
|
|
self.authenticate(user, pass, function(err, user) {
|
|
|
|
if (!err) {
|
2017-04-23 20:02:26 +02:00
|
|
|
req.remote_user = user;
|
|
|
|
next();
|
2014-11-24 20:46:37 +01:00
|
|
|
} else {
|
2017-04-23 20:02:26 +02:00
|
|
|
req.remote_user = buildAnonymousUser();
|
|
|
|
next(err);
|
2014-11-24 20:46:37 +01:00
|
|
|
}
|
2017-04-23 20:02:26 +02:00
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
2014-11-04 15:47:03 +01:00
|
|
|
|
2014-11-16 13:37:50 +01:00
|
|
|
Auth.prototype.issue_token = function(user) {
|
2017-04-23 20:02:26 +02:00
|
|
|
let data = jju.stringify({
|
2014-11-16 13:37:50 +01:00
|
|
|
u: user.name,
|
|
|
|
g: user.real_groups && user.real_groups.length ? user.real_groups : undefined,
|
|
|
|
t: ~~(Date.now()/1000),
|
2017-04-23 20:02:26 +02:00
|
|
|
}, {indent: false});
|
2014-11-16 13:37:50 +01:00
|
|
|
|
2017-04-23 20:02:26 +02:00
|
|
|
data = new Buffer(data, 'utf8');
|
|
|
|
let mac = Crypto.createHmac('sha256', this.secret).update(data).digest();
|
|
|
|
return Buffer.concat([data, mac]).toString('base64');
|
|
|
|
};
|
2014-11-16 13:37:50 +01:00
|
|
|
|
|
|
|
Auth.prototype.decode_token = function(str, expire_time) {
|
2017-04-23 20:02:26 +02:00
|
|
|
let buf = new Buffer(str, 'base64');
|
|
|
|
if (buf.length <= 32) throw Error[401]('invalid token');
|
2014-11-16 13:37:50 +01:00
|
|
|
|
2017-04-23 20:02:26 +02:00
|
|
|
let data = buf.slice(0, buf.length - 32);
|
|
|
|
let their_mac = buf.slice(buf.length - 32);
|
|
|
|
let good_mac = Crypto.createHmac('sha256', this.secret).update(data).digest();
|
2014-11-16 13:37:50 +01:00
|
|
|
|
2017-04-23 20:02:26 +02:00
|
|
|
their_mac = Crypto.createHash('sha512').update(their_mac).digest('hex');
|
|
|
|
good_mac = Crypto.createHash('sha512').update(good_mac).digest('hex');
|
|
|
|
if (their_mac !== good_mac) throw Error[401]('bad signature');
|
2014-11-16 13:37:50 +01:00
|
|
|
|
|
|
|
// make token expire in 24 hours
|
|
|
|
// TODO: make configurable?
|
2017-04-23 20:02:26 +02:00
|
|
|
expire_time = expire_time || 24*60*60;
|
2014-11-16 13:37:50 +01:00
|
|
|
|
2017-04-23 20:02:26 +02:00
|
|
|
data = jju.parse(data.toString('utf8'));
|
2014-11-16 13:37:50 +01:00
|
|
|
if (Math.abs(data.t - ~~(Date.now()/1000)) > expire_time)
|
2017-04-23 20:02:26 +02:00
|
|
|
throw Error[401]('token expired');
|
2014-11-16 13:37:50 +01:00
|
|
|
|
2017-04-23 20:02:26 +02:00
|
|
|
return data;
|
|
|
|
};
|
2014-11-16 13:37:50 +01:00
|
|
|
|
2014-11-24 20:46:37 +01:00
|
|
|
Auth.prototype.aes_encrypt = function(buf) {
|
2017-04-23 20:02:26 +02:00
|
|
|
let c = Crypto.createCipher('aes192', this.secret);
|
|
|
|
let b1 = c.update(buf);
|
|
|
|
let b2 = c.final();
|
|
|
|
return Buffer.concat([b1, b2]);
|
|
|
|
};
|
2014-11-24 20:46:37 +01:00
|
|
|
|
|
|
|
Auth.prototype.aes_decrypt = function(buf) {
|
|
|
|
try {
|
2017-04-23 20:02:26 +02:00
|
|
|
let c = Crypto.createDecipher('aes192', this.secret);
|
|
|
|
let b1 = c.update(buf);
|
|
|
|
let b2 = c.final();
|
|
|
|
return Buffer.concat([b1, b2]);
|
2014-11-24 20:46:37 +01:00
|
|
|
} catch(_) {
|
2017-04-23 20:02:26 +02:00
|
|
|
return new Buffer(0);
|
2014-11-24 20:46:37 +01:00
|
|
|
}
|
2017-04-23 20:02:26 +02:00
|
|
|
};
|
2014-11-24 20:46:37 +01:00
|
|
|
|
2017-04-23 20:02:26 +02:00
|
|
|
function buildAnonymousUser() {
|
2014-11-12 12:14:37 +01:00
|
|
|
return {
|
|
|
|
name: undefined,
|
2015-02-24 20:28:16 +01:00
|
|
|
// groups without '$' are going to be deprecated eventually
|
2017-04-23 20:02:26 +02:00
|
|
|
groups: ['$all', '$anonymous', '@all', '@anonymous', 'all', 'undefined', 'anonymous'],
|
2014-11-16 13:37:50 +01:00
|
|
|
real_groups: [],
|
2017-04-23 20:02:26 +02:00
|
|
|
};
|
2014-09-02 01:09:08 +02:00
|
|
|
}
|
|
|
|
|
2017-04-23 20:02:26 +02:00
|
|
|
function authenticatedUser(name, groups) {
|
|
|
|
let _groups = (groups || []).concat(['$all', '$authenticated', '@all', '@authenticated', 'all']);
|
2014-11-12 12:14:37 +01:00
|
|
|
return {
|
|
|
|
name: name,
|
2014-11-16 13:37:50 +01:00
|
|
|
groups: _groups,
|
|
|
|
real_groups: groups,
|
2017-04-23 20:02:26 +02:00
|
|
|
};
|
2014-09-02 01:09:08 +02:00
|
|
|
}
|