![]() ![]() ![]() ![]() |
Controls and Extensions |
A request control is sent by a client to modify or augment an LDAP operation. You can use a control to send more information to the server than is allowed by the operation's request, or to modify the behavior of the operation altogether.There are two types of request controls:
The former is used whenever a connection needs to be established or re-established with an LDAP server. The latter is used when all other LDAP operations are sent to the LDAP server. The reason why a distinction between these two types of request controls is necessary is because JNDI is a high-level API that does not deal directly with connections. It is the job of service providers to do any necessary connection management. Consequently, a single connection may be shared by multiple context instances, and a service provider is free to use its own algorithms to conserve connection and network usage. Thus, when a method is invoked on the context instance, the service provider might need to do some connection management in addition to performing the corresponding LDAP operations. For connection management, it uses the connection request controls, while for the normal LDAP operations, it uses the context request controls.
- Request controls that affect how a connection is created
- Request controls that affect context methods
Unless explicitly qualified, we use the term "request controls" to mean context request controls.
Controls Supported by LDAP Servers
Support for specific controls is LDAP server-dependent. Eventually, when controls are standardized, there might be a set of popular controls supported by most LDAP servers. However, there still might be controls that are proprietory and vendor-specific.Here is a simple program for finding out the list of controls that an LDAP server supports:
Here is the output produced by running this program against an LDAP server:// Create initial context DirContext ctx = new InitialDirContext(); // Read supportedcontrol from root DSE Attributes attrs = ctx.getAttributes( "ldap://localhost:389", new String[]{"supportedcontrol"});{supportedcontrol=supportedcontrol: 2.16.840.1.113730.3.4.2, 2.16.840.1.113730.3.4.3, 2.16.840.1.113730.3.4.4, 2.16.840.1.113730.3.4.5, 1.2.840.113556.1.4.473, 2.16.840.1.113730.3.4.9, 2.16.840.1.113730.3.4.12 }Implementations
The Controlinterface is generic for all request and response controls. Typically, you would be dealing implementation classes that implement this interface rather than directly using the methods in this interface. Such implementation classes typically have type-friendly constructors and accessor methods. For example, Sun provides classes that implement some popular controls, such as the Paged Results control, which allows you to retrieve the results of an LDAP "search" operation in pages. To create a Paged Results control, you use its constructor, PagedResultsControl, as follows:
In the next few pages, you will see other examples of how to construct and use controls.// Specify a page size of 20 Control prctl = new PagedResultsControl(20);
![]() ![]() ![]() ![]() |
Controls and Extensions |