APIdia Launch Partner
Top Description Inners Fields Constructors Methods
com.sun.jndi.ldap

public final Class LdapCtx

extends ComponentDirContext
implements EventDirContext, LdapContext
Class Inheritance
All Implemented Interfaces
javax.naming.ldap.LdapContext, javax.naming.directory.DirContext, javax.naming.Context, javax.naming.event.EventDirContext, javax.naming.event.EventContext
Imports
javax.naming.*, javax.naming.directory.*, javax.naming.event.*, javax.naming.ldap.*, .LdapName, .Rdn, java.util.Arrays, .Collections, .Locale, .Set, .Vector, .Hashtable, .List, .StringTokenizer, .Enumeration, java.util.concurrent.locks.ReentrantLock, java.util.function.Predicate, java.util.stream.Collectors, java.io.IOException, .OutputStream, com.sun.jndi.toolkit.ctx.*, com.sun.jndi.toolkit.dir.HierMemDirCtx, .SearchFilter, com.sun.jndi.ldap.ext.StartTlsResponseImpl, com.sun.naming.internal.NamingManagerHelper, .ObjectFactoriesFilter

The LDAP context implementation. Implementation is not thread-safe. Caller must sync as per JNDI spec. Members that are used directly or indirectly by internal worker threads (Connection, EventQueue, NamingEventNotifier) must be thread-safe. Connection - calls LdapClient.processUnsolicited(), which in turn calls LdapCtx.convertControls() and LdapCtx.fireUnsolicited(). convertControls() - no sync; reads envprops and 'this' fireUnsolicited() - sync on eventSupport for all references to 'unsolicited' (even those in other methods); don't sync on LdapCtx in case caller is already sync'ing on it - this would prevent Unsol events from firing and the Connection thread to block (thus preventing any other data from being read from the connection) References to 'eventSupport' need not be sync'ed because these methods can only be called after eventSupport has been set first (via addNamingListener()). EventQueue - no direct or indirect calls to LdapCtx NamingEventNotifier - calls newInstance() to get instance for run() to use; no sync needed for methods invoked on new instance; LdapAttribute links to LdapCtx in order to process getAttributeDefinition() and getAttributeSyntaxDefinition() calls. It invokes LdapCtx.getSchema(), which uses schemaTrees (a Hashtable - already sync). Potential conflict of duplicating construction of tree for same subschemasubentry but no inconsistency problems. NamingEnumerations link to LdapCtx for the following: 1. increment/decrement enum count so that ctx doesn't close the underlying connection 2. LdapClient handle to get next batch of results 3. Sets LdapCtx's response controls 4. Process return code 5. For narrowing response controls (using ctx's factories) Since processing of NamingEnumeration by client is treated the same as method invocation on LdapCtx, caller is responsible for locking.
Authors
Vincent Ryan, Rosanna Lee

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class

Field Summary

Modifier and TypeField and Description
private char
private static final String
private static final String
private int
private static final String
private Hashtable<String, Boolean>
pack-priv static final String
private Control[]
pack-priv LdapClient
private boolean
private static final String
private int
pack-priv volatile boolean
pack-priv String
pack-priv Name
private static final boolean
private static final int
private static final boolean
private static final int
public static final String
private static final int
public static final int
private static final char
private static final int
private static final int
pack-priv static final String
public static final int
private static final boolean
private static final String
private boolean
private static final String
private int
private static final String
private static final HierMemDirCtx
private static final String
private int
pack-priv Hashtable<String, Object>
private EventSupport
pack-priv int
private static final boolean
pack-priv boolean
private int
pack-priv String
private final ReentrantLock
private static final Control
private static final Set<String>
private static final ControlFactory
private static final String
private boolean
private static final String
private boolean
private static final NameParser
pack-priv int
private static final String
private int
private static final String
private static final String
private int
private static final String
private int
pack-priv Control[]
pack-priv Vector<Control>
private static final String[]
private Hashtable<String, DirContext>
private boolean
private static final String
private static final boolean
private static final String
private OutputStream
private static final String
private static final String
private boolean
private static final String
private boolean
private String
private boolean
private boolean
private static final String
private static final String
private boolean

Constructor Summary

AccessConstructor and Description
public
LdapCtx(String dn, String host, int port_number, Hashtable<?, ?> props, boolean useSsl)

pack-priv
LdapCtx(LdapCtx existing, String newDN)

Method Summary

Modifier and TypeMethod and Description
private static Control[]
addControl(Control[] prevCtls, Control addition)

public void
addNamingListener(Name nm, int scope, NamingListener l)

Implements javax.naming.event.EventContext.addNamingListener.

