首页 > 解决方案 > 创建可以验证登录的内存 LDAP 服务器,如域\用户名。unboundid 不工作

问题描述

这是我正在为其编写端点测试的旧代码,我需要一个内存中的 LDAP 服务器来模拟实际的 ldap。所以不能从test code.

服务器代码。

InMemoryDirectoryServerConfig config = new InMemoryDirectoryServerConfig("dc=sciencelogic");
            //config.addAdditionalBindCredentials("cn=Directory Manager", "password");
            config.setListenerConfigs(InMemoryListenerConfig.createLDAPConfig("default", 1389));
            config.setSchema(null);
            InMemoryDirectoryServer ds = new InMemoryDirectoryServer(config);
            ds.startListening();
            ds.importFromLDIF(true, new LDIFReader(getClass().getResourceAsStream("realm.ldif")));

测试代码

authDomainServerIP = "localhost:1389";//oCache.getItemKeyValue("authenticationDomainServerIP");
    Hashtable env = new Hashtable();
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
    env.put(Context.SECURITY_AUTHENTICATION, "simple");
    env.put(Context.PROVIDER_URL, "ldap://"+authDomainServerIP);

    // The value of Context.SECURITY_PRINCIPAL must be the logon username with the domain name
    env.put(Context.SECURITY_PRINCIPAL, "sciencelogic\\tkrilly");

    // The value of the Context.SECURITY_CREDENTIALS should be the user's password
    env.put(Context.SECURITY_CREDENTIALS, "password");

LDIF 文件。

dn: dc=sciencelogic
objectClass: top
objectClass: domain
dc: server


dn: uid=tkrilly,dc=sciencelogic
uid: tkrilly
sAMAccountName: tkrilly
userPrincipalName: tkrilly
cn: Ted Krilly
objectClass: top
objectClass: person
objectClass: inetOrgPerson
userPassword: password
street: 100 Commonwealth Avenue
l: Boston
st: MA
postalCode: 02134
mail: tkrilly@company.com
telephoneNumber: 617-776-2661
mobile: 617-776-3000
givenName: Ted
sn: Krilly

异常消息。

Error occured while authenticating the user : user.name - domain : CORP
Exception in thread "main" javax.naming.InvalidNameException: [LDAP: error code 34 - Unable to parse bind DN 'sciencelogic\tkrilly':  Unable to parse string 'sciencelogic\tkrilly' as a DN because it does not have an equal sign after RDN attribute 'sciencelogic\tkrilly'.]
    at com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:3095)
    at com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:2886)

标签: ldapunboundid-ldap-sdkunboundid

解决方案


推荐阅读