为内存中的UnboundID LDAP服务器创建自定义架构/添加到现有架构

时间:2011-10-20 20:48:13

标签: unit-testing active-directory ldap

我正在尝试从我的应用程序必须处理的字段复制LDAP布局/架构 - 我正在尝试使用可嵌入的UnboundID LDAP服务器通过自动化测试重新创建+测试它。

它必须处理的情况是用户架构的'memberOf'属性,比如Active Directory ......但我不太确定如何在内存中为这个ldap添加'user'类。

1)这可能吗? 2)有更好的策略吗? 3)我应该做些什么?我是LDAP新手。

以下是我的非工作代码。

谢谢, Mike Kohout

public class TestOpenLdap2
{
    private InMemoryDirectoryServer server;

    @Before
    public void start() throws Exception
    {
        InMemoryDirectoryServerConfig config = new InMemoryDirectoryServerConfig("dc=com");
        config.addAdditionalBindCredentials("cn=admin,ou=People,dc=example,dc=com", "cred");
        InMemoryListenerConfig listenerConfig = new InMemoryListenerConfig("test", null, 33390, null, null, null);
        config.setListenerConfigs(listenerConfig);
        server = new InMemoryDirectoryServer(config);
        server.startListening();
    }

    @Test
    public void testMemberOf() throws Exception
    {

        addEntry("dn: dc=com", "objectClass: top", "objectClass: domain", "dc: com");

        ObjectClassDefinition oc = new ObjectClassDefinition("10.19.19.78", new String[]{"user"}, "", false, new String[]{"TOP"},
                                                                              ObjectClassType.STRUCTURAL, new String[]{"memberOf"},
                                                                              new String[]{}, new HashMap());
        addEntry("dn: cn=schema2,dc=com", "objectClass: top", "objectClass: ldapSubEntry", "objectClass: subschema", "cn: schema2",
                    "objectClasses:  " + oc.toString());

        addEntry("dn: dc=people,dc=com", "objectClass: top", "objectClass: domain", "dc: people");
        addEntry("dn: dc=groups,dc=com", "objectClass: top", "objectClass: domain", "dc: groups");
        addEntry("dn: cn=test-group,dc=groups,dc=com", "objectClass: groupOfUniqueNames", "cn: test group");
        addEntry("dn: cn=Testy Tester,dc=people,dc=com", "objectClass: Person", "objectClass: user", "objectClass: organizationalPerson", "sn: Tester", "cn: Testy Tester", "memberOf: cn=test-group,dc=groups,dc=com");
    }

    public void addEntry(String... args) throws LDIFException, LDAPException
    {
        LDAPResult result = server.add(args);
        assert (result.getResultCode().intValue() == 0);
        System.out.println("added entry:" + Arrays.asList(args));
    }

3 个答案:

答案 0 :(得分:6)

任何遇到此问题的人都可能有兴趣知道所提到的功能是Neil Wilson已经实施(至少在com.unboundid:unboundid-ldapsdk:2.3.1中):)

以下是如何将personClass替换为包含userPrincipalName属性的人:

dn: cn=schema
changetype: modify
add: attributetypes
attributetypes: ( 1.2.3.4.5.6.7 NAME 'userPrincipalName' DESC 'userPrincipalName as per Active Directory' EQUALITY caseIgnoreMatch SYNTAX '1.3.6.1.4.1.1466.115.121.1.15' )

dn: cn=schema
changetype: modify
delete: objectClasses
objectClasses: ( 2.5.6.6
                 NAME 'person'
                 SUP top
                 STRUCTURAL
                 MUST ( sn $
                        cn )
                 MAY ( userPassword $
                       telephoneNumber $
                       seeAlso $
                       description )
                 X-ORIGIN 'RFC 4519' )

dn: cn=schema
changetype: modify
add: objectClasses
objectClasses: ( 2.5.6.6
                 NAME 'person'
                 SUP top
                 STRUCTURAL
                 MUST ( sn $
                        cn $
                        userPrincipalName )
                 MAY ( userPassword $
                       telephoneNumber $
                       seeAlso $
                       description ) )

请注意,必须删除person objectClass。它被定义为'objectClasses'属性,您必须指定整个定义才能引用它。该定义位于Neil提到的默认模式中:docs / standard-schema.ldif

我从一些描述如何修改架构元素的Oracle文档中复制了userPrincipalName属性定义:http://docs.oracle.com/cd/E12839_01/oid.1111/e10035/ldif_appendix.htm#CHDCCJIG

答案 1 :(得分:4)

目前,内存中目录服务器不支持在线模式更改(即,通过LDAP修改操作更新cn =模式条目)。这是我的待办事项清单,但尚未实施。

但是,如果您只想自定义服务器运行的架构,则只需使用要使用的架构初始化服务器即可。您可以根据多个文件中的信息创建模式(默认情况下,内存服务器使用的模式包含在docs / standard-schema.ldif文件中,因此您只需添加包含所需自定义模式元素的第二个文件使用)。

尼尔

答案 2 :(得分:0)

在纯LDAP考虑中,您要使用的行为称为 Referencial Integrity ,我可以在LDAP SDK for Java中阅读

  • 它提供了一个选项,用于维护指定的一组属性的参照完整性,以便删除和修改DN操作......

我不能帮助你。

目前,Active-Directory是目标,测试的一个好处是安装ADAM(Active Dirctory Application Mode)。它是Microsoft的免费目录,您可以使用它来复制AD架构和对象。您可以在Windows XP上安装的ADAM is a redistribuable。要在Windows 7上安装,最好使用LDS(Lightweight directory service)。两者都使用工具从AD迁移AD架构和对象。