2

我不确定如何通过 UnboundID 正确传递 OpenLDAP 插入所需的多个属性。我省略了 objectClass 属性并收到“no objectClass”错误。我还尝试了逗号分隔和括号/数组路由,如下所示并收到“值 #0 每个语法无效”错误。

String[] ldifLines = {"dn: ou=users,dc=sub,dc=domain,dc=com", "cn: " + uid, "userPassword: " + pw, "description: user", "uidNumber: " + lclDT, "gidNumber: 504", "uid: " + uid, "homeDirectory: " + File.separator + "home" + File.separator + this.getStrippedUser(), "objectClass: {posixAccount, top}"};
LDAPResult ldapResult = lclLC.add(new AddRequest(ldifLines));

那么,问题来了,如何在上面包含的字符串数组中成功传递这些objectClass属性呢?同样,我也尝试过:“objectClass:top,posixAccount”。提前致谢!

4

1 回答 1

3

它使用 LDIF 表示,因此如果一个属性有多个值,则该属性会出现多次。喜欢:

 String[] ldifLines = 
 {
   "dn: ou=users,dc=sub,dc=domain,dc=com",
   "objectClass: top",
   "objectClass: posixAccount"
   "cn: " + uid,
   "userPassword: " + pw,
   "description: user",
   "uidNumber: " + lclDT,
   "gidNumber: 504",
   "uid: " + uid,
   "homeDirectory: " + File.separator + "home" +
        File.separator + this.getStrippedUser(),
 };
 LDAPResult ldapResult = lclLC.add(new AddRequest(ldifLines));

此外,LDAP SDK 允许您使用快捷方式,只需一次调用即可完成,而无需创建数组或 AddRequest 对象,例如:

 LDAPResult ldapResult = lclLC.add(
      "dn: ou=users,dc=sub,dc=domain,dc=com",
      "objectClass: top",
      "objectClass: posixAccount"
      "cn: " + uid,
      "userPassword: " + pw,
      "description: user",
      "uidNumber: " + lclDT,
      "gidNumber: 504",
      "uid: " + uid,
      "homeDirectory: " + File.separator + "home" +
           File.separator + this.getStrippedUser());
于 2015-02-21T23:36:36.913 回答