av1987
av1987

Reputation: 493

Creating inmemory LDAP server that can authenticate login like domain\username. unboundid is not working

This is an old code for which I am writing an Endpoint Test and I need an inmemory LDAP SERVER to mock the actual ldap. so cannot change anything from the test code.

SERVER 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")));

Test code

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 file.

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: [email protected]
telephoneNumber: 617-776-2661
mobile: 617-776-3000
givenName: Ted
sn: Krilly

Exception message.

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)

Upvotes: 1

Views: 284

Answers (0)

Related Questions