【问题标题】:How to import ldif file using unboundid-ldap-sdp?如何使用 unboundid-ldap-sdp 导入 ldif 文件?
【发布时间】:2013-07-25 13:25:17
【问题描述】:

我从 LDAP 服务器导出了以下 ldif 文件,现在正尝试导入它,以便复制我从中导出它的目录:

dn: cn=MYCOMPANY Users,dc=mycompany,dc=com
changetype: add
objectClass: posixGroup
objectClass: top
cn: MYCOMPANY Users
gidNumber: 1001

dn: cn=jim smith,cn=MYCOMPANY Users,dc=mycompany,dc=com
objectClass: inetOrgPerson
objectClass: posixAccount
objectClass: top
givenName: jim
cn: jim smith
sn: smith
gidNumber: 1000
homeDirectory: /home/users/arolls
uid: jsmith
uidNumber: 1038
userPassword: {MD5}X03MO1qnZdYdgyfeuILPmQ==

dn: cn=dave jones,cn=MYCOMPANY Users,dc=mycompany,dc=com
objectClass: inetOrgPerson
objectClass: posixAccount
objectClass: top
givenName: dave
userPassword: {MD5}FhCDh0PMkOPk/dp0goLZuA==
loginShell: /bin/sh
cn: dave jones
sn: dave
gidNumber: 1000
homeDirectory: /home/users/dave
uid: dave
uidNumber: 1006

我正在尝试使用

LDIFReader r = new LDIFReader(resourceAsStream);
LDIFChangeRecord readEntry = null;
while ((readEntry = r.readChangeRecord()) != null) {
  readEntry.processChange(server);
}

我收到以下错误,有人知道我做错了什么吗?

LDAPException(resultCode=65 (object class violation), errorMessage='Unable to add entry 'cn=MYCOMPANY Users,dc=mycompany,dc=com' because it violates the provided schema: The entry contains object class posixGroup which is not defined in the schema. The entry contains attribute cn which is not allowed by its object classes and/or DIT content rule. The entry contains attribute gidNumber which is not defined in the schema. The entry's RDN contains attribute cn which is not allowed to be included in the entry.', diagnosticMessage='Unable to add entry 'cn=MYCOMPANY Users,dc=mycompany,dc=com' because it violates the provided schema: The entry contains object class posixGroup which is not defined in the schema. The entry contains attribute cn which is not allowed by its object classes and/or DIT content rule. The entry contains attribute gidNumber which is not defined in the schema. The entry's RDN contains attribute cn which is not allowed to be included in the entry.')

at com.unboundid.ldap.listener.InMemoryDirectoryServer.add(InMemoryDirectoryServer.java:1382)
at com.unboundid.ldif.LDIFAddChangeRecord.processChange(LDIFAddChangeRecord.java:213)
at com.github.trevershick.test.ldap.LdapServerResource.loadLdifFiles(LdapServerResource.java:156)
at com.github.trevershick.test.ldap.LdapServerResource.start(LdapServerResource.java:81)
at org.rory.util.services.ldap.TestLDAPAuthUIUtilUsingInMemoryLdapServer.startup(TestLDAPAuthUIUtilUsingInMemoryLdapServer.java:42)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
java.lang.NullPointerException
at org.rory.util.services.ldap.TestLDAPAuthUIUtilUsingInMemoryLdapServer.shutdown(TestLDAPAuthUIUtilUsingInMemoryLdapServer.java:47)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

非常感谢!

【问题讨论】:

    标签: java ldap unboundid-ldap-sdk ldif


    【解决方案1】:

    感谢 Neil 通过https://sourceforge.net/p/ldap-sdk/discussion/1001257/thread/08ceb8da/?limit=25#65b0 完成这项工作。

    具体来说,我需要做两件事:

    1. 通过以下方式禁用架构检查:

    InMemoryDirectoryServerConfig.setSchema(null)

    1. 在 ldif 的顶部添加了以下 4 行:

    dn: dc=mycompany,dc=com

    objectClass: 顶部

    objectClass:域

    dc: 我的公司

    【讨论】:

      【解决方案2】:

      在您的目录服务器架构中找不到 objectClass posixGroupposixGroupRFC 2307-bis 定义。您需要将该 objectClass 及其关联属性添加到架构中,然后添加您的 LDIF 更改记录。

      【讨论】:

      • 谢谢,那么您知道如何使用 unboundid-ldap-sdk 将其添加到架构中吗?
      • 这取决于正在使用的服务器。如果服务器支持架构的 LDAP 后端,则可以使用 ModifyRequest 添加架构。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-05
      相关资源
      最近更新 更多