gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 13:53:59 26 4
gpt4 key购买 nike

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

它必须处理的情况是用户架构的“memberOf”属性,就像 Active Directory 一样……但我不太确定如何将“用户”类添加到内存中的这个 ldap。

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

下面是我的非工作代码。

谢谢,
迈克·科豪特

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));
}

最佳答案

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

以下是您如何用包含 userPrincipalName 属性的对象类替换 person 对象类:

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

关于unit-testing - 为内存中的 UnboundID LDAP 服务器创建自定义架构/添加到现有架构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7842050/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com