【问题标题】:ldapjs connecting to LDAP (ldap.forumsys.com) failsldapjs 连接到 LDAP (ldap.forumsys.com) 失败
【发布时间】:2018-08-01 06:02:43
【问题描述】:

这是一个在线 LDPA 测试服务器,http://www.forumsys.com/tutorials/integration-how-to/ldap/online-ldap-test-server/

所以我做了一些简单的脚本来测试它,但我总是得到不需要的响应。

这是我的代码:

const ldap = require('ldapjs');
const assert = require('assert');

// LDAP Connection Settings
const server = "ldap.forumsys.com";
const uid = "tesla"
const password = "password"; // User password

// Create client and bind to AD
const client = ldap.createClient({
    url: `ldap://${server}`
});

// Search AD for user
const searchOptions = {
  filter: '(uid=${uid})'
};

// client.bind(`uid=tesla,dc=example,dc=com`,password,err => {
//     assert.ifError(err);
// });

client.search(`cn=read-only-admin,dc=example,dc=com`,searchOptions,(err,res) => {
    assert.ifError(err);

    res.on('searchEntry', entry => {
        console.log(entry.object.name);
    });
    res.on('searchReference', referral => {
        console.log('referral: ' + referral.uris.join());
    });
    res.on('error', err => {
        console.error('error: ' + err.message);
    });
    res.on('end', result => {
        console.log(result);
    });
});


// Wrap up
client.unbind( err => {
    assert.ifError(err);
});

我通过运行 app.js 来恢复它

SearchResponse {
  messageID: 1,
  protocolOp: 101,
  controls: [],
  log: 
   Logger {
     domain: null,
     _events: {},
     _eventsCount: 0,
     _maxListeners: undefined,
     _isSimpleChild: true,
     _level: 30,
     streams: [ [Object] ],
     serializers: { req: [Function], res: [Function], err: [Function] },
     src: false,
     fields: 
      { name: 'ldapjs',
        component: 'client',
        hostname: 'will-ThinkPad-T440p',
        pid: 17485,
        clazz: 'Client' } },
  status: 0,
  matchedDN: '',
  errorMessage: '',
  referrals: [],
  connection: 
   Socket {
     connecting: false,
     _hadError: false,
     _handle: 
      TCP {
        reading: true,
        owner: [Circular],
        onread: [Function: onread],
        onconnection: null,
        writeQueueSize: 0 },
     _parent: null,
     _host: 'ldap.forumsys.com',
     _readableState: 
      ReadableState {
        objectMode: false,
        highWaterMark: 16384,
        buffer: [Object],
        length: 0,
        pipes: null,
        pipesCount: 0,
        flowing: true,
        ended: false,
        endEmitted: false,
        reading: false,
        sync: false,
        needReadable: true,
        emittedReadable: false,
        readableListening: false,
        resumeScheduled: false,
        destroyed: false,
        defaultEncoding: 'utf8',
        awaitDrain: 0,
        readingMore: false,
        decoder: null,
        encoding: null },
     readable: true,
     domain: null,
     _events: 
      { finish: [Function: onSocketFinish],
        _socketEnd: [Function: onSocketEnd],
        data: [Function: onData],
        close: [Object],
        end: [Function: onEnd],
        error: [Function: onSocketError],
        timeout: [Function: onTimeout] },
     _eventsCount: 7,
     _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,
        bufferedRequestCount: 0,
        corkedRequestsFree: [Object] },
     writable: true,
     allowHalfOpen: false,
     _bytesDispatched: 79,
     _sockname: null,
     _pendingData: null,
     _pendingEncoding: '',
     server: null,
     _server: null,
     [Symbol(asyncId)]: 8,
     [Symbol(bytesRead)]: 0 },
  attributes: [],
  notAttributes: [],
  sentEntries: 0 }

其中不包含任何有关“特斯拉”的信息......

【问题讨论】:

  • 您能否详细说明该响应是不需要/失败的?它有什么问题?
  • 嘿,@halfer,是的。我已经通过附加整个回复更新了帖子,其中不包含任何关于我正在查询的“特斯拉”的信息。谢谢。

标签: ldap openldap ldapjs


【解决方案1】:

可能是这个部分:

// Search AD for user
const searchOptions = {
  filter: '(uid=${uid})'
};

需要像上面的 url 设置这样的反引号?如果这是一个动态值,您应该添加它们以将其转换为字符串文字,例如:

// Search AD for user
const searchOptions = {
  filter: `(uid=${uid})`
};

【讨论】:

    【解决方案2】:
    const searchOptions = {
      filter: '(uid=${uid})'
    };
    

    以上部分不正确。 应该是

    const searchOptions = {
      filter: `(uid=${uid})`
    };
    

    我认为古斯塔夫已经给出了正确答案。但除此之外,原因是当使用' 时,变量替换不会像您预期的那样发生。要构建这样的字符串,您需要使用 `

    反正既然你已经写了一个LDAP测试服务器,那么已经有写好的测试服务器来实现了,例如,你可以使用

    https://hub.docker.com/r/upekshejay/simple-ldap-test-server

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-29
      • 1970-01-01
      • 1970-01-01
      • 2019-09-15
      • 1970-01-01
      相关资源
      最近更新 更多