directory-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Robert r. Sanders" <>
Subject Re: Client library
Date Tue, 02 Aug 2005 15:11:45 GMT
Its a little hard to find "from scratch", but JNDI has a lot to do w/ 
LDAP (look at the javax.naming.dir package).

Create a connection to the Apache Directory server (when its running on 

        Hashtable env = new Hashtable();

        env.put(Context.PROVIDER_URL, "ldap://localhost:389/ou=system");



        env.put(Context.SECURITY_PRINCIPAL, "uid=admin,ou=system");

        env.put(Context.SECURITY_CREDENTIALS, "secret");

        DirContext context = new InitialDirContext(env);

Add entries to a context:

    String name = "cn=User Two,ou=users";

    Attributes attrs = new BasicAttributes();

    attrs.put("dn", name + ",ou=system");

    attrs.put("cn", "Two User");

    attrs.put("givenName", "Two");

    attrs.put("sn", "User");

    attrs.put("uid", "user.two");

    attrs.put("mail", "");

    attrs.put("userPassword", "plaintext2");

    attrs.put("objectClass", "inetOrgPerson");

    attrs.put("objectClass", "top");


    context.createSubcontext(name, attrs);

There are some pretty decent tutorials under the JNDI trail on this.

Ugo Cei wrote:

> Hi,
> I'm looking for a good LDAP Java client library and I'd like to use 
> Apache stuff, if at all possible. Looking around on 
> I couldn't understand whether there is something 
> usable already, and couldn't find anything in the latest distributed 
> version (0.9 I think). My needs are quite basic: I just need to create 
> and update entries in an LDAP repository used for storing user 
> credentials. If something is available, I could invest some time 
> towards developing it further.
>     Thanks in Advance,
>         Ugo
> P.S.: I'm not subscribed to this list, so I would be grateful if you 
> could Cc: me in your replies. I will certainly subscribe if necessary.
    Robert r. Sanders
    Chief Technologist
    (334) 821-5412

View raw message