gnu.inet.ldap
Class LDAPConnection

java.lang.Object
  extended by gnu.inet.ldap.LDAPConnection

public class LDAPConnection
extends java.lang.Object

An LDAPv3 client. This client is still experimental, please contact Chris Burdess if you want to help out with it.


Field Summary
static int DEFAULT_PORT
          The default LDAP port.
static int DEREF_ALWAYS
          Dereference aliases both in searching and in locating the base object of the search.
static int DEREF_FINDING_BASE_OBJ
          Dereference aliases in locating the base object of the search, but not when searching subordinates of the base object.
static int DEREF_IN_SEARCHING
          Dereference aliases in subordinates of the base object in searching, but not in locating the base object of the search.
static int DEREF_NEVER
          Do not dereference aliases in searching or in locating the base object of the search.
protected  java.lang.String host
           
protected  int port
           
static int SCOPE_BASE_OBJECT
           
static int SCOPE_SINGLE_LEVEL
           
static int SCOPE_WHOLE_SUBTREE
           
protected  int version
           
 
Constructor Summary
LDAPConnection(java.lang.String host)
          Creates a new LDAP connection to the specified host, using the default LDAP port.
LDAPConnection(java.lang.String host, int port)
          Creates a new LDAP connection to the specified host and port.
LDAPConnection(java.lang.String host, int port, int connectionTimeout, int timeout)
          Creates a new LDAP connection to the specified host, port, and timeouts.
 
Method Summary
 LDAPResult add(java.lang.String name, AttributeValues[] attributes)
          Requests the addition of a new entry into the directory.
 LDAPResult bind(java.lang.String name, java.lang.String mechanism, byte[] credentials, javax.naming.ldap.Control[] controls)
          Initiates a bind operation to authenticate the client to the server.
 LDAPResult delete(java.lang.String name)
          Requests the removal of an entry from the directory.
 LDAPResult modify(java.lang.String name, Modification[] modifications)
          Issues a modify request.
 LDAPResult modifyDN(java.lang.String name, java.lang.String newRDN, boolean deleteOldRDN, java.lang.String newSuperior)
          Changes the leftmost(least significant) component of the name of an entry in the directory, or move a subtree of entries to a new location in the directory.
 LDAPResult search(java.lang.String name, int scope, int derefAliases, int sizeLimit, int timeLimit, boolean typesOnly, java.lang.String filter, java.lang.String[] attributes, javax.naming.ldap.Control[] controls, ResultHandler handler)
          Issues a search request.
 void setVersion(int version)
          Sets the version of LDAP to use.
 void unbind()
          Issues an unbind request.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_PORT

public static final int DEFAULT_PORT
The default LDAP port.

See Also:
Constant Field Values

SCOPE_BASE_OBJECT

public static final int SCOPE_BASE_OBJECT
See Also:
Constant Field Values

SCOPE_SINGLE_LEVEL

public static final int SCOPE_SINGLE_LEVEL
See Also:
Constant Field Values

SCOPE_WHOLE_SUBTREE

public static final int SCOPE_WHOLE_SUBTREE
See Also:
Constant Field Values

DEREF_NEVER

public static final int DEREF_NEVER
Do not dereference aliases in searching or in locating the base object of the search.

See Also:
Constant Field Values

DEREF_IN_SEARCHING

public static final int DEREF_IN_SEARCHING
Dereference aliases in subordinates of the base object in searching, but not in locating the base object of the search.

See Also:
Constant Field Values

DEREF_FINDING_BASE_OBJ

public static final int DEREF_FINDING_BASE_OBJ
Dereference aliases in locating the base object of the search, but not when searching subordinates of the base object.

See Also:
Constant Field Values

DEREF_ALWAYS

public static final int DEREF_ALWAYS
Dereference aliases both in searching and in locating the base object of the search.

See Also:
Constant Field Values

host

protected java.lang.String host

port

protected int port

version

protected int version
Constructor Detail

LDAPConnection

public LDAPConnection(java.lang.String host)
               throws java.io.IOException
Creates a new LDAP connection to the specified host, using the default LDAP port.

