Developing A White Pages Service with LDAP and JNDI

Developing A White Pages Service with LDAP and JNDI

Adding Entries

Adding entries to the server is the first thing you should do. To add entries to slapd, you use ldapadd, which reads the content of an ldif file, checks the validity of its entries, and adds the entries to the server if the entries are correct.

To add entries to the LDAP server, you need to pass the domain name and the password for the root user. For example, with the following command you pass the domain name (sendal.jepit.edu.au) and the password (secret) and the example.ldif containing the entries to be added.

ldapadd -x -D "cn=Manager ,dc=sendal,dc=jepit,dc=edu,dc=au" -w secret -f example.ldif

The argument list of ldapadd can be displayed by typing ldapadd with no arguments.

LDAP Data Interchange Format (LDIF)

As mentioned above, the LDIF is used to represent LDAP entries in text form. The basic syntax of an LDIF entry is

. 

[<id>]

dn: <distinguished name>

<attrtype>: <attrvalue>

<attrtype>: <attrvalue>

...

where <id> is the optional entry ID (a positive decimal number). Normally, you would not supply the <id>, allowing the database creation tools to do that for you. A line may be continued by starting the next line with a single space or tab character, as in

dn: cn=Frank Dominic, o=University of Michigan, c=US 

Multiple attribute values are specified on separate lines.

cn: Frank Dominic 

cn: Frank B Dominic

If an <attrvalue> contains a non-printing character, or begins with a space or a colon (:), the <attrtype> is followed by a double colon and the value is encoded in base 64 notation. e.g., the value " begins with a space" would be encoded like this:

cn:: IGJlZ2lucyB3aXRoIGEgc3BhY2U= 

Blank lines separate multiple entries within the same LDIF file.

Here is an example of an LDIF file containing three entries.

dn: cn=Barbara J Jensen, o=University of Michigan, c=US

cn: Barbara J Jensen

cn: Babs Jensen

objectclass: person

sn: Jensen 

dn: cn=Bjorn J Jensen, o=University of Michigan, c=US

cn: Bjorn J Jensen

cn: Bjorn Jensen

objectclass: person

sn: Jensen 

dn: cn=Jennifer J Jensen, o=University of Michigan, c=US

cn: Jennifer J Jensen

cn: Jennifer Jensen

objectclass: person

sn: Jensen

jpegPhoto:: /9j/4AAQSkZJRgABAAAAAQABAAD/2wBDABALD 

A4MChAODQ4SERATGCgaGBYWGDEjJR0oOjM9PDkzODdASFxOQ 

ERXRTc4UG1RV19iZ2hnPk1xeXBkeFxlZ2P/2wBDARESEhgVG ... 

Notice that the jpegPhoto in Jennifer Jensen's entry is encoded in base 64.

Java Naming and Directory Interface (JNDI)

The JNDI is API for writing programs to access naming and directory services.

The JNDI is grouped into five packages.

  • javax.naming
  • javax.naming.directory
  • javax.naming.event
  • javax.naming.ldap
  • javax.naming.spi

For the project in this article you only need the javax.naming and javax.naming.directory packages.

JNDI is included in version 1.3 of Java 2 SDK. If you are using this version, you are in luck. For users of JDK 1.1 and Java 2 SDK version 1.2, the JNDI can be downloaded and installed separately. In the Java 2 SDK, version 1.3, you can find service providers for the following services:

  • LDAP
  • CORBA Common Object Service (COS) name service
  • Java Remote Method Invocation (RMI) Registry.

If you are using an older version of Java, you must first download the JNDI as a Standard Extension on the JDK 1.1 and Java 2 SDK, version 1.2.

You must also download one or more service providers. These service providers act like JDBC drivers for database access.

Prev  [1] [2] [3] [4] [5] [6] [7] Next

Close    To Top
  • Prev Article-Java:
  • Next Article-Java:
  • Now: Tutorial for Web and Software Design > Java > Java EE > Java Content
    Photoshop Tutorial
     

    Special Effect

      3D Effect
      Photoshop Articles
    Programming Tutorial
     

    C/C++ Tutorial

      Visual Basic
      C# Tutorial
    Database Tutorial
     

    MySQL Tutorial

      MS SQL Tutorial
      Oracle Tutorial
    Geek Tutorial
     

    Blogging Tutorial

      RSS Tutorial
      Podcasting Tutorial
    Graphic Design Tutorial
      Coreldraw Tutorial
      Illustrator Tutorial
      3D Tutorials
    Webmaster Articles
     

    Domain Service

      Web Hosting
      Site Promotion
    Java Tutorial/ Articles
     

    Java Servlets

      JavaEE Tutorial
     

    JavaBeans Tutorial

    XML Tutorial/ Articles
     

    XML Style

      AJAX Tutorial
      XML Mobile
    Flash Tutorial/ Articles
     

    Flash Video

      Action Script
      Flash Articles
    OS Tutorial/ Articles
      Linux Tutorial
      Symbian Tutorial
      MacOS Tutorial
    Personal Tech
      Hardware Tutorial
      Software Tutorial
      Online Auction