Hi there.
Im relatively (its been years) new to LDAP Im sure mine is a basic
newbie problem,
But I need to deliver an LDAP Java coding solution asap.
So...I installed Apache Directory Suite and Studio and loaded the
sevenSeas ldif file,
Brought up Apache Studio, got a connection, scanned the schema entries.
Now, my first LDAP with Java coding try: simply get a context connection
with the
Admin/admin system userid.  After that works I need to be able to
rebind? With other
User/passwords for authentication validation then retrieve a few
attributes.
Alas, my 1st coding attempt fails with :
javax.naming.InvalidNameException: [LDAP: error code 34 - Incorrect DN
given : admin (0x61 0x64 0x6D 0x69 0x6E ) is invalid]
        at
com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:2961)
        at
com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:2767)
        at com.sun.jndi.ldap.LdapCtx.connect(LdapCtx.java:2681)
        at com.sun.jndi.ldap.LdapCtx.<init>(LdapCtx.java:310)
        at
com.sun.jndi.ldap.LdapCtxFactory.getUsingURL(LdapCtxFactory.java:190)
        at
com.sun.jndi.ldap.LdapCtxFactory.getUsingURLs(LdapCtxFactory.java:208)
        at
com.sun.jndi.ldap.LdapCtxFactory.getLdapCtxInstance(LdapCtxFactory.java:
151)
        at
com.sun.jndi.ldap.LdapCtxFactory.getInitialContext(LdapCtxFactory.java:8
1)
        at
javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:679)
        at
javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:259)
        at javax.naming.InitialContext.init(InitialContext.java:235)
        at javax.naming.InitialContext.<init>(InitialContext.java:209)
        at bstt.dlt.ws.impl.LDAPTester.main(LDAPTester.java:35)
Error exiting...2


And here is my code try:
I suspect it may me the provider url?


package bstt.dlt.ws.impl;

import java.util.Hashtable;

import javax.naming.Context;
import javax.naming.NamingException;
import javax.naming.directory.DirContext;
import javax.naming.directory.InitialDirContext;

public class LDAPTester {
        
        
        
        public static void main(String[] args) {
                
                DirContext ctx = null;
                // TODO: init env variable from properties file
                // uid=admin,ou=system  pass=admin
                String sec_authentication = "simple";
                // env.put(Context.SECURITY_PRINCIPAL, "cn=S. User,
ou=NewHires, o=JNDITutorial");
                String sec_principal = "uid=admin, ou=system";
                //String sec_principal = "admin";
                String sec_credentials = "admin";
                // TODO ? provider url needs an extension
ie..."ldap://10.0.1.10:389/dc=ldap,dc=gruchala,dc=eu";);
                String provider_url = "ldap://localhost:10389";;
                
                // Set up the environment for creating the initial
context
                Hashtable<String, Object> env = new Hashtable<String,
Object>();
                env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.ldap.LdapCtxFactory");
                env.put(Context.PROVIDER_URL, provider_url);
        
env.put(Context.SECURITY_AUTHENTICATION,sec_authentication);
                env.put(Context.SECURITY_PRINCIPAL, sec_credentials);
// specify the username
                env.put(Context.SECURITY_CREDENTIALS, sec_credentials);
// specify the password
                try {
                        ctx = new InitialDirContext(env);
                        System.out.println(ctx.lookup("cn=admin"));

                } catch (NamingException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                        //   "LDAP: error code 34 Trying to import users
from the ldap import 
                        // gives the error "LDAP: error code 34" Error
code 34 means the dn syntax 
                        // in the ldap url is invalid. Consult your ldap
documentation or ldap administrator 
                        // for the correct dn syntax." 

                        System.err.println("Error exiting...2");
                        return;
                }
                

                // ... do something useful with ctx
                System.out.println("... do something useful with ctx");


                
        }
        

}

Lee

Reply via email to