错误:修改必须是groupOfNames成员修改ldapjs上的属性

问题描述 投票:0回答:1

我有一个代码应该将用户添加到 ldapjs 中的 groupOfNames

  function addUserToGroup(userDN, groupName, callback) {
    const groupDN = `cn=${groupName},ou=groups,dc=XXX`;
    console.log(userDN);
    console.log(groupDN);
    const change = new ldap.Change({
      operation: 'add',
      modification: {
        member: [userDN],
      },
    });
  
    client.modify(groupDN, change, (err) => {
      if (err) {
        console.error('Error adding user to group:', err);
      }
      callback(err, groupDN);
    });
  }

  addUserToGroup('uid=3d4dfc3d-7493-4a1d-9659-f1799a48a927,ou=people,dc=XXX', 'everybody', (err) => {
    if (err) {
      console.error('Error assigning user to group:', err);
    }
  });

但是它抛出了这个错误

uid=3d4dfc3d-7493-4a1d-9659-f1799a48a927,ou=people,dc=XXX
cn=everybody,ou=groups,dc=XXX
C:\XXX\projects\ldaptest\node_modules\@ldapjs\change\index.js:55
      throw Error('modification must be an Attribute')
      ^

Error: modification must be an Attribute
    at Change.set modification [as modification] (C:\XXX\projects\ldaptest\node_modules\@ldapjs\change\index.js:55:13)
    at new Change (C:\XXX\projects\ldaptest\node_modules\@ldapjs\change\index.js:29:23)
    at addUserToGroup (C:\XXX\projects\ldaptest\index.js:169:20)
    at C:\XXX\projects\ldaptest\index.js:44:3
    at callbackWrapper (C:\XXX\projects\ldaptest\node_modules\ldapjs\lib\client\client.js:296:5)
    at sendResult (C:\XXX\projects\ldaptest\node_modules\ldapjs\lib\client\client.js:1244:12)
    at messageCallback (C:\XXX\projects\ldaptest\node_modules\ldapjs\lib\client\client.js:1269:16)
    at Parser.onMessage (C:\XXX\projects\ldaptest\node_modules\ldapjs\lib\client\client.js:925:14)
    at Parser.emit (node:events:527:28)
    at Parser.write (C:\XXX\projects\ldaptest\node_modules\ldapjs\lib\messages\parser.js:135:8)
[nodemon] app crashed - waiting for file changes before starting...

我用一些在线示例更改了代码,但找不到有效的代码。有什么帮助吗?

node.js openldap ldapjs
1个回答
0
投票

我遇到了同样的错误,但是我得到了解决方案,

const userPasswordAttribute = new ldap.Attribute({
  type: 'member',
  values: userDN
});

const change = new ldap.Change({
  operation: 'add',
  modification: userPasswordAttribute
});

详情请参阅页面

© www.soinside.com 2019 - 2024. All rights reserved.