Complete Contents
Preface
Chapter 1 Understanding LDAP
Chapter 2 Using the Netscape Directory SDK for Java
Chapter 3 Quick Start
Chapter 4 Writing an LDAP Client
Chapter 5 Using the LDAP Java Classes
Chapter 6 Searching the Directory
Chapter 7 Using Filter Configuration Files
Chapter 8 Adding, Updating, and Deleting Entries
Chapter 9 Comparing Values in Entries
Chapter 10 Working with LDAP URLs
Chapter 11 Getting Server Information
Chapter 12 Connecting Over SSL
Chapter 13 Working with LDAP Controls
Chapter 14 Using SASL Authentication
Chapter 15 Using Netscape's JNDI Service Provider
Chapter 16 Working with Extended Operations
Chapter 17 Using the Asynchronous Interface
Glossary
Directory SDK for Java 4.0 Programmer's Guide: Using the Netscape Directory SDK for
Previous Next Contents Index


Chapter 2 Using the Netscape Directory SDK for Java

This chapter describes the Lightweight Directory Access Protocol (LDAP) Java classes and the Netscape Directory SDK for Java.

The chapter contains the following sections:


Understanding the LDAP Java Classes
The Netscape Directory SDK for Java includes the LDAP Java classes, which you use to build LDAP clients. The LDAP Java classes allow you to write applets and applications that can connect to LDAP servers and perform standard LDAP operations (for example, you can search for entries or add, update, or delete entries).

The classes are organized in the following packages:

Typically, clients execute the methods in the Netscape Directory SDK for Java synchronously. All LDAP operations block until they are completed (with the exception of the search method, which can return information before all the results have been received).

An asynchronous interface is also provided for circumstances requiring low-level interaction with an LDAP server. The asynchronous interface is discussed more fully in Chapter 17, "Using the Asynchronous Interface."

Subsequent chapters in this manual explain how to use these LDAP Java classes.


Getting Started with the Netscape Directory SDK for Java
This section covers the following topics:

Getting and Installing the SDK
You can get the Netscape Directory SDK for Java from Netscape's DevEdge web site at the following location:

http://developer.netscape.com/tech/directory/index.html

The SDK is available as a GNU-zipped tar file for UNIX, a self-extracting executable for Windows, and a StuffIt archive for the Macintosh.

To install the SDK:

Download the appropriate file for your operating system

Expand the file (it contains a number of subdirectories).

Exploring the SDK
The Netscape Directory SDK for Java contains the following directories:

Preparing to Use the SDK
Before compiling any applets or applications, make sure to add the following to your CLASSPATH environment variable:

Writing Applets with the SDK
In Netscape Communicator, an applet can connect to servers on hosts other than the host that served the applet. This capability is part of the new signed applet security framework.

To take advantage of this capability, your applet class (the class making an LDAP connection) must be signed. Your applet class needs to request certain special rights before connecting to other servers.

The rest of this section summarizes the steps that you need to take to enable your applet to connect to other LDAP servers.

  1. Get a certificate from your organization's certificate authority (if your organization issues certificates internally) or from a third-party certificate authority, such as RSA, Verisign, or ATT.

  1. Create a JAR file with your classes and have them signed.

  1. Add the following line to your applet code in the thread where you invoke LDAPConnection.connect:
  2.    PrivilegeManager.enablePrivilege("UniversalConnect"); 
    
If you want to test the ability for your applet to connect to other hosts (other than the originating one) without using object signing and certificates (for example, in case you want to test your applet while waiting for your certificate to be issued), you can configure Netscape Communicator to bypass this check.

First, exit Communicator (or make sure that it is not running). Then, add the following line to the prefs.js file:

user_pref("signed.applets.codebase_principal_support", true); 
Checking the Version of Classes from an Applet
Netscape Communicator 4.0 and more recent versions include a copy of the LDAP Java classes. Different versions of Communicator have different versions of the classes.

The following table lists some of the different versions of the classes that have been released up to this point in time.

Table 2.1 Recently released versions of the LDAP Java classes
Version
Description
3.03
Released with the Netscape Directory SDK for Java 3.0
3.1
Released with the Netscape Directory SDK for Java 3.1.
4.0
Available at:
http://developer.netscape.com/software/ldap/

Version 3.03 and beyond of the LDAP Java classes include new classes such as LDAPCache and LDAPSchema. If you plan to use these classes in an applet, make sure to check the version of the LDAP Java classes available in the browser.

To get the version number, invoke the LDAPConnection.getProperty method and pass in the constant LDAPConnection.LDAP_PROPERTY_SDK. The version number is a Float type. For example:

...
Float sdkVersion = ( Float )myConn.getProperty( myConn.LDAP_PROPERTY_SDK );
System.out.println( "LDAP Java Classes version: " + sdkVersion );
...
For information on the differences between the LDAP Java classes in this release and in previous releases, see the release notes at:

http://developer.netscape.com/tech/directory/index.html?content=java40relnotes.html

Working with the LDAP JavaBeans
The Netscape Directory SDK for Java includes a set of LDAP JavaBeans that you can use in a design environment, such as Sun Microsystems' BeanBox or Symantec's Visual Cafe.

These Beans are part of the netscape.ldap.beans package. The class files are located in the beans directory.

The following JavaBeans are included with the SDK:

The netscape.ldap.beans package also includes the following classes:

Before you use the Beans in a design environment, make sure to set your CLASSPATH environment variable to include the LDAP Java classes. For example:

set CLASSPATH=classes;D:\netscape\ldapjdk\packages\ldapjdk.jar

CLASSPATH=.;...<other_paths>;
D:\NETSCAPE\LDAPJDK\PACKAGES\LDAPJDK.JAR

Next, set up your design environment to include the JAR files under the beans directory of the Netscape Directory SDK for Java. For example:

Note that the LDAP JavaBeans are not visible Beans; they are not UI components.

The Beans have a Debug property that you can set to specify that you want debugging information printed out. This information is printed to standard output, so if you are testing the applet in BeanBox or in appletviewer, debug messages are printed out to the console or shell window.

Using the Classes in JavaScript
Using Netscape Communicator's LiveConnect capabilities, you can use the LDAP Java classes from within JavaScript code in an HTML page. (LiveConnect enables communication between JavaScript and Java applets in a page and between JavaScript and plug-ins loaded on a page.)

To see an example of how you can do this, see the sample JavaScript code in the HTML file in the examples/js directory. For information on LiveConnect, see the chapter on LiveConnect in the Netscape JavaScript Guide (available at http://developer.netscape.com/docs/manuals/js/client/jsguide/index.htm) and Netscape Tech Note TN-JSCR-03-9707 (available at http://developer.netscape.com/docs/technote/javascript/liveconnect/liveconnect_rh.html).

 

© Copyright 1999 Netscape Communications Corporation. All rights reserved.