node-ldapjs/lib/messages/bind_request.js

85 lines
1.8 KiB
JavaScript
Raw Normal View History

2011-08-04 20:32:01 +00:00
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
2020-10-31 21:07:32 +00:00
const assert = require('assert-plus')
const util = require('util')
2011-08-04 20:32:01 +00:00
2020-10-31 21:07:32 +00:00
const asn1 = require('asn1')
2011-08-04 20:32:01 +00:00
2020-10-31 21:07:32 +00:00
const LDAPMessage = require('./message')
const Protocol = require('../protocol')
2011-08-04 20:32:01 +00:00
/// --- Globals
2020-10-31 21:07:32 +00:00
const Ber = asn1.Ber
const LDAP_BIND_SIMPLE = 'simple'
// var LDAP_BIND_SASL = 'sasl'
2011-08-04 20:32:01 +00:00
/// --- API
2011-08-04 20:32:01 +00:00
function BindRequest (options) {
options = options || {}
assert.object(options)
2011-08-04 20:32:01 +00:00
options.protocolOp = Protocol.LDAP_REQ_BIND
LDAPMessage.call(this, options)
2011-08-04 20:32:01 +00:00
this.version = options.version || 0x03
this.name = options.name || null
this.authentication = options.authentication || LDAP_BIND_SIMPLE
this.credentials = options.credentials || ''
2011-08-04 20:32:01 +00:00
}
util.inherits(BindRequest, LDAPMessage)
Object.defineProperties(BindRequest.prototype, {
type: {
get: function getType () { return 'BindRequest' },
configurable: false
},
_dn: {
get: function getDN () { return this.name },
configurable: false
}
})
2011-08-04 20:32:01 +00:00
BindRequest.prototype._parse = function (ber) {
assert.ok(ber)
2011-08-04 20:32:01 +00:00
this.version = ber.readInt()
this.name = ber.readString()
2011-08-04 20:32:01 +00:00
2020-10-31 21:07:32 +00:00
const t = ber.peek()
2011-08-04 20:32:01 +00:00
// TODO add support for SASL et al
if (t !== Ber.Context) { throw new Error('authentication 0x' + t.toString(16) + ' not supported') }
2011-08-04 20:32:01 +00:00
this.authentication = LDAP_BIND_SIMPLE
this.credentials = ber.readString(Ber.Context)
2011-08-04 20:32:01 +00:00
return true
}
2011-08-04 20:32:01 +00:00
BindRequest.prototype._toBer = function (ber) {
assert.ok(ber)
2011-08-04 20:32:01 +00:00
ber.writeInt(this.version)
ber.writeString((this.name || '').toString())
2011-08-04 20:32:01 +00:00
// TODO add support for SASL et al
ber.writeString((this.credentials || ''), Ber.Context)
2011-08-04 20:32:01 +00:00
return ber
}
2011-08-04 20:32:01 +00:00
BindRequest.prototype._json = function (j) {
assert.ok(j)
2011-08-04 20:32:01 +00:00
j.version = this.version
j.name = this.name
j.authenticationType = this.authentication
j.credentials = this.credentials
return j
}
/// --- Exports
module.exports = BindRequest