LdapContext (Java SE 15 & JDK 15) (original) (raw)

All Superinterfaces:

[Context](../Context.html "interface in javax.naming"), [DirContext](../directory/DirContext.html "interface in javax.naming.directory")

All Known Implementing Classes:

[InitialLdapContext](InitialLdapContext.html "class in javax.naming.ldap")


public interface LdapContext extends DirContext

This interface represents a context in which you can perform operations with LDAPv3-style controls and perform LDAPv3-style extended operations. For applications that do not require such controls or extended operations, the more generic javax.naming.directory.DirContext should be used instead.

Usage Details About Controls

This interface provides support for LDAP v3 controls. At a high level, this support allows a user program to set request controls for LDAP operations that are executed in the course of the user program's invocation ofContext/DirContext methods, and read response controls resulting from LDAP operations. At the implementation level, there are some details that developers of both the user program and service providers need to understand in order to correctly use request and response controls.

Request Controls

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.

Unless explicitly qualified, the term "request controls" refers to context request controls.

Context Request Controls

There are two ways in which a context instance gets its request controls:

  1. ldapContext.newInstance(**reqCtls**)
  2. ldapContext.setRequestControls(**reqCtls**)

where ldapContext is an instance of LdapContext. Specifying null or an empty array for reqCtls means no request controls.newInstance() creates a new instance of a context usingreqCtls, while setRequestControls() updates an existing context instance's request controls to reqCtls.

Unlike environment properties, request controls of a context instance_are not inherited_ by context instances that are derived from it. Derived context instances have null as their context request controls. You must set the request controls of a derived context instance explicitly using setRequestControls().

A context instance's request controls are retrieved using the method getRequestControls().

Connection Request Controls

There are three ways in which connection request controls are set:

  1. new InitialLdapContext(env, **connCtls**)
  2. refException.getReferralContext(env, **connCtls**)
  3. ldapContext.reconnect(**connCtls**);

where refException is an instance ofLdapReferralException, and ldapContext is an instance of LdapContext. Specifying null or an empty array for connCtls means no connection request controls.

Like environment properties, connection request controls of a context_are inherited_ by contexts that are derived from it. Typically, you initialize the connection request controls using theInitialLdapContext constructor orLdapReferralContext.getReferralContext(). These connection request controls are inherited by contexts that share the same connection--that is, contexts derived from the initial or referral contexts.

Use reconnect() to change the connection request controls of a context. Invoking ldapContext.reconnect() affects only the connection used by ldapContext and any new contexts instances that are derived form ldapContext. Contexts that previously shared the connection with ldapContext remain unchanged. That is, a context's connection request controls must be explicitly changed and is not affected by changes to another context's connection request controls.

A context instance's connection request controls are retrieved using the method getConnectControls().

Service Provider Requirements

A service provider supports connection and context request controls in the following ways. Context request controls must be associated on a per context instance basis while connection request controls must be associated on a per connection instance basis. The service provider must look for the connection request controls in the environment property "java.naming.ldap.control.connect" and pass this environment property on to context instances that it creates.

Response Controls

The method LdapContext.getResponseControls() is used to retrieve the response controls generated by LDAP operations executed as the result of invoking a Context/DirContext operation. The result is all of the responses controls generated by the underlying LDAP operations, including any implicit reconnection. To get only the reconnection response controls, use reconnect() followed by getResponseControls().

Parameters

A Control[] array passed as a parameter to any method is owned by the caller. The service provider will not modify the array or keep a reference to it, although it may keep references to the individual Control objects in the array. A Control[] array returned by any method is immutable, and may not subsequently be modified by either the caller or the service provider.

Since:

1.3

See Also:

InitialLdapContext, LdapReferralException.getReferralContext(java.util.Hashtable,javax.naming.ldap.Control[])

Fields

Modifier and Type Field Description
static String CONTROL_FACTORIES Constant that holds the name of the environment property for specifying the list of control factories to use.

Fields declared in interface javax.naming.Context