Adds a listener for receiving naming events fired when the object(s) identified by a target and scope changes.

public void
addNamingListener(String nm, int scope, NamingListener l)

Implements javax.naming.event.EventContext.addNamingListener.

Adds a listener for receiving naming events fired when the object named by the string target name and scope changes.

public void
addNamingListener(String nm, String filter, SearchControls ctls, NamingListener l)

Implements javax.naming.event.EventDirContext.addNamingListener.

Adds a listener for receiving naming events fired when objects identified by the search filter filter at the object named by the string target name are modified.

public void
addNamingListener(Name nm, String filter, SearchControls ctls, NamingListener l)

Implements javax.naming.event.EventDirContext.addNamingListener.

Adds a listener for receiving naming events fired when objects identified by the search filter filter at the object named by target are modified.

public void
addNamingListener(Name nm, String filter, Object[] filterArgs, SearchControls ctls, NamingListener l)

Implements javax.naming.event.EventDirContext.addNamingListener.

Adds a listener for receiving naming events fired when objects identified by the search filter filter and filter arguments at the object named by the target are modified.

public void
addNamingListener(String nm, String filterExpr, Object[] filterArgs, SearchControls ctls, NamingListener l)

Implements javax.naming.event.EventDirContext.addNamingListener.

Adds a listener for receiving naming events fired when objects identified by the search filter filter and filter arguments at the object named by the string target name are modified.

private static Attributes

Returns:

Non-null attributes with attributes from the RDN added
addRdnAttributes
(String
The non-null DN of the entry to add
dn
,
Attributes
The non-null attributes of entry to add
attrs
,
boolean
Whether attrs can be updated directly
directUpdate
)

Adds attributes from RDN to attrs if not already present.

public Object
addToEnvironment(String propName, Object propVal)

Implements javax.naming.Context.addToEnvironment.

Adds a new environment property to the environment of this context.

private void
addUnsolicited()

Registers this context with the underlying LdapClient.

private void
private static <T> Vector<T>
appendVector(Vector<T> v1, Vector<T> v2)

private DirContext
buildSchemaTree(String subschemasubentry)

protected void
protected void
protected Context
protected DirContext
protected void
protected Attributes
protected NameParser
protected DirContext
protected DirContext
protected NamingEnumeration<NameClassPair>
protected NamingEnumeration<Binding>
protected Object
protected void
protected void
protected void
protected void
protected void
protected NamingEnumeration<SearchResult>
c_search(Name name, Attributes matchingAttributes, Continuation cont)

protected NamingEnumeration<SearchResult>
c_search(Name name, Attributes matchingAttributes, String[] attributesToReturn, Continuation cont)

Implements abstract com.sun.jndi.toolkit.ctx.ComponentDirContext.c_search.

protected NamingEnumeration<SearchResult>
protected NamingEnumeration<SearchResult>
c_search(Name name, String filterExpr, Object[] filterArgs, SearchControls cons, Continuation cont)

Implements abstract com.sun.jndi.toolkit.ctx.ComponentDirContext.c_search.

protected void
private static Control[]
private static SearchControls
public void
close()

Implements javax.naming.Context.close.

Closes this context.

private void
closeConnection(boolean hardclose)

private LdapResult
compare(Name name, String type, String value)

public Name
composeName(Name name, Name prefix)

Overrides com.sun.jndi.toolkit.ctx.PartialCompositeContext.composeName.

Implements javax.naming.Context.composeName.

Composes the name of this context with a name relative to this context.

private static String
concatNames(String lesser, String greater)

private void
connect(boolean startTLS)

private static boolean
pack-priv Control[]
convertControls(Vector<Control>
A non-null Vector
ctls
)

Narrow controls using own default factory and ControlFactory.

private static int
pack-priv void
private LdapResult
doSearch(Name name, String filter, SearchControls cons, boolean relative, boolean waitForReply)

private LdapResult
doSearchOnce(Name name, String filter, SearchControls cons, boolean relative)

private void
private void
private void
ensureOpen(boolean startTLS)

public ExtendedResponse
extendedOperation(ExtendedRequest request)

Implements javax.naming.ldap.LdapContext.extendedOperation.

Performs an extended operation.

private static Vector<Vector<String>>
extractURLs(String refString)

private static boolean
filterToAssertion(String filter, String[] tokens)

protected void
finalize()

Overrides java.lang.Object.finalize.

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.

private static int
findControl(Control[] ctls, Control target)

pack-priv void
fireUnsolicited(Object obj)

Uses EventSupport to fire an event related to an unsolicited notification.

private String
private String
public Control[]
getConnectControls()

Implements javax.naming.ldap.LdapContext.getConnectControls.

Retrieves the connection request controls in effect for this context.

