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: Working with Extended Operations
Previous Next Contents Index


Chapter 16 Working with Extended Operations

This chapter explains how LDAP v3 extended operations work and how to use the extended operations that are supported by your LDAP server.

The chapter includes the following sections:


How Extended Operations Work
Extended operations are part of the LDAP v3 protocol. Each extended operation is identified by an OID.

LDAP clients can request the operation by sending an extended operation request. Within the request, the client specifies:

The server receives the request, and performs the extended operation. The server can send back to the client a response containing:

In order to use extended operations, both the server and the client must understand the specific extended operation to be performed.

The rest of this chapter describes how to set these up.


Implementing Support for Extended Operations on the Server
If you are running your own Netscape Directory Server 3.0 or later, you can write your own server plug-in that handles extended operations.

You can write an extended operation plug-in that:

For more information, see the Netscape Directory Server Plug-In Programmer's Guide.


Determining the Extended Operations Supported
To determine the extended operations supported by the server, get the root DSE of the server, and check the supportedExtension attribute. The values of this attribute are the object identifiers (OIDs) of the extended operations supported by this server.

If the root DSE does not have a supportedExtension attribute, the server does not support any extended operations.

For information on getting the root DSE, see "Getting the Root DSE".


Performing an Extended Operation
To perform an extended operation, do the following:

  1. Construct a new LDAPExtendedOperation object, specifying the OID of the extended operation and the data that you want applied to the operation.
  2. Invoke the extendedOperation method of the LDAPConnection object, passing it the newly constructed LDAPExtendedOperation object.
The LDAPExtendedOperation object that this method returns represents the server's response. You can invoke the getID and getValue methods of this object to get the OID and the data from the server's response.


Example: Extended Operation
The following program is an example of an LDAP client that request an extended operation with the OID 1.2.3.4 from the server.

...
import netscape.ldap.*;
import java.util.*;
import java.io.*;
...
public class ReqExtOp {
   public static void main( String[] args ) {
      LDAPConnection ld = null;
      int status = -1;
      try {
         ld = new LDAPConnection();

         /* Connect to server */
         String MY_HOST = "localhost";
         int MY_PORT = LDAPv2.DEFAULT_PORT;
         ld.connect( MY_HOST, MY_PORT );
         System.out.println( "Connected to server." );

         /* Authenticate to the server as directory manager */
         String MGR_DN = "cn=Directory Manager";
         String MGR_PW = "23skidoo";
         if ( ld.LDAP_VERSION < 3 ) {
            ld.authenticate( 3, MGR_DN, MGR_PW );
         } else {
            System.out.println( "Specified LDAP server does not " +
               "support v3 of the LDAP protocol." );
            ld.disconnect();
            System.exit(1);
         }
         System.out.println( "Authenticated to directory." );

         /* Create an extended operation object */
         String myval = "My Value";
         byte vals[] = myval.getBytes( "UTF8" );
         LDAPExtendedOperation exop =
            new LDAPExtendedOperation("1.2.3.4", vals );
         System.out.println( "Created LDAPExtendedOperation object." );

         /* Request the extended operation from the server. */
         LDAPExtendedOperation exres = ld.extendedOperation( exop );
         System.out.println( "Performed extended operation." );

         /* Get data from the response sent by the server. */
         System.out.println( "OID: " + exres.getID() );
         String retValue = new String( exres.getValue(), "UTF8" );
         System.out.println( "Value: " + retValue );
      }
      catch( LDAPException e ) {
         System.out.println( "Error: " + e.toString() );
      }
      catch( UnsupportedEncodingException e ) {
         System.out.println( "Error: UTF8 not supported" );
      }

      /* Done, so disconnect */
      if ( (ld != null) && ld.isConnected() ) {
         try {
            ld.disconnect();
         } catch ( LDAPException e ) {
            System.out.println( "Error: " + e.toString() );
         }
      }
      System.exit(status);
   }
}
...

 

© Copyright 1999 Netscape Communications Corporation. All rights reserved.