[APPLET](../Context.html#APPLET), [AUTHORITATIVE](../Context.html#AUTHORITATIVE), [BATCHSIZE](../Context.html#BATCHSIZE), [DNS_URL](../Context.html#DNS%5FURL), [INITIAL_CONTEXT_FACTORY](../Context.html#INITIAL%5FCONTEXT%5FFACTORY), [LANGUAGE](../Context.html#LANGUAGE), [OBJECT_FACTORIES](../Context.html#OBJECT%5FFACTORIES), [PROVIDER_URL](../Context.html#PROVIDER%5FURL), [REFERRAL](../Context.html#REFERRAL), [SECURITY_AUTHENTICATION](../Context.html#SECURITY%5FAUTHENTICATION), [SECURITY_CREDENTIALS](../Context.html#SECURITY%5FCREDENTIALS), [SECURITY_PRINCIPAL](../Context.html#SECURITY%5FPRINCIPAL), [SECURITY_PROTOCOL](../Context.html#SECURITY%5FPROTOCOL), [STATE_FACTORIES](../Context.html#STATE%5FFACTORIES), [URL_PKG_PREFIXES](../Context.html#URL%5FPKG%5FPREFIXES)

Modifier and Type Method Description
ExtendedResponse extendedOperation​(ExtendedRequest request) Performs an extended operation.
Control[] getConnectControls() Retrieves the connection request controls in effect for this context.
Control[] getRequestControls() Retrieves the request controls in effect for this context.
Control[] getResponseControls() Retrieves the response controls produced as a result of the last method invoked on this context.
LdapContext newInstance​(Control[] requestControls) Creates a new instance of this context initialized using request controls.
void reconnect​(Control[] connCtls) Reconnects to the LDAP server using the supplied controls and this context's environment.
void setRequestControls​(Control[] requestControls) Sets the request controls for methods subsequently invoked on this context.

Methods declared in interface javax.naming.Context

[addToEnvironment](../Context.html#addToEnvironment%28java.lang.String,java.lang.Object%29), [bind](../Context.html#bind%28java.lang.String,java.lang.Object%29), [bind](../Context.html#bind%28javax.naming.Name,java.lang.Object%29), [close](../Context.html#close%28%29), [composeName](../Context.html#composeName%28java.lang.String,java.lang.String%29), [composeName](../Context.html#composeName%28javax.naming.Name,javax.naming.Name%29), [createSubcontext](../Context.html#createSubcontext%28java.lang.String%29), [createSubcontext](../Context.html#createSubcontext%28javax.naming.Name%29), [destroySubcontext](../Context.html#destroySubcontext%28java.lang.String%29), [destroySubcontext](../Context.html#destroySubcontext%28javax.naming.Name%29), [getEnvironment](../Context.html#getEnvironment%28%29), [getNameInNamespace](../Context.html#getNameInNamespace%28%29), [getNameParser](../Context.html#getNameParser%28java.lang.String%29), [getNameParser](../Context.html#getNameParser%28javax.naming.Name%29), [list](../Context.html#list%28java.lang.String%29), [list](../Context.html#list%28javax.naming.Name%29), [listBindings](../Context.html#listBindings%28java.lang.String%29), [listBindings](../Context.html#listBindings%28javax.naming.Name%29), [lookup](../Context.html#lookup%28java.lang.String%29), [lookup](../Context.html#lookup%28javax.naming.Name%29), [lookupLink](../Context.html#lookupLink%28java.lang.String%29), [lookupLink](../Context.html#lookupLink%28javax.naming.Name%29), [rebind](../Context.html#rebind%28java.lang.String,java.lang.Object%29), [rebind](../Context.html#rebind%28javax.naming.Name,java.lang.Object%29), [removeFromEnvironment](../Context.html#removeFromEnvironment%28java.lang.String%29), [rename](../Context.html#rename%28java.lang.String,java.lang.String%29), [rename](../Context.html#rename%28javax.naming.Name,javax.naming.Name%29), [unbind](../Context.html#unbind%28java.lang.String%29), [unbind](../Context.html#unbind%28javax.naming.Name%29)

Methods declared in interface javax.naming.directory.DirContext

[bind](../directory/DirContext.html#bind%28java.lang.String,java.lang.Object,javax.naming.directory.Attributes%29), [bind](../directory/DirContext.html#bind%28javax.naming.Name,java.lang.Object,javax.naming.directory.Attributes%29), [createSubcontext](../directory/DirContext.html#createSubcontext%28java.lang.String,javax.naming.directory.Attributes%29), [createSubcontext](../directory/DirContext.html#createSubcontext%28javax.naming.Name,javax.naming.directory.Attributes%29), [getAttributes](../directory/DirContext.html#getAttributes%28java.lang.String%29), [getAttributes](../directory/DirContext.html#getAttributes%28java.lang.String,java.lang.String%5B%5D%29), [getAttributes](../directory/DirContext.html#getAttributes%28javax.naming.Name%29), [getAttributes](../directory/DirContext.html#getAttributes%28javax.naming.Name,java.lang.String%5B%5D%29), [getSchema](../directory/DirContext.html#getSchema%28java.lang.String%29), [getSchema](../directory/DirContext.html#getSchema%28javax.naming.Name%29), [getSchemaClassDefinition](../directory/DirContext.html#getSchemaClassDefinition%28java.lang.String%29), [getSchemaClassDefinition](../directory/DirContext.html#getSchemaClassDefinition%28javax.naming.Name%29), [modifyAttributes](../directory/DirContext.html#modifyAttributes%28java.lang.String,int,javax.naming.directory.Attributes%29), [modifyAttributes](../directory/DirContext.html#modifyAttributes%28java.lang.String,javax.naming.directory.ModificationItem%5B%5D%29), [modifyAttributes](../directory/DirContext.html#modifyAttributes%28javax.naming.Name,int,javax.naming.directory.Attributes%29), [modifyAttributes](../directory/DirContext.html#modifyAttributes%28javax.naming.Name,javax.naming.directory.ModificationItem%5B%5D%29), [rebind](../directory/DirContext.html#rebind%28java.lang.String,java.lang.Object,javax.naming.directory.Attributes%29), [rebind](../directory/DirContext.html#rebind%28javax.naming.Name,java.lang.Object,javax.naming.directory.Attributes%29), [search](../directory/DirContext.html#search%28java.lang.String,java.lang.String,java.lang.Object%5B%5D,javax.naming.directory.SearchControls%29), [search](../directory/DirContext.html#search%28java.lang.String,java.lang.String,javax.naming.directory.SearchControls%29), [search](../directory/DirContext.html#search%28java.lang.String,javax.naming.directory.Attributes%29), [search](../directory/DirContext.html#search%28java.lang.String,javax.naming.directory.Attributes,java.lang.String%5B%5D%29), [search](../directory/DirContext.html#search%28javax.naming.Name,java.lang.String,java.lang.Object%5B%5D,javax.naming.directory.SearchControls%29), [search](../directory/DirContext.html#search%28javax.naming.Name,java.lang.String,javax.naming.directory.SearchControls%29), [search](../directory/DirContext.html#search%28javax.naming.Name,javax.naming.directory.Attributes%29), [search](../directory/DirContext.html#search%28javax.naming.Name,javax.naming.directory.Attributes,java.lang.String%5B%5D%29)