public Hashtable<String, Object>
getEnvironment()

Implements javax.naming.Context.getEnvironment.

Retrieves the environment in effect for this context.

private static Set<String>
public String
getNameInNamespace()

Implements javax.naming.Context.getNameInNamespace.

Retrieves the full name of this context within its own namespace.

public Control[]
getRequestControls()

Implements javax.naming.ldap.LdapContext.getRequestControls.

Retrieves the request controls in effect for this context.

public Control[]
getResponseControls()

Implements javax.naming.ldap.LdapContext.getResponseControls.

Retrieves the response controls produced as a result of the last method invoked on this context.

private String
getSchemaEntry(Name name, boolean relative)

private DirContext
pack-priv LdapResult
private static String
getTargetName(Name
The non-null target name.
nm
)

Retrieves the target name for which the listener is registering.

pack-priv String
pack-priv void
private void
private boolean
public static NamingException

Returns:

A NamingException or null if the error code indicates success.
mapErrorCode
(int
numeric LDAP error code
errorCode
,
String
textual description of the LDAP error. May be null.
errorMessage
)

Maps an LDAP error code to an appropriate NamingException.

public LdapContext
newInstance(Control[] reqCtls)

Implements javax.naming.ldap.LdapContext.newInstance.

Creates a new instance of this context initialized using request controls.

protected Hashtable<String, Object>
protected void
pack-priv void
processReturnCode(LdapResult answer, Name remainName)

protected void
processReturnCode(LdapResult res, Name resolvedName, Object resolvedObj, Name remainName, Hashtable<?, ?> envprops, String fullDN)

public void
reconnect(Control[] connCtls)

Implements javax.naming.ldap.LdapContext.reconnect.

Reconnects to the LDAP server using the supplied controls and this context's environment.

private static Control[]
removeControl(Control[] prevCtls, Control target)

public Object
removeFromEnvironment(String propName)

Implements javax.naming.Context.removeFromEnvironment.

Removes an environment property from the environment of this context.

public void
removeNamingListener(NamingListener l)

Implements javax.naming.event.EventContext.removeNamingListener.

Removes a listener from receiving naming events fired by this EventContext.

private void
removeUnsolicited()

Removes this context from registering interest in unsolicited notifications from the underlying LdapClient.

pack-priv NamingEnumeration<SearchResult>
searchAux(Name name, String filter, SearchControls cons, boolean relative, boolean waitForReply, Continuation cont)

private static boolean
searchToCompare(String filter, SearchControls cons, String[] tokens)

private void
setBatchSize(String batchSizeProp)

Sets the batch size of this context;

private void
private void
setConnectTimeout(String connectTimeoutProp)

Sets the connect timeout value

private void
setDeleteRDN(String deleteRDNProp)

private void
setDerefAliases(String deref)

Set whether aliases are dereferenced during resolution and searches.

pack-priv void
setDomainName(String domainName)

Sets the domain name for the context in the com.sun.jndi.ldap.domainname property.

pack-priv void
setHopCount(int hopCount)

pack-priv void
setParents(Attributes attrs, Name name)

pack-priv void
setProviderUrl(String providerUrl)

Sets the URL that created the context in the java.naming.provider.url property.

private void
setReadTimeout(String readTimeoutProp)

Sets the read timeout value

private void
setReferralLimit(String referralLimitProp)

Sets the limit on referral chains

private void
setReferralMode(String ref, boolean update)

Sets the referral mode of this context to 'follow', 'throw' or 'ignore'.

private void
private void
setReplyQueueSize(String replyQueueSizeProp)

Sets the size of the queue of unprocessed search replies

public void
setRequestControls(Control[] reqCtls)

Implements javax.naming.ldap.LdapContext.setRequestControls.

Sets the request controls for methods subsequently invoked on this context.

private void
setTypesOnly(String typesOnlyProp)

private void
setWaitForReply(String waitForReplyProp)

Sets the flag that controls whether to block until the first search reply is received

public boolean
targetMustExist()

Implements javax.naming.event.EventContext.targetMustExist.

Determines whether a listener can register interest in a target that does not exist.

Inherited from com.sun.jndi.toolkit.ctx.ComponentDirContext:
c_bind_nnsc_createSubcontext_nnsc_getAttributes_nnsc_getSchema_nnsc_getSchemaClassDefinition_nnsc_modifyAttributes_nnsc_modifyAttributes_nnsc_rebind_nnsc_search_nnsc_search_nnsc_search_nnsp_bindp_createSubcontextp_getAttributesp_getSchemap_getSchemaClassDefinitionp_modifyAttributesp_modifyAttributesp_rebindp_searchp_searchp_search