Мое веб-приложение получает информацию с LDAP-сервера.Пользователь должен войти на LDAP-сервер со своим именем пользователя и паролем.Я хочу сохранить LDAP-клиент в сеансе, чтобы пользователю не нужно было вводить свой пароль каждый раз, когда он делает запрос.
Я использую экспресс и экспресс-сеанс для обработки сеанса.Я использую ldapjs-client https://www.npmjs.com/package/ldapjs-client,, который, по сути, является оболочкой для ldapjs.Я пробовал это с обычной библиотекой ldapjs, но она тоже не работает.
Когда сохраненный клиент используется в том же запросе, он работает.Однако, если он загружен из сеанса в другом запросе, он больше не работает.
Отображается следующее сообщение об ошибке:
TypeError: client.search is not a function
Я пытался обернуть клиента в объект и сохранить объект, но он не работает.
Код для сохранения клиента:
//Client initialattion.
const LdapClient = require("ldapjs-client");
req.session.client = new LdapClient({ url: "ldap://Ip-To-Ldap:389" });
await req.session.client.bind(req.body.name, req.body.password);
client-Object перед первым запросом:
Client {
url: 'ldap://Ip-To-Server:389',
protocol: 'ldap:',
slashes: true,
auth: null,
host: 'Ip-To-Server',
port: 389,
hostname: 'Ip-To-Server',
hash: null,
query: null,
pathname: null,
path: null,
href: 'ldap://Ip-To-Server:389',
secure: false,
_queue: Map {},
_parser:
Parser {
domain: null,
_events:
[Object: null prototype] { error: [Function], message: [Function] },
_eventsCount: 2,
_maxListeners: undefined,
buffer: null },
_socket:
Socket {
connecting: false,
_hadError: false,
_handle:
TCP {
reading: true,
onread: [Function: onStreamRead],
onconnection: null,
[Symbol(owner)]: [Circular] },
_parent: null,
_host: 'ldap.zhaw.ch',
_readableState:
ReadableState {
objectMode: false,
highWaterMark: 16384,
buffer: BufferList { head: null, tail: null, length: 0 },
length: 0,
pipes: null,
pipesCount: 0,
flowing: true,
ended: false,
endEmitted: false,
reading: true,
sync: false,
needReadable: true,
emittedReadable: false,
readableListening: false,
resumeScheduled: false,
paused: false,
emitClose: false,
autoDestroy: false,
destroyed: false,
defaultEncoding: 'utf8',
awaitDrain: 0,
readingMore: false,
decoder: null,
encoding: null },
readable: true,
domain: null,
_events:
[Object: null prototype] {
end: [Function: onReadableStreamEnd],
close: [Function: destroy],
error: [Function],
data: [Function] },
_eventsCount: 4,
_maxListeners: undefined,
_writableState:
WritableState {
objectMode: false,
highWaterMark: 16384,
finalCalled: false,
needDrain: false,
ending: false,
ended: false,
finished: false,
destroyed: false,
decodeStrings: false,
defaultEncoding: 'utf8',
length: 0,
writing: false,
corked: 0,
sync: false,
bufferProcessing: false,
onwrite: [Function: bound onwrite],
writecb: null,
writelen: 0,
bufferedRequest: null,
lastBufferedRequest: null,
pendingcb: 0,
prefinished: false,
errorEmitted: false,
emitClose: false,
autoDestroy: false,
bufferedRequestCount: 0,
corkedRequestsFree: [Object] },
writable: true,
allowHalfOpen: false,
_sockname: null,
_pendingData: null,
_pendingEncoding: '',
server: null,
_server: null,
[Symbol(asyncId)]: 91,
[Symbol(lastWriteQueueSize)]: 0,
[Symbol(timeout)]: null,
[Symbol(kBytesRead)]: 0,
[Symbol(kBytesWritten)]: 0 } }
После загрузки в другой запрос:
{ url: 'ldap://ldap.zhaw.ch:389',
protocol: 'ldap:',
slashes: true,
auth: null,
host: 'ldap.zhaw.ch',
port: 389,
hostname: 'ldap.zhaw.ch',
hash: null,
query: null,
pathname: null,
path: null,
href: 'ldap://ldap.zhaw.ch:389',
secure: false,
_queue: {},
_parser: { domain: null, _events: {}, _eventsCount: 2, buffer: null },
_socket:
{ connecting: false,
_hadError: false,
_handle: { reading: true, onconnection: null },
_parent: null,
_host: 'ldap.zhaw.ch',
_readableState:
{ objectMode: false,
highWaterMark: 16384,
buffer: [Object],
length: 0,
pipes: null,
pipesCount: 0,
flowing: true,
ended: false,
endEmitted: false,
reading: true,
sync: false,
needReadable: true,
emittedReadable: false,
readableListening: false,
resumeScheduled: false,
paused: false,
emitClose: false,
autoDestroy: false,
destroyed: false,
defaultEncoding: 'utf8',
awaitDrain: 0,
readingMore: false,
decoder: null,
encoding: null },
readable: true,
domain: null,
_events: {},
_eventsCount: 4,
_writableState:
{ objectMode: false,
highWaterMark: 16384,
finalCalled: false,
needDrain: false,
ending: false,
ended: false,
finished: false,
destroyed: false,
decodeStrings: false,
defaultEncoding: 'utf8',
length: 0,
writing: false,
corked: 0,
sync: false,
bufferProcessing: false,
writecb: null,
writelen: 0,
bufferedRequest: null,
lastBufferedRequest: null,
pendingcb: 0,
prefinished: false,
errorEmitted: false,
emitClose: false,
autoDestroy: false,
bufferedRequestCount: 0,
corkedRequestsFree: [Object] },
writable: true,
allowHalfOpen: false,
_sockname: null,
_pendingData: null,
_pendingEncoding: '',
server: null,
_server: null } }