Parameters:
host - the host
Throws:
java.io.IOException

LDAPConnection

public LDAPConnection(java.lang.String host,
                      int port)
               throws java.io.IOException
Creates a new LDAP connection to the specified host and port.

Parameters:
host - the host
port - the port
Throws:
java.io.IOException

LDAPConnection

public LDAPConnection(java.lang.String host,
                      int port,
                      int connectionTimeout,
                      int timeout)
               throws java.io.IOException
Creates a new LDAP connection to the specified host, port, and timeouts.

Parameters:
host - the host
port - the port
connectionTimeout - the connection timeout in ms
timeout - the socket I/O timeout in ms
Throws:
java.io.IOException
Method Detail

setVersion

public void setVersion(int version)
Sets the version of LDAP to use. This implementation supports versions 2 and 3.

Parameters:
version - the LDAP version

bind

public LDAPResult bind(java.lang.String name,
                       java.lang.String mechanism,
                       byte[] credentials,
                       javax.naming.ldap.Control[] controls)
                throws java.io.IOException
Initiates a bind operation to authenticate the client to the server.

Parameters:
name - the LDAP DN to authenticate to, or null for anonymous binding
mechanism - the SASL mechanism to use, or null for simple authentication
credentials - the security credentials to use
Returns:
the LDAP result
Throws:
java.io.IOException

unbind

public void unbind()
            throws java.io.IOException
Issues an unbind request. This indicates to the server that the client has no more requests to issue and will terminate the connection. After invoking this method, no further methods may be invoked.

Throws:
java.io.IOException

search

public LDAPResult search(java.lang.String name,
                         int scope,
                         int derefAliases,
                         int sizeLimit,
                         int timeLimit,
                         boolean typesOnly,
                         java.lang.String filter,
                         java.lang.String[] attributes,
                         javax.naming.ldap.Control[] controls,
                         ResultHandler handler)
                  throws java.io.IOException
Issues a search request.

Parameters:
name - the LDAP DN that is the base object entry relative to which the search is to be performed
scope - the search scope, one of the SCOPE_* constants
derefAliases - whether to dereference aliases, one of the DEREF_* constants
sizeLimit - the maximum number of entries to return, or 0 for no restriction
timeLimit - the maximum time in seconds permitted for the search, or 0 for no restriction
typesOnly - whether to return only attribute types(true) or both attribute types and values(false)
filter - the search filter in RFC2254 format
attributes - the IDs of the attributes to return
controls - the request controls
handler - the result handler to receive notification of results
Returns:
the LDAP result
Throws:
java.io.IOException

modify

public LDAPResult modify(java.lang.String name,
                         Modification[] modifications)
                  throws java.io.IOException
Issues a modify request.

Parameters:
name - the LDAP DN of the object to be modified(alias dereferencing will not be performed)
modifications - a sequence of modifications to be executed to be executed
Throws:
java.io.IOException
See Also:
Modification

add

public LDAPResult add(java.lang.String name,
                      AttributeValues[] attributes)
               throws java.io.IOException
Requests the addition of a new entry into the directory.

Parameters:
name - the LDAP DN of the new entry
attributes - a sequence of attributes to assign to the new entry
Throws:
java.io.IOException

delete

public LDAPResult delete(java.lang.String name)
                  throws java.io.IOException
Requests the removal of an entry from the directory.

Parameters:
name - the LDAP DN of the entry to remove
Throws:
java.io.IOException

modifyDN

public LDAPResult modifyDN(java.lang.String name,
                           java.lang.String newRDN,
                           boolean deleteOldRDN,
                           java.lang.String newSuperior)
                    throws java.io.IOException
Changes the leftmost(least significant) component of the name of an entry in the directory, or move a subtree of entries to a new location in the directory.

Parameters:
name - the LDAP DN of the entry to be changed
newRDN - the RDN that will form the leftmost component of the new name of the entry
deleteOldRDN - if false, the old RDN values will be retained as attributes of the entry, otherwise they are deleted from the entry
newSuperior - if non-null, the DN of the entry to become the immediate superior of the existing entry
Throws:
java.io.IOException