Start basic LDAP server groundwork
This commit is contained in:
21
app/unit/LDAPRegistry.js
Normal file
21
app/unit/LDAPRegistry.js
Normal file
@@ -0,0 +1,21 @@
|
||||
const Unit = require('libflitter/Unit')
|
||||
|
||||
class LDAPRegistry extends Unit {
|
||||
static get name() {
|
||||
return 'ldap_registry'
|
||||
}
|
||||
|
||||
static get services() {
|
||||
return [...super.services, 'output']
|
||||
}
|
||||
|
||||
async go(app) {
|
||||
|
||||
}
|
||||
|
||||
async cleanup(app) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = exports = LDAPRegistry
|
||||
44
app/unit/LDAPServerUnit.js
Normal file
44
app/unit/LDAPServerUnit.js
Normal file
@@ -0,0 +1,44 @@
|
||||
const Unit = require('libflitter/Unit')
|
||||
const LDAP = require('ldapjs')
|
||||
|
||||
class LDAPServerUnit extends Unit {
|
||||
static get name() {
|
||||
return 'ldap_server'
|
||||
}
|
||||
|
||||
static get services() {
|
||||
return [...super.services, 'configs', 'express', 'output']
|
||||
}
|
||||
|
||||
async go(app) {
|
||||
this.config = this.configs.get('ldap:server')
|
||||
const server_config = {}
|
||||
|
||||
// If Flitter is configured to use an SSL certificate,
|
||||
// use it to enable LDAPS in the server.
|
||||
if ( this.express.use_ssl() ) {
|
||||
this.output.info('[LDAP Server] Using configured SSL certificate to enable LDAPS.')
|
||||
server_config.certificate = await this.express.ssl_certificate()
|
||||
server_config.key = await this.express.ssl_key()
|
||||
}
|
||||
|
||||
this.server = LDAP.createServer(server_config)
|
||||
|
||||
if ( this.config.max_connections ) {
|
||||
this.server.maxConnections = this.config.max_connections
|
||||
}
|
||||
|
||||
this.output.info(`[LDAP Server] Will listen on ${this.config.interface}:${this.config.port}`)
|
||||
await new Promise((res, rej) => {
|
||||
this.server.listen(this.config.port, this.config.interface, () => {
|
||||
res()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
async cleanup(app) {
|
||||
this.server.close()
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = exports = LDAPServerUnit
|
||||
Reference in New Issue
Block a user