Ability to not create users on first sign in (fix #497).

This commit is contained in:
Julien Fontanet 2015-11-17 15:59:31 +01:00
parent f0497ec16d
commit bd9396b031
3 changed files with 18 additions and 5 deletions

View File

@ -10,5 +10,10 @@
],
"mounts": {}
},
"datadir": "/var/lib/xo-server/data"
"datadir": "/var/lib/xo-server/data",
// Should users be created on first sign in?
//
// Necessary for external authentication providers.
"createUserOnFirstSignin": true
}

View File

@ -581,8 +581,8 @@ export default async function main (args) {
// Create the main object which will connects to Xen servers and
// manages all the models.
const xo = new Xo()
await xo.start(config)
const xo = new Xo(config)
await xo.start()
// Loads default authentication providers.
registerPasswordAuthenticationProvider(xo)

View File

@ -105,9 +105,11 @@ class NoSuchRemote extends NoSuchObject {
// ===================================================================
export default class Xo extends EventEmitter {
constructor () {
constructor (config) {
super()
this._config = config
this._objects = new XoCollection()
this._objects.createIndex('byRef', new XoUniqueIndex('_xapiRef'))
@ -143,7 +145,9 @@ export default class Xo extends EventEmitter {
// -----------------------------------------------------------------
async start (config) {
async start () {
const { _config: config } = this
await fs.mkdirp(config.datadir)
this._leveldb = sublevel(levelup(`${config.datadir}/leveldb`, {
@ -393,6 +397,10 @@ export default class Xo extends EventEmitter {
return user
}
if (!this._config.createUserOnFirstSignin) {
throw new Error(`registering ${name} user is forbidden`)
}
return await this.createUser(name, {
_provider: provider
})