|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--netscape.ldap.LDAPConnection
Represents a connection to an LDAP server.
Use objects of this class to perform LDAP operations (such as search, modify, and add) on an LDAP server.
To perform an LDAP operation on a server, you need to follow these steps:
LDAPConnection
object.
connect
method to connect to the
LDAP server.
authenticate
method to authenticate
to server.
disconnect
method to disconnect from
the server when done.
All operations block until completion (with the exception of the search method in which the results may not all return at the same time).
This class also specifies a default set of constraints
(such as the maximum length of time to allow for an operation before timing out)
which apply to all operations. To get and set these constraints,
use the getOption
and setOption
methods.
To override these constraints for an individual operation,
define a new set of constraints by creating a LDAPConstraints
object and pass the object to the method for the operation. For search
operations, additional constraints are defined in LDAPSearchConstraints
(a subclass of LDAPConstraints
). To override the default search
constraints, create an LDAPSearchConstraints
object and pass it
to the search
method.
If you set up your client to follow referrals automatically,
an operation that results in a referral will create a new connection
to the LDAP server identified in the referral. In order to have
your client authenticate to that LDAP server automatically, you need
to define a class that implements the LDAPRebind
interface.
In your definition of the class, you need to define a
getRebindAuthentication
method that creates an LDAPRebindAuth
object containing the distinguished name and password to use for reauthentication.
Most errors that occur raise the same exception (LDAPException
).
In order to determine the exact problem that occurred, you can retrieve the
result code from this exception and compare its value against a set of defined
result codes.
LDAPConstraints
,
LDAPSearchConstraints
,
LDAPRebind
,
LDAPRebindAuth
,
LDAPException
Field Summary | |
static java.lang.String |
LDAP_PROPERTY_PROTOCOL
Name of the property specifying the highest supported version of the LDAP protocol. |
static java.lang.String |
LDAP_PROPERTY_SDK
Name of the property specifying the version of the SDK. |
static java.lang.String |
LDAP_PROPERTY_SECURITY
Name of the property specifying the types of authentication allowed by this API (for example, anonymous authentication and simple authentication). |
static int |
LDAP_VERSION
Version of the LDAP protocol used by default. |
static int |
MAXBACKLOG
Option specifying the maximum number of unread entries to be cached in any LDAPSearchResults without suspending reading from the server. |
static int |
NODELAY_PARALLEL
Specifies the parallel connection setup policy with no delay when a list of hosts is passed to the connect method. |
static int |
NODELAY_SERIAL
Specifies the serial connection setup policy when a list of hosts is passed to the connect method. |
static java.lang.String |
TRACE_PROPERTY
Name of the property to enable/disable LDAP message trace. |
Fields inherited from interface netscape.ldap.LDAPv3 |
ALL_USER_ATTRS,
CLIENTCONTROLS,
NO_ATTRS,
SERVERCONTROLS |
Fields inherited from interface netscape.ldap.LDAPv2 |
BATCHSIZE,
BIND,
DEFAULT_PORT,
DEREF,
DEREF_ALWAYS,
DEREF_FINDING,
DEREF_NEVER,
DEREF_SEARCHING,
PROTOCOL_VERSION,
REFERRALS,
REFERRALS_HOP_LIMIT,
REFERRALS_REBIND_PROC,
SCOPE_BASE,
SCOPE_ONE,
SCOPE_SUB,
SERVER_TIMELIMIT,
SIZELIMIT,
TIMELIMIT |
Constructor Summary | |
LDAPConnection()
Constructs a new LDAPConnection object,
which represents a connection to an LDAP server. |
|
LDAPConnection(LDAPSocketFactory factory)
Constructs a new LDAPConnection object that
will use the specified socket factory class to create
socket connections. |
Method Summary | |
void |
abandon(int id)
Cancels the ldap request with the specified id and discards any results already received. |
void |
abandon(LDAPSearchListener searchlistener)
Cancels all outstanding search requests associated with this LDAPSearchListener object and discards any results already received. |
void |
abandon(LDAPSearchResults searchResults)
Abandons a current search operation, notifying the server not to send additional search results. |
void |
add(LDAPEntry entry)
Adds an entry to the directory. |
void |
add(LDAPEntry entry,
LDAPConstraints cons)
Adds an entry to the directory and allows you to specify preferences for this LDAP add operation by using an LDAPConstraints object. |
LDAPResponseListener |
add(LDAPEntry entry,
LDAPResponseListener listener)
Adds an entry to the directory. |
LDAPResponseListener |
add(LDAPEntry entry,
LDAPResponseListener listener,
LDAPConstraints cons)
Adds an entry to the directory and allows you to specify constraints for this LDAP add operation by using an LDAPConstraints
object. |
void |
add(LDAPEntry entry,
LDAPSearchConstraints cons)
Deprecated. Please use the method signature where cons is
LDAPConstraints instead of LDAPSearchConstraints |
void |
authenticate(int version,
java.lang.String dn,
java.lang.String passwd)
Authenticates to the LDAP server (that you are currently connected to) using the specified name and password, and requesting that the server use at least the specified protocol version. |
void |
authenticate(int version,
java.lang.String dn,
java.lang.String passwd,
LDAPConstraints cons)
Authenticates to the LDAP server (to which you are currently connected) using the specified name and password, and requesting that the server use at least the specified protocol version. |
LDAPResponseListener |
authenticate(int version,
java.lang.String dn,
java.lang.String passwd,
LDAPResponseListener listener)
Authenticates to the LDAP server (that the object is currently connected to) using the specified name and password and allows you to specify constraints for this LDAP add operation by using an LDAPConstraints object. |
LDAPResponseListener |
authenticate(int version,
java.lang.String dn,
java.lang.String passwd,
LDAPResponseListener listener,
LDAPConstraints cons)
Authenticates to the LDAP server (that the object is currently connected to) using the specified name and password and allows you to specify constraints for this LDAP add operation by using an LDAPConstraints object. |
void |
authenticate(int version,
java.lang.String dn,
java.lang.String passwd,
LDAPSearchConstraints cons)
Deprecated. Please use the method signature where cons is
LDAPConstraints instead of LDAPSearchConstraints |
void |
authenticate(java.lang.String dn,
java.util.Hashtable props,
java.lang.Object cbh)
Authenticates to the LDAP server (that the object is currently connected to) using the specified name and whatever SASL mechanisms are supported by the server. |
void |
authenticate(java.lang.String dn,
java.lang.String passwd)
Authenticates to the LDAP server (to which you are currently connected) using the specified name and password. |
void |
authenticate(java.lang.String dn,
java.lang.String[] mechanisms,
java.util.Hashtable props,
java.lang.Object cbh)
Authenticates to the LDAP server (to which the object is currently connected) using the specified name and a specified SASL mechanism or set of mechanisms. |
void |
authenticate(java.lang.String dn,
java.lang.String[] mechanisms,
java.lang.String packageName,
java.util.Hashtable props,
java.lang.Object cbh)
Deprecated. Please use authenticate without packageName instead. |
void |
authenticate(java.lang.String dn,
java.lang.String passwd,
LDAPConstraints cons)
Authenticates to the LDAP server (to which you are currently connected) using the specified name and password. |
void |
authenticate(java.lang.String dn,
java.lang.String passwd,
LDAPSearchConstraints cons)
Deprecated. Please use the method signature where cons is
LDAPConstraints instead of LDAPSearchConstraints |
void |
authenticate(java.lang.String dn,
java.lang.String mechanism,
java.lang.String packageName,
java.util.Hashtable props,
java.lang.Object cbh)
Deprecated. Please use authenticate without packageName instead. |
void |
bind(int version,
java.lang.String dn,
java.lang.String passwd)
Authenticates to the LDAP server (to which you are currently connected) using the specified name and password, and requests that the server use at least the specified protocol version. |
void |
bind(int version,
java.lang.String dn,
java.lang.String passwd,
LDAPConstraints cons)
Authenticates to the LDAP server (to which you are currently connected) using the specified name and password, and requesting that the server use at least the specified protocol version. |
LDAPResponseListener |
bind(int version,
java.lang.String dn,
java.lang.String passwd,
LDAPResponseListener listener)
Authenticates to the LDAP server (to which the object is currently connected) using the specified name and password. |
LDAPResponseListener |
bind(int version,
java.lang.String dn,
java.lang.String passwd,
LDAPResponseListener listener,
LDAPConstraints cons)
Authenticates to the LDAP server (to which the object is currently connected) using the specified name and password and allows you to specify constraints for this LDAP add operation by using an LDAPConstraints object. |
void |
bind(java.lang.String dn,
java.util.Hashtable props,
java.lang.Object cbh)
Authenticates to the LDAP server (to which the object is currently connected) using the specified name and whatever SASL mechanisms are supported by the server. |
void |
bind(java.lang.String dn,
java.lang.String passwd)
Authenticates to the LDAP server (to which you are currently connected) using the specified name and password. |
void |
bind(java.lang.String dn,
java.lang.String[] mechanisms,
java.util.Hashtable props,
java.lang.Object cbh)
Authenticates to the LDAP server (to which the object is currently connected) using the specified name and a specified SASL mechanism or set of mechanisms. |
void |
bind(java.lang.String dn,
java.lang.String passwd,
LDAPConstraints cons)
Authenticates to the LDAP server (to which you are currently connected) using the specified name and password. |
LDAPResponseListener |
bind(java.lang.String dn,
java.lang.String passwd,
LDAPResponseListener listener)
Authenticates to the LDAP server (to which the object is currently connected) using the specified name and password. |
LDAPResponseListener |
bind(java.lang.String dn,
java.lang.String passwd,
LDAPResponseListener listener,
LDAPConstraints cons)
Authenticates to the LDAP server (to which the object is currently connected) using the specified name and password and allows you to specify constraints for this LDAP add operation by using an LDAPConstraints object. |
java.lang.Object |
clone()
Creates and returns a new LDAPConnection object that
contains the same information as the current connection, including:
the default search constraints
host name and port number of the LDAP server
the DN and password used to authenticate to the LDAP server
|
boolean |
compare(java.lang.String DN,
LDAPAttribute attr)
Checks to see if an entry contains an attribute with a specified value. |
boolean |
compare(java.lang.String DN,
LDAPAttribute attr,
LDAPConstraints cons)
Compares the given entry's attribute value to the specified attribute value. |
LDAPResponseListener |
compare(java.lang.String dn,
LDAPAttribute attr,
LDAPResponseListener listener)
Compare an attribute value with one in the directory. |
LDAPResponseListener |
compare(java.lang.String dn,
LDAPAttribute attr,
LDAPResponseListener listener,
LDAPConstraints cons)
Compare an attribute value with one in the directory. |
boolean |
compare(java.lang.String DN,
LDAPAttribute attr,
LDAPSearchConstraints cons)
Deprecated. Please use the method signature where cons is
LDAPConstraints instead of LDAPSearchConstraints |
void |
connect(int version,
java.lang.String host,
int port,
java.lang.String dn,
java.lang.String passwd)
Connects to the specified host and port and uses the specified DN and password to authenticate to the server, with the specified LDAP protocol version. |
void |
connect(int version,
java.lang.String host,
int port,
java.lang.String dn,
java.lang.String passwd,
LDAPConstraints cons)
Connects to the specified host and port and uses the specified DN and password to authenticate to the server, with the specified LDAP protocol version. |
void |
connect(int version,
java.lang.String host,
int port,
java.lang.String dn,
java.lang.String passwd,
LDAPSearchConstraints cons)
Deprecated. Please use the method signature where cons is
LDAPConstraints instead of LDAPSearchConstraints |
void |
connect(java.lang.String host,
int port)
Connects to the specified host and port. |
void |
connect(java.lang.String host,
int port,
java.lang.String dn,
java.lang.String passwd)
Connects to the specified host and port and uses the specified DN and password to authenticate to the server. |
void |
connect(java.lang.String host,
int port,
java.lang.String dn,
java.lang.String passwd,
LDAPConstraints cons)
Connects to the specified host and port and uses the specified DN and password to authenticate to the server. |
void |
connect(java.lang.String host,
int port,
java.lang.String dn,
java.lang.String passwd,
LDAPSearchConstraints cons)
Deprecated. Please use the method signature where cons is
LDAPConstraints instead of LDAPSearchConstraints |
void |
delete(java.lang.String DN)
Deletes the entry for the specified DN from the directory. |
void |
delete(java.lang.String DN,
LDAPConstraints cons)
Deletes the entry for the specified DN from the directory and allows you to specify preferences for this LDAP delete operation by using an LDAPConstraints object. |
LDAPResponseListener |
delete(java.lang.String dn,
LDAPResponseListener listener)
Deletes the entry for the specified DN from the directory. |
LDAPResponseListener |
delete(java.lang.String dn,
LDAPResponseListener listener,
LDAPConstraints cons)
Deletes the entry for the specified DN from the directory. |
void |
delete(java.lang.String DN,
LDAPSearchConstraints cons)
Deprecated. Please use the method signature where cons is
LDAPConstraints instead of LDAPSearchConstraints |
void |
disconnect()
Disconnects from the LDAP server. |
LDAPExtendedOperation |
extendedOperation(LDAPExtendedOperation op)
Performs an extended operation on the directory. |
LDAPExtendedOperation |
extendedOperation(LDAPExtendedOperation op,
LDAPConstraints cons)
Performs an extended operation on the directory. |
LDAPExtendedOperation |
extendedOperation(LDAPExtendedOperation op,
LDAPSearchConstraints cons)
Deprecated. Please use the method signature where cons is
LDAPConstraints instead of LDAPSearchConstraints |
void |
finalize()
Finalize method, which disconnects from the LDAP server. |
java.lang.String |
getAuthenticationDN()
Returns the distinguished name (DN) used for authentication over this connection. |
java.lang.String |
getAuthenticationPassword()
Returns the password used for authentication over this connection. |
LDAPCache |
getCache()
Gets the LDAPCache object associated with
the current LDAPConnection object. |
int |
getConnSetupDelay()
Returns the delay in seconds when making concurrent connection attempts to multiple servers. |
LDAPConstraints |
getConstraints()
Returns the set of constraints that apply to all operations performed through this connection (unless you specify a different set of constraints when calling a method). |
java.lang.String |
getHost()
Returns the host name of the LDAP server to which you are connected. |
java.io.InputStream |
getInputStream()
Gets the stream for reading from the listener socket |
java.lang.Object |
getOption(int option)
Returns the value of the specified option for this LDAPConnection object. |
java.io.OutputStream |
getOutputStream()
Gets the stream for writing to the socket |
int |
getPort()
Returns the port number of the LDAP server to which you are connected. |
java.lang.Object |
getProperty(java.lang.String name)
Gets a property of a connection. |
LDAPControl[] |
getResponseControls()
Returns an array of the latest controls (if any) from server. |
LDAPSearchConstraints |
getSearchConstraints()
Returns the set of search constraints that apply to all searches performed through this connection (unless you specify a different set of search constraints when calling the search
method). |
LDAPSocketFactory |
getSocketFactory()
Gets the object representing the socket factory used to establish a connection to the LDAP server. |
boolean |
isAuthenticated()
Indicates whether this client has authenticated to the LDAP server |
boolean |
isConnected()
Indicates whether the connection represented by this object is open at this time. |
static boolean |
isNetscape()
Reports if the class is running in a Netscape browser. |
static void |
main(java.lang.String[] args)
Prints out the LDAP Java SDK version and the highest LDAP protocol version supported by the SDK. |
void |
modify(java.lang.String DN,
LDAPModification mod)
Makes a single change to an existing entry in the directory (for example, changes the value of an attribute, adds a new attribute value, or removes an existing attribute value). |
void |
modify(java.lang.String DN,
LDAPModification[] mods)
Makes a set of changes to an existing entry in the directory (for example, changes attribute values, adds new attribute values, or removes existing attribute values). |
void |
modify(java.lang.String DN,
LDAPModification[] mods,
LDAPConstraints cons)
Makes a set of changes to an existing entry in the directory and allows you to specify preferences for this LDAP modify operation by using an LDAPConstraints object. |
void |
modify(java.lang.String DN,
LDAPModification[] mods,
LDAPSearchConstraints cons)
Deprecated. Please use the method signature where cons is
LDAPConstraints instead of LDAPSearchConstraints |
void |
modify(java.lang.String DN,
LDAPModification mod,
LDAPConstraints cons)
Makes a single change to an existing entry in the directory and allows you to specify preferences for this LDAP modify operation by using an LDAPConstraints object. |
LDAPResponseListener |
modify(java.lang.String dn,
LDAPModification mod,
LDAPResponseListener listener)
Makes a single change to an existing entry in the directory (for example, changes the value of an attribute, adds a new attribute value, or removes an existing attribute value). The LDAPModification object specifies both the change to make and the LDAPAttribute value to be changed. |
LDAPResponseListener |
modify(java.lang.String dn,
LDAPModification mod,
LDAPResponseListener listener,
LDAPConstraints cons)
Makes a single change to an existing entry in the directory (for example, changes the value of an attribute, adds a new attribute value, or removes an existing attribute value). The LDAPModification object specifies both the change to make and the LDAPAttribute value to be changed. |
void |
modify(java.lang.String DN,
LDAPModification mod,
LDAPSearchConstraints cons)
Deprecated. Please use the method signature where cons is
LDAPConstraints instead of LDAPSearchConstraints |
void |
modify(java.lang.String DN,
LDAPModificationSet mods)
Makes a set of changes to an existing entry in the directory (for example, changes attribute values, adds new attribute values, or removes existing attribute values). |
void |
modify(java.lang.String DN,
LDAPModificationSet mods,
LDAPConstraints cons)
Makes a set of changes to an existing entry in the directory and allows you to specify preferences for this LDAP modify operation by using an LDAPConstraints object. |
LDAPResponseListener |
modify(java.lang.String dn,
LDAPModificationSet mods,
LDAPResponseListener listener)
Makes a set of changes to an existing entry in the directory (for example, changes attribute values, adds new attribute values, or removes existing attribute values). |
LDAPResponseListener |
modify(java.lang.String dn,
LDAPModificationSet mods,
LDAPResponseListener listener,
LDAPConstraints cons)
Makes a set of changes to an existing entry in the directory (for example, changes attribute values, adds new attribute values, or removes existing attribute values). |
void |
modify(java.lang.String DN,
LDAPModificationSet mods,
LDAPSearchConstraints cons)
Deprecated. Please use the method signature where cons is
LDAPConstraints instead of LDAPSearchConstraints |
static LDAPEntry |
read(LDAPUrl toGet)
Reads the entry specified by the LDAP URL. |
LDAPEntry |
read(java.lang.String DN)
Reads the entry for the specified distiguished name (DN) and retrieves all attributes for the entry. |
LDAPEntry |
read(java.lang.String DN,
LDAPSearchConstraints cons)
Reads the entry for the specified distiguished name (DN) and retrieves all attributes for the entry. |
LDAPEntry |
read(java.lang.String DN,
java.lang.String[] attrs)
Reads the entry for the specified distinguished name (DN) and retrieves only the specified attributes from the entry. |
LDAPEntry |
read(java.lang.String DN,
java.lang.String[] attrs,
LDAPSearchConstraints cons)
Read the entry corresponding to the specified distinguished name (DN), and retrieve only the specified attributes. |
void |
reconnect()
Disconnect from the server and then reconnect using the current credentials and authentication method |
void |
rename(java.lang.String DN,
java.lang.String newRDN,
boolean deleteOldRDN)
Renames an existing entry in the directory. |
void |
rename(java.lang.String DN,
java.lang.String newRDN,
boolean deleteOldRDN,
LDAPConstraints cons)
Renames an existing entry in the directory. |
LDAPResponseListener |
rename(java.lang.String dn,
java.lang.String newRdn,
boolean deleteOldRdn,
LDAPResponseListener listener)
Renames an existing entry in the directory. |
LDAPResponseListener |
rename(java.lang.String dn,
java.lang.String newRdn,
boolean deleteOldRdn,
LDAPResponseListener listener,
LDAPConstraints cons)
Renames an existing entry in the directory. |
void |
rename(java.lang.String DN,
java.lang.String newRDN,
boolean deleteOldRDN,
LDAPSearchConstraints cons)
Deprecated. Please use the method signature where cons is
LDAPConstraints instead of LDAPSearchConstraints |
void |
rename(java.lang.String dn,
java.lang.String newRDN,
java.lang.String newParentDN,
boolean deleteOldRDN)
Renames an existing entry in the directory and (optionally) changes the location of the entry in the directory tree. |
void |
rename(java.lang.String DN,
java.lang.String newRDN,
java.lang.String newParentDN,
boolean deleteOldRDN,
LDAPConstraints cons)
Renames an existing entry in the directory and (optionally) changes the location of the entry in the directory tree. |
void |
rename(java.lang.String DN,
java.lang.String newRDN,
java.lang.String newParentDN,
boolean deleteOldRDN,
LDAPSearchConstraints cons)
Deprecated. Please use the method signature where cons is
LDAPConstraints instead of LDAPSearchConstraints |
static LDAPSearchResults |
search(LDAPUrl toGet)
Performs the search specified by the LDAP URL. |
static LDAPSearchResults |
search(LDAPUrl toGet,
LDAPSearchConstraints cons)
Performs the search specified by the LDAP URL. |
LDAPSearchResults |
search(java.lang.String base,
int scope,
java.lang.String filter,
java.lang.String[] attrs,
boolean attrsOnly)
Performs the search specified by the criteria that you enter. |
LDAPSearchResults |
search(java.lang.String base,
int scope,
java.lang.String filter,
java.lang.String[] attrs,
boolean attrsOnly,
LDAPSearchConstraints cons)
Performs the search specified by the criteria that you enter. |
LDAPSearchListener |
search(java.lang.String base,
int scope,
java.lang.String filter,
java.lang.String[] attrs,
boolean typesOnly,
LDAPSearchListener listener)
Performs the search specified by the criteria that you enter. |
LDAPSearchListener |
search(java.lang.String base,
int scope,
java.lang.String filter,
java.lang.String[] attrs,
boolean typesOnly,
LDAPSearchListener listener,
LDAPSearchConstraints cons)
Performs the search specified by the criteria that you enter. |
void |
setCache(LDAPCache cache)
Sets the specified LDAPCache object as the
cache for the LDAPConnection object. |
void |
setConnSetupDelay(int delay)
Specifies the delay in seconds when making concurrent connection attempts to multiple servers. |
void |
setConstraints(LDAPConstraints cons)
Set the default constraint set for all operations. |
void |
setInputStream(java.io.InputStream is)
Sets the stream for reading from the listener socket if there is one |
void |
setOption(int option,
java.lang.Object value)
Sets the value of the specified option for this LDAPConnection object. |
void |
setOutputStream(java.io.OutputStream os)
Sets the stream for writing to the socket |
void |
setProperty(java.lang.String name,
java.lang.Object val)
The following properties are defined: com.netscape.ldap.schema.quoting - "standard" or "NetscapeBug" Note: if this property is not set, the SDK will query the server to determine if attribute syntax values and objectclass superior values must be quoted when adding schema. com.netscape.ldap.saslpackage - the default is "com.netscape.sasl" |
void |
setSearchConstraints(LDAPSearchConstraints cons)
Set the default constraint set for all search operations. |
void |
setSocketFactory(LDAPSocketFactory factory)
Specifies the object representing the socket factory that you want to use to establish a connection to a server. |
Methods inherited from class java.lang.Object |
equals,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
Field Detail |
public static final int LDAP_VERSION
LDAP_VERSION
is 2, so your client will
attempt to authenticate to LDAP servers as an LDAP v2 client.
The following is an example of some code that prints the
value of this variable:
LDAPConnection ld = new LDAPConnection(); System.out.println( "The default LDAP protocol version used is " ld.LDAP_VERSION );If you want to authenticate as an LDAP v3 client, use the
authenticate(int version, String dn, String passwd)
method.
For example:
ld.authenticate( 3, myDN, myPW );
authenticate(int, java.lang.String, java.lang.String)
public static final java.lang.String LDAP_PROPERTY_SDK
To get the version number, pass this name to the
getProperty
method. The SDK version number
is of the type Float
. For example:
... Float sdkVersion = ( Float )myConn.getProperty( myConn.LDAP_PROPERTY_SDK ); System.out.println( "SDK version: " + sdkVersion ); ...
getProperty(java.lang.String)
public static final java.lang.String LDAP_PROPERTY_PROTOCOL
To get the version number, pass this name to the
getProperty
method. The LDAP protocol version number
is of the type Float
. For example:
... Float LDAPVersion = ( Float )myConn.getProperty( myConn.LDAP_PROPERTY_PROTOCOL ); System.out.println( "Highest supported LDAP protocol version: " + LDAPVersion ); ...
getProperty(java.lang.String)
public static final java.lang.String LDAP_PROPERTY_SECURITY
To get the supported types, pass this name to the
getProperty
method. The value of this property is
of the type String
. For example:
... String authTypes = ( String )myConn.getProperty( myConn.LDAP_PROPERTY_SECURITY ); System.out.println( "Supported authentication types: " + authTypes ); ...
getProperty(java.lang.String)
public static final java.lang.String TRACE_PROPERTY
The property can be specified either as a system property
(java -D command line option), or programmatically with
setProperty
method.
When -D command line option is used, defining the property with no value will send the trace output to the standard error. If the value is defined, it is assumed to be the name of an output file.
When the property is set with getProperty
method,
the property must have an output stream as the value. To stop
tracing, null
should be passed as the property value.
setProperty(java.lang.String, java.lang.Object)
public static final int NODELAY_SERIAL
connect
method.setConnSetupDelay(int)
public static final int NODELAY_PARALLEL
connect
method.
For each host in the list, a separate thread is created to attempt
to connect to the host. All threads are started simultaneously.setConnSetupDelay(int)
public static final int MAXBACKLOG
getOption(int)
,
setOption(int, java.lang.Object)
Constructor Detail |
public LDAPConnection()
LDAPConnection
object,
which represents a connection to an LDAP server.
Calling the constructor does not actually establish
the connection. To connect to the LDAP server, use the
connect
method.
connect(java.lang.String, int)
,
authenticate(java.lang.String, java.lang.String)
public LDAPConnection(LDAPSocketFactory factory)
LDAPConnection
object that
will use the specified socket factory class to create
socket connections. The socket factory class must implement
the LDAPSocketFactory
interface. LDAPSSLSocketFactory
class implements this interface.)
Note that calling the LDAPConnection
constructor
does not actually establish a connection to an LDAP server.
To connect to an LDAP server, use the
connect
method. The socket connection will be
constructed when this method is called.
LDAPSocketFactory
,
LDAPSSLSocketFactory
,
connect(java.lang.String, int)
,
authenticate(java.lang.String, java.lang.String)
,
getSocketFactory()
,
setSocketFactory(netscape.ldap.LDAPSocketFactory)
Method Detail |
public void finalize() throws LDAPException
public void setCache(LDAPCache cache)
LDAPCache
object as the
cache for the LDAPConnection
object.
cache
- the LDAPCache
object representing
the cache that the current connection should useLDAPCache
,
getCache()
public LDAPCache getCache()
LDAPCache
object associated with
the current LDAPConnection
object.
LDAPCache
object representing
the cache that the current connection should useLDAPCache
,
setCache(netscape.ldap.LDAPCache)
public java.lang.Object getProperty(java.lang.String name) throws LDAPException
You can get the following properties for a given connection:
LDAP_PROPERTY_SDK
To get the version of this SDK, get this property. The value of
this property is of the type Float
.
LDAP_PROPERTY_PROTOCOL
To get the highest supported version of the LDAP protocol, get
this property.
The value of this property is of the type Float
.
LDAP_PROPERTY_SECURITY
To get a comma-separated list of the types of authentication
supported, get this property. The value of this property is of the
type String
.
For example, the following section of code gets the version of the SDK.
... Float sdkVersion = ( Float )myConn.getProperty( myConn.LDAP_PROPERTY_SDK ); System.out.println( "SDK version: " + sdkVersion ); ...
name
- name of the property (for example, LDAP_PROPERTY_SDK
)
Since the return value is an object, you should recast it as the appropriate type.
(For example, when getting the LDAP_PROPERTY_SDK
property,
recast the return value as a Float
.)
If you pass this method an unknown property name, the method returns null.
LDAP_PROPERTY_SDK
,
LDAP_PROPERTY_PROTOCOL
,
LDAP_PROPERTY_SECURITY
public void setProperty(java.lang.String name, java.lang.Object val) throws LDAPException
name
- name of the property to setval
- value to setpublic java.lang.String getHost()
public int getPort()
public java.lang.String getAuthenticationDN()
public java.lang.String getAuthenticationPassword()
public int getConnSetupDelay()
NODELAY_SERIAL
The serial connection setup policy is enabled
(no concurrency).NODELAY_PARALLEL
The parallel connection setup policy with no delay
is enabled.delay > 0
The parallel connection setup policy with the delay of
delay
seconds is enabled.setConnSetupDelay(int)
public void setConnSetupDelay(int delay)
Effectively, selects the connection setup policy when a list of hosts is passed
to the connect
method.
If the serial policy, the default one, is selected, an attempt is made to
connect to the first host in the list. The next entry in
the list is tried only if the attempt to connect to the current host fails.
This might cause your application to block for unacceptably long time if a host is down.
If the parallel policy is selected, multiple connection attempts may run
concurrently on a separate thread. A new connection attempt to the next entry
in the list can be started with or without delay.
You must set the ConnSetupDelay
before making the call to the
connect
method.
delay
- the delay in seconds between connection attempts. Possible values are:NODELAY_SERIAL
Use the serial connection setup policy.NODELAY_PARALLEL
Use the parallel connection setup policy with no delay.
Start all connection setup threads immediately.delay > 0
Use the parallel connection setup policy with delay.
Start another connection setup thread after delay
seconds.NODELAY_SERIAL
,
NODELAY_PARALLEL
,
connect(java.lang.String, int)
public LDAPSocketFactory getSocketFactory()
LDAPSocketFactory
,
LDAPSSLSocketFactory
,
setSocketFactory(netscape.ldap.LDAPSocketFactory)
public void setSocketFactory(LDAPSocketFactory factory)
factory
- the object representing the socket factory that
you want to use to establish a connection to a serverLDAPSocketFactory
,
LDAPSSLSocketFactory
,
getSocketFactory()
public boolean isConnected()
true
if connected to an LDAP server over this connection.
If not connected to an LDAP server, returns false
.public boolean isAuthenticated()
true,
, if authenticated. If not
authenticated, or if authenticated as an anonymous user (with
either a blank name or password), returns false
.public void connect(java.lang.String host, int port) throws LDAPException
For example, the following section of code establishes a connection with the LDAP server running on the host ldap.netscape.com and the port 389.
String ldapHost = "ldap.netscape.com"; int ldapPort = 389; LDAPConnection myConn = new LDAPConnection(); try { myConn.connect( ldapHost, ldapPort ); } catch ( LDAPException e ) { System.out.println( "Unable to connect to " + ldapHost + " at port " + ldapPort ); return; } System.out.println( "Connected to " + ldapHost + " at port " + ldapPort )
host
- host name of the LDAP server to which you want to connect.
This value can also be a space-delimited list of hostnames or
hostnames and port numbers (using the syntax
hostname:portnumber). The connection setup policy specified with
the ConnSetupDelay
property controls whether connection
attempts are made serially or concurrently. For example, you can specify
the following values for the host
argument:myhost myhost hishost:389 herhost:5000 whathost myhost:686 myhost:389 hishost:5000 whathost:1024
port
- port number of the LDAP server to which you want to connect.
This parameter is ignored for any host in the host
parameter which includes a colon and port number.setConnSetupDelay(int)
public void connect(java.lang.String host, int port, java.lang.String dn, java.lang.String passwd) throws LDAPException
For example, the following section of code establishes a connection with the LDAP server running on ldap.netscape.com at port 389. The example also attempts to authenticate the client as Barbara Jensen.
String ldapHost = "ldap.netscape.com"; int ldapPort = 389; String myDN = "cn=Barbara Jensen,ou=Product Development,o=Ace Industry,c=US"; String myPW = "hifalutin"; LDAPConnection myConn = new LDAPConnection(); try { myConn.connect( ldapHost, ldapPort, myDN, myPW ); } catch ( LDAPException e ) { switch( e.getLDAPResultCode() ) { case e.NO_SUCH_OBJECT: System.out.println( "The specified user does not exist." ); break; case e.INVALID_CREDENTIALS: System.out.println( "Invalid password." ); break; default: System.out.println( "Error number: " + e.getLDAPResultCode() ); System.out.println( "Failed to connect to " + ldapHost + " at port " + ldapPort ); break; } return; } System.out.println( "Connected to " + ldapHost + " at port " + ldapPort );
host
- host name of the LDAP server to which you want to connect.
This value can also be a space-delimited list of hostnames or
hostnames and port numbers (using the syntax
hostname:portnumber). The connection setup policy specified with
the ConnSetupDelay
property controls whether connection
attempts are made serially or concurrently. For example, you can specify
the following values for the host
argument:myhost myhost hishost:389 herhost:5000 whathost myhost:686 myhost:389 hishost:5000 whathost:1024
port
- port number of the LDAP server to which you want to connect.
This parameter is ignored for any host in the host
parameter which includes a colon and port number.dn
- distinguished name used for authenticationpasswd
- password used for authenticationsetConnSetupDelay(int)
public void connect(java.lang.String host, int port, java.lang.String dn, java.lang.String passwd, LDAPConstraints cons) throws LDAPException
host
- host name of the LDAP server to which you want to connect.
This value can also be a space-delimited list of hostnames or
hostnames and port numbers (using the syntax
hostname:portnumber). The connection setup policy specified with
the ConnSetupDelay
property controls whether connection
attempts are made serially or concurrently. For example, you can specify
the following values for the host
argument:myhost myhost hishost:389 herhost:5000 whathost myhost:686 myhost:389 hishost:5000 whathost:1024
port
- port number of the LDAP server to which you want to connect.
This parameter is ignored for any host in the host
parameter which includes a colon and port number.dn
- distinguished name used for authenticationpasswd
- password used for authenticationcons
- preferences for the bind operationsetConnSetupDelay(int)
public void connect(java.lang.String host, int port, java.lang.String dn, java.lang.String passwd, LDAPSearchConstraints cons) throws LDAPException
cons
is
LDAPConstraints
instead of LDAPSearchConstraints
public void connect(int version, java.lang.String host, int port, java.lang.String dn, java.lang.String passwd) throws LDAPException
connect(host, port)
followed by authenticate(version, dn, passwd)
.version
- requested version of LDAP: currently 2 or 3host
- a hostname to which to connect or a dotted string representing
the IP address of this host.
Alternatively, this can be a space-delimited list of host names.
Each host name may include a trailing colon and port number. In the
case where more than one host name is specified, the connection setup
policy specified with the ConnSetupDelay
property controls
whether connection attempts are made serially or concurrently.
Examples: "directory.knowledge.com" "199.254.1.2" "directory.knowledge.com:1050 people.catalog.com 199.254.1.2"
port
- the TCP or UDP port number to which to connect or contact.
The default LDAP port is 389. "port" is ignored for any host name which
includes a colon and port number.dn
- if non-null and non-empty, specifies that the connection and
all operations through it should authenticate with dn as the
distinguished namepasswd
- if non-null and non-empty, specifies that the connection and
all operations through it should authenticate with dn as the
distinguished name and passwd as password.setConnSetupDelay(int)
public void connect(int version, java.lang.String host, int port, java.lang.String dn, java.lang.String passwd, LDAPConstraints cons) throws LDAPException
connect(host, port)
followed by authenticate(version, dn, passwd)
.version
- requested version of LDAP: currently 2 or 3host
- a hostname to which to connect or a dotted string representing
the IP address of this host.
Alternatively, this can be a space-delimited list of host names.
Each host name may include a trailing colon and port number. In the
case where more than one host name is specified, the connection setup
policy specified with the ConnSetupDelay
property controls
whether connection attempts are made serially or concurrently.
Examples: "directory.knowledge.com" "199.254.1.2" "directory.knowledge.com:1050 people.catalog.com 199.254.1.2"
port
- the TCP or UDP port number to which to connect or contact.
The default LDAP port is 389. "port" is ignored for any host name which
includes a colon and port number.dn
- if non-null and non-empty, specifies that the connection and
all operations through it should authenticate with dn as the
distinguished namepasswd
- if non-null and non-empty, specifies that the connection and
all operations through it should authenticate with dn as the
distinguished name and passwd as passwordcons
- preferences for the bind operationsetConnSetupDelay(int)
public void connect(int version, java.lang.String host, int port, java.lang.String dn, java.lang.String passwd, LDAPSearchConstraints cons) throws LDAPException
cons
is
LDAPConstraints
instead of LDAPSearchConstraints
public void abandon(LDAPSearchResults searchResults) throws LDAPException
searchResults
- the search results returned when the search
was startedsearch(java.lang.String, int, java.lang.String, java.lang.String[], boolean, netscape.ldap.LDAPSearchConstraints)
,
LDAPSearchResults
public void authenticate(java.lang.String dn, java.lang.String passwd) throws LDAPException
For example, the following section of code authenticates the client as Barbara Jensen. The code assumes that the client has already established a connection with an LDAP server.
String myDN = "cn=Barbara Jensen,ou=Product Development,o=Ace Industry,c=US"; String myPW = "hifalutin"; try { myConn.authenticate( myDN, myPW ); } catch ( LDAPException e ) { switch( e.getLDAPResultCode() ) { case e.NO_SUCH_OBJECT: System.out.println( "The specified user does not exist." ); break; case e.INVALID_CREDENTIALS: System.out.println( "Invalid password." ); break; default: System.out.println( "Error number: " + e.getLDAPResultCode() ); System.out.println( "Failed to authentice as " + myDN ); break; } return; } System.out.println( "Authenticated as " + myDN );
dn
- distinguished name used for authenticationpasswd
- password used for authenticationpublic void authenticate(java.lang.String dn, java.lang.String passwd, LDAPConstraints cons) throws LDAPException
dn
- distinguished name used for authenticationpasswd
- password used for authenticationcons
- preferences for the bind operationpublic void authenticate(java.lang.String dn, java.lang.String passwd, LDAPSearchConstraints cons) throws LDAPException
cons
is
LDAPConstraints
instead of LDAPSearchConstraints
public void authenticate(int version, java.lang.String dn, java.lang.String passwd) throws LDAPException
version
- required LDAP protocol versiondn
- distinguished name used for authenticationpasswd
- password used for authenticationpublic void authenticate(int version, java.lang.String dn, java.lang.String passwd, LDAPConstraints cons) throws LDAPException
version
- required LDAP protocol versiondn
- distinguished name used for authenticationpasswd
- password used for authenticationcons
- preferences for the bind operationpublic void authenticate(int version, java.lang.String dn, java.lang.String passwd, LDAPSearchConstraints cons) throws LDAPException
cons
is
LDAPConstraints
instead of LDAPSearchConstraints
public void authenticate(java.lang.String dn, java.util.Hashtable props, java.lang.Object cbh) throws LDAPException
dn
- if non-null and non-empty, specifies that the connection and
all operations through it should authenticate with dn as the
distinguished namecbh
- a class which the SASL framework can call to obtain
additional required informationpublic void authenticate(java.lang.String dn, java.lang.String[] mechanisms, java.util.Hashtable props, java.lang.Object cbh) throws LDAPException
dn
- if non-null and non-empty, specifies that the connection and
all operations through it should authenticate with dn as the
distinguished namemechanisms
- a list of acceptable mechanisms. The first one
for which a Mechanism Driver can be instantiated is returned.cbh
- a class which the SASL framework can call to
obtain additional required informationnetscape.ldap.LDAPConnection#authenticate(java.lang.String,
java.util.Hashtable, javax.security.auth.callback.CallbackHandler)
public void authenticate(java.lang.String dn, java.lang.String mechanism, java.lang.String packageName, java.util.Hashtable props, java.lang.Object cbh) throws LDAPException
dn
- if non-null and non-empty, specifies that the connection and
all operations through it should authenticate with dn as the
distinguished namemechanism
- a single mechanism name, e.g. "GSSAPI"packageName
- a package containing a SASL ClientFactory,
e.g. "myclasses.SASL". If null, a system default is used.cbh
- a class which the SASL framework can call to
obtain additional required informationpublic void authenticate(java.lang.String dn, java.lang.String[] mechanisms, java.lang.String packageName, java.util.Hashtable props, java.lang.Object cbh) throws LDAPException
dn
- if non-null and non-empty, specifies that the connection and
all operations through it should authenticate with dn as the
distinguished namemechanisms
- a list of acceptable mechanisms. The first one
for which a Mechanism Driver can be instantiated is returned.packageName
- a package containing a SASL ClientFactory,
e.g. "myclasses.SASL". If null, a system default is used.cbh
- a class which the SASL framework can call to
obtain additional required informationpublic LDAPResponseListener authenticate(int version, java.lang.String dn, java.lang.String passwd, LDAPResponseListener listener, LDAPConstraints cons) throws LDAPException
LDAPConstraints
object. If the object
has been disconnected from an LDAP server, this method attempts to
reconnect to the server. If the object had already authenticated, the
old authentication is discarded.version
- Required LDAP protocol version.dn
- If non-null and non-empty, specifies that the connection
and all operations through it should be authenticated with dn as the
distinguished name.passwd
- If non-null and non-empty, specifies that the connection
and all operations through it should be authenticated with dn as the
distinguished name and passwd as password.listener
- Handler for messages returned from a server in response
to this request. If it is null, a listener object is created internally.cons
- Constraints specific to the operation.LDAPResponseListener
,
LDAPConstraints
public LDAPResponseListener authenticate(int version, java.lang.String dn, java.lang.String passwd, LDAPResponseListener listener) throws LDAPException
LDAPConstraints
object. If the object
has been disconnected from an LDAP server, this method attempts to
reconnect to the server. If the object had already authenticated, the
old authentication is discarded.version
- Required LDAP protocol version.dn
- If non-null and non-empty, specifies that the connection
and all operations through it should be authenticated with dn as the
distinguished name.passwd
- If non-null and non-empty, specifies that the connection
and all operations through it should be authenticated with dn as the
distinguished name and passwd as password.listener
- Handler for messages returned from a server in response
to this request. If it is null, a listener object is created internally.LDAPResponseListener
,
LDAPConstraints
public void bind(java.lang.String dn, java.lang.String passwd) throws LDAPException
For example, the following section of code authenticates the client as Barbara Jensen. The code assumes that the client has already established a connection with an LDAP server.
String myDN = "cn=Barbara Jensen,ou=Product Development,o=Ace Industry,c=US"; String myPW = "hifalutin"; try { myConn.bind( myDN, myPW ); } catch ( LDAPException e ) { switch( e.getLDAPResultCode() ) { case e.NO_SUCH_OBJECT: System.out.println( "The specified user does not exist." ); break; case e.INVALID_CREDENTIALS: System.out.println( "Invalid password." ); break; default: System.out.println( "Error number: " + e.getLDAPResultCode() ); System.out.println( "Failed to authentice as " + myDN ); break; } return; } System.out.println( "Authenticated as " + myDN );
dn
- distinguished name used for authenticationpasswd
- password used for authenticationpublic void bind(java.lang.String dn, java.lang.String passwd, LDAPConstraints cons) throws LDAPException
dn
- distinguished name used for authenticationpasswd
- password used for authenticationcons
- preferences for the bind operationpublic void bind(int version, java.lang.String dn, java.lang.String passwd) throws LDAPException
version
- required LDAP protocol versiondn
- distinguished name used for authenticationpasswd
- password used for authenticationpublic void bind(int version, java.lang.String dn, java.lang.String passwd, LDAPConstraints cons) throws LDAPException
version
- required LDAP protocol versiondn
- distinguished name used for authenticationpasswd
- password used for authenticationcons
- preferences for the bind operationpublic void bind(java.lang.String dn, java.util.Hashtable props, java.lang.Object cbh) throws LDAPException
dn
- if non-null and non-empty, specifies that the connection and
all operations through it should authenticate with dn as the
distinguished namecbh
- a class which the SASL framework can call to
obtain additional required informationpublic void bind(java.lang.String dn, java.lang.String[] mechanisms, java.util.Hashtable props, java.lang.Object cbh) throws LDAPException
dn
- if non-null and non-empty, specifies that the connection and
all operations through it should authenticate with dn as the
distinguished namemechanisms
- a list of acceptable mechanisms. The first one
for which a Mechanism Driver can be instantiated is returned.cbh
- a class which the SASL framework can call to
obtain additional required informationnetscape.ldap.LDAPConnection#bind(java.lang.String,
java.util.Hashtable, javax.security.auth.callback.CallbackHandler)
public void reconnect() throws LDAPException
public void disconnect() throws LDAPException
connect
.connect(java.lang.String, int)
,
connect(java.lang.String, int, java.lang.String, java.lang.String)
public LDAPEntry read(java.lang.String DN) throws LDAPException
For example, the following section of code reads the entry for Barbara Jensen and retrieves all attributes for that entry.
String findDN = "cn=Barbara Jensen,ou=Product Development,o=Ace Industry,c=US"; LDAPEntry foundEntry = null; try { foundEntry = myConn.read( findDN ); } catch ( LDAPException e ) { switch( e.getLDAPResultCode() ) { case e.NO_SUCH_OBJECT: System.out.println( "The specified entry does not exist." ); break; case e.LDAP_PARTIAL_RESULTS: System.out.println( "Entry served by a different LDAP server." ); break; case e.INSUFFICIENT_ACCESS_RIGHTS: System.out.println( "You do not have the access rights to perform this operation." ); break; default: System.out.println( "Error number: " + e.getLDAPResultCode() ); System.out.println( "Could not read the specified entry." ); break; } return; } System.out.println( "Found the specified entry." );
DN
- distinguished name of the entry to retrievepublic LDAPEntry read(java.lang.String DN, LDAPSearchConstraints cons) throws LDAPException
For example, the following section of code reads the entry for Barbara Jensen and retrieves all attributes for that entry.
String findDN = "cn=Barbara Jensen,ou=Product Development,o=Ace Industry,c=US"; LDAPEntry foundEntry = null; try { foundEntry = myConn.read( findDN ); } catch ( LDAPException e ) { switch( e.getLDAPResultCode() ) { case e.NO_SUCH_OBJECT: System.out.println( "The specified entry does not exist." ); break; case e.LDAP_PARTIAL_RESULTS: System.out.println( "Entry served by a different LDAP server." ); break; case e.INSUFFICIENT_ACCESS_RIGHTS: System.out.println( "You do not have the access rights to perform this operation." ); break; default: System.out.println( "Error number: " + e.getLDAPResultCode() ); System.out.println( "Could not read the specified entry." ); break; } return; } System.out.println( "Found the specified entry." );
DN
- distinguished name of the entry to retrievecons
- preferences for the read operationpublic LDAPEntry read(java.lang.String DN, java.lang.String[] attrs) throws LDAPException
For example, the following section of code reads the entry for
Barbara Jensen and retrieves only the cn
and
sn
attributes.
The example prints out all attributes that have been retrieved
(the two specified attributes).
String findDN = "cn=Barbara Jensen,ou=Product Development,o=Ace Industry,c=US"; LDAPEntry foundEntry = null; String getAttrs[] = { "cn", "sn" }; try { foundEntry = myConn.read( findDN, getAttrs ); } catch ( LDAPException e ) { switch( e.getLDAPResultCode() ) { case e.NO_SUCH_OBJECT: System.out.println( "The specified entry does not exist." ); break; case e.LDAP_PARTIAL_RESULTS: System.out.println( "Entry served by a different LDAP server." ); break; case e.INSUFFICIENT_ACCESS_RIGHTS: System.out.println( "You do not have the access " + "rights to perform this operation." ); break; default: System.out.println( "Error number: " + e.getLDAPResultCode() ); System.out.println( "Could not read the specified entry." ); break; } return; } LDAPAttributeSet foundAttrs = foundEntry.getAttributeSet(); int size = foundAttrs.size(); Enumeration enumAttrs = foundAttrs.getAttributes(); System.out.println( "Attributes: " ); while ( enumAttrs.hasMoreElements() ) { LDAPAttribute anAttr = ( LDAPAttribute )enumAttrs.nextElement(); String attrName = anAttr.getName(); System.out.println( "\t" + attrName ); Enumeration enumVals = anAttr.getStringValues(); while ( enumVals.hasMoreElements() ) { String aVal = ( String )enumVals.nextElement(); System.out.println( "\t\t" + aVal ); } }
DN
- distinguished name of the entry to retrieveattrs
- names of attributes to retrievepublic LDAPEntry read(java.lang.String DN, java.lang.String[] attrs, LDAPSearchConstraints cons) throws LDAPException
DN
- distinguished name of the entry to retrieveattrs
- names of attributes to retrievecons
- the constraints set for the read operationpublic static LDAPEntry read(LDAPUrl toGet) throws LDAPException
When you call this method, a new connection is created automatically, using the host and port specified in the URL. After finding the entry, the method closes this connection (in other words, it disconnects from the LDAP server).
If the URL specifies a filter and scope, these are not used. Of the information specified in the URL, this method only uses the LDAP host name and port number, the base distinguished name (DN), and the list of attributes to return.
The method returns the entry specified by the base DN.
(Note: If you want to search for more than one entry, use the
search( LDAPUrl )
method instead.)
For example, the following section of code reads the entry specified by the LDAP URL.
String flatURL = "ldap://alway.mcom.com:3890/cn=Barbara Jenson,ou=Product Development,o=Ace Industry,c=US?cn,sn,mail"; LDAPUrl myURL; try { myURL = new LDAPUrl( flatURL ); } catch ( java.net.MalformedURLException e ) { System.out.println( "BAD URL!!! BAD, BAD, BAD URL!!!" ); return; } LDAPEntry myEntry = null; try { myEntry = myConn.read( myURL ); } catch ( LDAPException e ) { int errCode = e.getLDAPResultCode(); switch( errCode ) { case ( e.NO_SUCH_OBJECT ): System.out.println( "The specified entry " + myDN + " does not exist in the directory." ); return; default: System.out.println( "An internal error occurred." ); return; } }
toGet
- LDAP URL specifying the entry to readLDAPUrl
,
search(netscape.ldap.LDAPUrl)
public static LDAPSearchResults search(LDAPUrl toGet) throws LDAPException
For example, the following section of code searches for all entries under
the ou=Product Development,o=Ace Industry,c=US
subtree of a
directory. The example gets and prints the mail attribute for each entry
found.
String flatURL = "ldap://alway.mcom.com:3890/ou=Product Development,o=Ace Industry,c=US?mail?sub?objectclass=*"; LDAPUrl myURL; try { myURL = new LDAPUrl( flatURL ); } catch ( java.net.MalformedURLException e ) { System.out.println( "Incorrect URL syntax." ); return; } LDAPSearchResults myResults = null; try { myResults = myConn.search( myURL ); } catch ( LDAPException e ) { int errCode = e.getLDAPResultCode(); System.out.println( "LDAPException: return code:" + errCode ); return; } while ( myResults.hasMoreElements() ) { LDAPEntry myEntry = myResults.next(); String nextDN = myEntry.getDN(); System.out.println( nextDN ); LDAPAttributeSet entryAttrs = myEntry.getAttributeSet(); Enumeration attrsInSet = entryAttrs.getAttributes(); while ( attrsInSet.hasMoreElements() ) { LDAPAttribute nextAttr = (LDAPAttribute)attrsInSet.nextElement(); String attrName = nextAttr.getName(); System.out.print( "\t" + attrName + ": " ); Enumeration valsInAttr = nextAttr.getStringValues(); while ( valsInAttr.hasMoreElements() ) { String nextValue = (String)valsInAttr.nextElement(); System.out.println( nextValue ); } } }
To abandon the search, use the abandon
method.
toGet
- LDAP URL representing the search to performLDAPUrl
,
LDAPSearchResults
,
abandon(netscape.ldap.LDAPSearchResults)
public static LDAPSearchResults search(LDAPUrl toGet, LDAPSearchConstraints cons) throws LDAPException
As part of the search constraints, you can specify whether or not you want the results delivered all at once or in smaller batches. If you specify the results delivered in smaller batches, each iteration blocks until the next batch of results is returned.
For example, the following section of code retrieves the first 5 matching entries for the search specified by the LDAP URL. The example accomplishes this by creating a new set of search constraints where the maximum number of search results is 5.
LDAPSearchConstraints mySearchConstraints = myConn.getSearchConstraints(); mySearchConstraints.setMaxResults( 5 ); String flatURL = "ldap://alway.mcom.com:3890/ou=Product Development,o=Ace Industry,c=US?mail?sub?objectclass=*"; LDAPUrl myURL; try { myURL = new LDAPUrl( flatURL ); } catch ( java.net.MalformedURLException e ) { System.out.println( "Incorrect URL syntax." ); return; } LDAPSearchResults myResults = null; try { myResults = myConn.search( myURL, mySearchConstraints ); } catch ( LDAPException e ) { int errCode = e.getLDAPResultCode(); System.out.println( "LDAPException: return code:" + errCode ); return; }
To abandon the search, use the abandon
method.
toGet
- LDAP URL representing the search to runcons
- constraints specific to the searchLDAPUrl
,
LDAPSearchResults
,
abandon(netscape.ldap.LDAPSearchResults)
public LDAPSearchResults search(java.lang.String base, int scope, java.lang.String filter, java.lang.String[] attrs, boolean attrsOnly) throws LDAPException
For example, the following section of code searches for all entries under
the ou=Product Development,o=Ace Industry,c=US
subtree of a
directory. The example gets and prints the mail attribute for each entry
found.
String myBaseDN = "ou=Product Development,o=Ace Industry,c=US"; String myFilter="(objectclass=*)"; String[] myAttrs = { "mail" }; LDAPSearchResults myResults = null; try { myResults = myConn.search( myBaseDN, LDAPv2.SCOPE_SUB, myFilter, myAttrs, false ); } catch ( LDAPException e ) { int errCode = e.getLDAPResultCode(); System.out.println( "LDAPException: return code:" + errCode ); return; } while ( myResults.hasMoreElements() ) { LDAPEntry myEntry = myResults.next(); String nextDN = myEntry.getDN(); System.out.println( nextDN ); LDAPAttributeSet entryAttrs = myEntry.getAttributeSet(); Enumeration attrsInSet = entryAttrs.getAttributes(); while ( attrsInSet.hasMoreElements() ) { LDAPAttribute nextAttr = (LDAPAttribute)attrsInSet.nextElement(); String attrName = nextAttr.getName(); System.out.println( "\t" + attrName + ":" ); Enumeration valsInAttr = nextAttr.getStringValues(); while ( valsInAttr.hasMoreElements() ) { String nextValue = (String)valsInAttr.nextElement(); System.out.println( "\t\t" + nextValue ); } } }
To abandon the search, use the abandon
method.
base
- the base distinguished name from which to searchscope
- the scope of the entries to search. You can specify one
of the following:
LDAPv2.SCOPE_BASE
(search only the base DN)
LDAPv2.SCOPE_ONE
(search only entries under the base DN)
LDAPv2.SCOPE_SUB
(search the base DN and all entries within its subtree)
filter
- search filter specifying the search criteriaattrs
- list of attributes that you want returned in the
search resultsattrsOnly
- if true, returns the names but not the values of the
attributes found. If false, returns the names and values for
attributes foundabandon(netscape.ldap.LDAPSearchResults)
public LDAPSearchResults search(java.lang.String base, int scope, java.lang.String filter, java.lang.String[] attrs, boolean attrsOnly, LDAPSearchConstraints cons) throws LDAPException
As part of the search constraints, you can specify whether or not you want the results delivered all at once or in smaller batches. If you specify that you want the results delivered in smaller batches, each iteration blocks until the next batch of results is returned.
For example, the following section of code retrieves the first 5 entries matching the specified search criteria. The example accomplishes this by creating a new set of search constraints where the maximum number of search results is 5.
String myBaseDN = "ou=Product Development,o=Ace Industry,c=US"; String myFilter="(objectclass=*)"; String[] myAttrs = { "mail" }; LDAPSearchConstraints mySearchConstraints = myConn.getSearchConstraints(); mySearchConstraints.setMaxResults( 5 ); LDAPSearchResults myResults = null; try { myResults = myConn.search( myBaseDN, LDAPv2.SCOPE_SUB, myFilter, myAttrs, false, mySearchConstraints ); } catch ( LDAPException e ) { int errCode = e.getLDAPResultCode(); System.out.println( "LDAPException: return code:" + errCode ); return; }
To abandon the search, use the abandon
method.
base
- the base distinguished name from which to searchscope
- the scope of the entries to search. You can specify one
of the following:
LDAPv2.SCOPE_BASE
(search only the base DN)
LDAPv2.SCOPE_ONE
(search only entries under the base DN)
LDAPv2.SCOPE_SUB
(search the base DN and all entries within its subtree)
filter
- search filter specifying the search criteriaattrs
- list of attributes to return in the search
resultscons
- constraints specific to this search (for example, the
maximum number of entries to return)attrsOnly
- if true, returns the names but not the values of the
attributes found. If false, returns the names and values for
attributes foundabandon(netscape.ldap.LDAPSearchResults)
public boolean compare(java.lang.String DN, LDAPAttribute attr) throws LDAPException
true
if the entry has the value. Returns
false
if the entry does not have the value or the
attribute. To represent the value that you want compared, you need
to create an LDAPAttribute
object.Note that only string values can be compared.
For example, the following section of code checks to see if the entry "cn=Barbara Jensen,ou=Product Development,o=Ace Industry,c=US" contains the attribute "mail" with the value "bjensen@aceindustry.com".
... LDAPConnection myConn = new LDAPConnection(); ... String myDN = "cn=Barbara Jensen,ou=Product Development,o=Ace Industry,c=US"; String nameOfAttr = "mail"; String valOfAttr = "bjensen@aceindustry.com"; LDAPAttribute cmpThisAttr = new LDAPAttribute( nameOfAttr, valOfAttr ); boolean hasValue = myConn.compare( myDN, cmpThisAttr ); if ( hasValue ) { System.out.println( "Attribute and value found in entry." ); } else { System.out.println( "Attribute and value not found in entry." ); } ...
DN
- the distinguished name of the entry to use in
the comparisonattr
- the attribute to compare against the entry.
(The method checks to see if the entry has an attribute with the same name
and value as this attribute.)LDAPAttribute
public boolean compare(java.lang.String DN, LDAPAttribute attr, LDAPConstraints cons) throws LDAPException
DN
- distinguished name of the entry that you want compared
against the specified attribute valueattr
- attribute name and value to use in the comparisoncons
- the constraints set for the compare operationpublic boolean compare(java.lang.String DN, LDAPAttribute attr, LDAPSearchConstraints cons) throws LDAPException
cons
is
LDAPConstraints
instead of LDAPSearchConstraints
public void add(LDAPEntry entry) throws LDAPException
Before using this method, you need to create an
LDAPEntry
object and use it to specify the
distinguished name and attributes of the new entry. Make sure
to specify values for all required attributes in the
entry. If all required attributes are not specified and the LDAP server
checks the entry against the schema, an LDAPException
may be thrown (where the LDAP result code is
OBJECT_CLASS_VIOLATION
).
For example, the following section of code creates an
LDAPEntry
object for a new entry and uses the object
to add the new entry to the directory. Because the definition of
the LDAP inetOrgPerson
class specifies that the
cn
, sn
, and objectclass
attributes are required, these attributes are specified as part
of the new entry. (mail
is not required but is shown
here as an example of specifying additional attributes.)
... String myDN = "cn=Barbara Jensen,ou=Product Development,o=Ace Industry,c=US"; LDAPAttribute attr1 = new LDAPAttribute( "cn", "Barbara Jensen" ); LDAPAttribute attr2 = new LDAPAttribute( "sn", "Jensen" ); LDAPAttribute attr3 = new LDAPAttribute( "objectclass", "top" ); LDAPAttribute attr4 = new LDAPAttribute( "objectclass", "person" ); LDAPAttribute attr5 = new LDAPAttribute( "objectclass", "organizationalPerson" ); LDAPAttribute attr6 = new LDAPAttribute( "objectclass", "inetOrgPerson" ); LDAPAttribute attr7 = new LDAPAttribute( "mail", "bjensen@aceindustry.com" ); LDAPAttributeSet myAttrs = new LDAPAttributeSet(); myAttrs.add( attr1 ); myAttrs.add( attr2 ); myAttrs.add( attr3 ); myAttrs.add( attr4 ); myAttrs.add( attr5 ); myAttrs.add( attr6 ); myAttrs.add( attr7 ); LDAPEntry myEntry = new LDAPEntry( myDN, myAttrs ); myConn.add( myEntry ); ...
entry
- LDAPEntry object specifying the distinguished name and
attributes of the new entryLDAPEntry
public void add(LDAPEntry entry, LDAPConstraints cons) throws LDAPException
LDAPConstraints
object. For
example, you can specify whether or not to follow referrals.
You can also apply LDAP v3 controls to the operation.
entry
- LDAPEntry object specifying the distinguished name and
attributes of the new entrycons
- the set of preferences to apply to this operationLDAPEntry
,
LDAPConstraints
public void add(LDAPEntry entry, LDAPSearchConstraints cons) throws LDAPException
cons
is
LDAPConstraints
instead of LDAPSearchConstraints
public LDAPExtendedOperation extendedOperation(LDAPExtendedOperation op) throws LDAPException
Note that in order for the extended operation to work, the server that you are connecting to must support LDAP v3 and must be configured to process the specified extended operation.
op
- LDAPExtendedOperation object specifying the OID of the
extended operation and the data to use in the operationLDAPExtendedOperation
public LDAPExtendedOperation extendedOperation(LDAPExtendedOperation op, LDAPConstraints cons) throws LDAPException
Note that in order for the extended operation to work, the server that you are connecting to must support LDAP v3 and must be configured to process the specified extended operation.
op
- LDAPExtendedOperation object specifying the OID of the
extended operation and the data to use in the operationcons
- preferences for the extended operationLDAPExtendedOperation
public LDAPExtendedOperation extendedOperation(LDAPExtendedOperation op, LDAPSearchConstraints cons) throws LDAPException
cons
is
LDAPConstraints
instead of LDAPSearchConstraints
public void modify(java.lang.String DN, LDAPModification mod) throws LDAPException
Use the LDAPModification
object to specify the change
to make and the LDAPAttribute
object
to specify the attribute value to change. The
LDAPModification
object allows you add an attribute
value, change an attibute value, or remove an attribute
value.
For example, the following section of code changes Barbara Jensen's email address in the directory to babs@aceindustry.com.
... String myEntryDN = "cn=Barbara Jensen,ou=Product Development,o=Ace Industry,c=US"; LDAPAttribute attrEmail = new LDAPAttribute( "mail", "babs@aceindustry.com" ); LDAPModification singleChange = new LDAPModification( LDAPModification.REPLACE, attrEmail ); myConn.modify( myEntryDN, singleChange ); ...
DN
- the distinguished name of the entry to modifymod
- a single change to make to the entryLDAPModification
public void modify(java.lang.String DN, LDAPModification mod, LDAPConstraints cons) throws LDAPException
LDAPConstraints
object. For
example, you can specify whether or not to follow referrals.
You can also apply LDAP v3 controls to the operation.
DN
- the distinguished name of the entry to modifymod
- a single change to make to the entrycons
- the set of preferences to apply to this operationLDAPModification
,
LDAPConstraints
public void modify(java.lang.String DN, LDAPModification mod, LDAPSearchConstraints cons) throws LDAPException
cons
is
LDAPConstraints
instead of LDAPSearchConstraints
public void modify(java.lang.String DN, LDAPModificationSet mods) throws LDAPException
Use the LDAPModificationSet
object to specify the set
of changes to make. Changes are specified in terms
of attribute values. You must specify each attribute value to modify, add,
or remove by an LDAPAttribute
object.
For example, the following section of code changes Barbara Jensen's title, adds a telephone number to the entry, and removes the room number from the entry.
... String myEntryDN = "cn=Barbara Jensen,ou=Product Development,o=Ace Industry,c=US"; LDAPModificationSet manyChanges = new LDAPModificationSet(); LDAPAttribute attrTelephoneNumber = new LDAPAttribute( "telephoneNumber", "555-1212" ); manyChanges.add( LDAPModification.ADD, attrTelephoneNumber ); LDAPAttribute attrRoomNumber = new LDAPAttribute( "roomnumber", "222" ); manyChanges.add( LDAPModification.DELETE, attrRoomNumber ); LDAPAttribute attrTitle = new LDAPAttribute( "title", "Manager of Product Development" ); manyChanges.add( LDAPModification.REPLACE, attrTitle ); myConn.modify( myEntryDN, manyChanges ); ...
DN
- the distinguished name of the entry to modifymods
- a set of changes to make to the entryLDAPModificationSet
public void modify(java.lang.String DN, LDAPModificationSet mods, LDAPConstraints cons) throws LDAPException
LDAPConstraints
object. For
example, you can specify whether or not to follow referrals.
You can also apply LDAP v3 controls to the operation.
DN
- the distinguished name of the entry to modifymods
- a set of changes to make to the entrycons
- the set of preferences to apply to this operationLDAPModificationSet
,
LDAPConstraints
public void modify(java.lang.String DN, LDAPModificationSet mods, LDAPSearchConstraints cons) throws LDAPException
cons
is
LDAPConstraints
instead of LDAPSearchConstraints
public void modify(java.lang.String DN, LDAPModification[] mods) throws LDAPException
Use an array of LDAPModification
objects to specify the
changes to make. Each change must be specified by
an LDAPModification
object, and you must specify each
attribute value to modify, add, or remove by an LDAPAttribute
object.
DN
- the distinguished name of the entry to modifymods
- an array of objects representing the changes to make
to the entryLDAPModification
public void modify(java.lang.String DN, LDAPModification[] mods, LDAPConstraints cons) throws LDAPException
LDAPConstraints
object. For
example, you can specify whether or not to follow referrals.
You can also apply LDAP v3 controls to the operation.
DN
- the distinguished name of the entry to modifymods
- an array of objects representing the changes to make
to the entrycons
- the set of preferences to apply to this operationLDAPModification
,
LDAPConstraints
public void modify(java.lang.String DN, LDAPModification[] mods, LDAPSearchConstraints cons) throws LDAPException
cons
is
LDAPConstraints
instead of LDAPSearchConstraints
public void delete(java.lang.String DN) throws LDAPException
For example, the following section of code deletes the entry for Barbara Jensen from the directory.
... String myEntryDN = "cn=Barbara Jensen,ou=Product Development,o=Ace Industry,c=US"; myConn.delete( myEntryDN ); ...
DN
- distinguished name identifying the entry
to remove from the directorypublic void delete(java.lang.String DN, LDAPConstraints cons) throws LDAPException
LDAPConstraints
object. For
example, you can specify whether or not to follow referrals.
You can also apply LDAP v3 controls to the operation.
DN
- distinguished name identifying the entry
to remove from the directorycons
- the set of preferences to apply to this operationLDAPConstraints
public void delete(java.lang.String DN, LDAPSearchConstraints cons) throws LDAPException
cons
is
LDAPConstraints
instead of LDAPSearchConstraints
public void rename(java.lang.String DN, java.lang.String newRDN, boolean deleteOldRDN) throws LDAPException
You can specify whether or not the original name of the entry is retained as a value in the entry. For example, suppose you rename the entry "cn=Barbara" to "cn=Babs". You can keep "cn=Barbara" as a value in the entry so that the cn attribute has two values:
cn=Barbara cn=BabsThe following example renames an entry. The old name of the entry is kept as a value in the entry.
... String myEntryDN = "cn=Barbara Jensen,ou=Product Development,o=Ace Industry,c=US"; String newRDN = "cn=Babs Jensen"; myConn.rename( myEntryDN, newRDN, false ); ...
DN
- current distinguished name of the entrynewRDN
- new relative distinguished name for the entry (for example,
"cn=newName")deleteOldRDN
- if true
, the old name is not retained
as an attribute value (for example, the attribute value "cn=oldName" is
removed). If false
, the old name is retained
as an attribute value (for example, the entry might now have two values
for the cn attribute: "cn=oldName" and "cn=newName").public void rename(java.lang.String DN, java.lang.String newRDN, boolean deleteOldRDN, LDAPConstraints cons) throws LDAPException
You can specify whether or not the original name of the entry is retained as a value in the entry. For example, suppose you rename the entry "cn=Barbara" to "cn=Babs". You can keep "cn=Barbara" as a value in the entry so that the cn attribute has two values:
cn=Barbara cn=BabsThe following example renames an entry. The old name of the entry is kept as a value in the entry.
... String myEntryDN = "cn=Barbara Jensen,ou=Product Development,o=Ace Industry,c=US"; String newRDN = "cn=Babs Jensen"; myConn.rename( myEntryDN, newRDN, false ); ...
DN
- current distinguished name of the entrynewRDN
- new relative distinguished name for the entry (for example,
"cn=newName")deleteOldRDN
- if true
, the old name is not retained
as an attribute value (for example, the attribute value "cn=oldName" is
removed). If false
, the old name is retained
as an attribute value (for example, the entry might now have two values
for the cn attribute: "cn=oldName" and "cn=newName").cons
- the set of preferences to apply to this operationpublic void rename(java.lang.String DN, java.lang.String newRDN, boolean deleteOldRDN, LDAPSearchConstraints cons) throws LDAPException
cons
is
LDAPConstraints
instead of LDAPSearchConstraints
public void rename(java.lang.String dn, java.lang.String newRDN, java.lang.String newParentDN, boolean deleteOldRDN) throws LDAPException
NOTE: Netscape Directory Server 3.0 does not support the
capability to move an entry to a different location in the
directory tree. If you specify a value for the newParentDN
argument, an LDAPException
will be thrown.
DN
- current distinguished name of the entrynewRDN
- new relative distinguished name for the entry (for example,
"cn=newName")newParentDN
- if not null, the distinguished name for the
entry under which the entry should be moved (for example, to move
an entry under the Accounting subtree, specify this argument as
"ou=Accounting, o=Ace Industry, c=US")deleteOldRDN
- if true
, the old name is not retained
as an attribute value (for example, the attribute value "cn=oldName" is
removed). If false
, the old name is retained
as an attribute value (for example, the entry might now have two values
for the cn attribute: "cn=oldName" and "cn=newName").public void rename(java.lang.String DN, java.lang.String newRDN, java.lang.String newParentDN, boolean deleteOldRDN, LDAPConstraints cons) throws LDAPException
LDAPConstraints
object. For
example, you can specify whether or not to follow referrals.
You can also apply LDAP v3 controls to the operation.
NOTE: Netscape Directory Server 3.0 does not support the
capability to move an entry to a different location in the
directory tree. If you specify a value for the newParentDN
argument, an LDAPException
will be thrown.
DN
- current distinguished name of the entrynewRDN
- new relative distinguished name for the entry (for example,
"cn=newName")newParentDN
- if not null, the distinguished name for the
entry under which the entry should be moved (for example, to move
an entry under the Accounting subtree, specify this argument as
"ou=Accounting, o=Ace Industry, c=US")deleteOldRDN
- if true
, the old name is not retained
as an attribute value (for example, the attribute value "cn=oldName" is
removed). If false
, the old name is retained
as an attribute value (for example, the entry might now have two values
for the cn attribute: "cn=oldName" and "cn=newName").cons
- the set of preferences to apply to this operationLDAPConstraints
public void rename(java.lang.String DN, java.lang.String newRDN, java.lang.String newParentDN, boolean deleteOldRDN, LDAPSearchConstraints cons) throws LDAPException
cons
is
LDAPConstraints
instead of LDAPSearchConstraints
public LDAPResponseListener add(LDAPEntry entry, LDAPResponseListener listener) throws LDAPException
entry
- LDAPEntry object specifying the distinguished name and
attributes of the new entrylistener
- handler for messages returned from a server in response
to this request. If it is null, a listener object is created internally.cons
- constraints specific to the operationLDAPEntry
,
LDAPResponseListener
public LDAPResponseListener add(LDAPEntry entry, LDAPResponseListener listener, LDAPConstraints cons) throws LDAPException
LDAPConstraints
object. For example, you can specify whether or not to follow referrals.
You can also apply LDAP v3 controls to the operation.
entry
- LDAPEntry object specifying the distinguished name and
attributes of the new entrylistener
- handler for messages returned from a server in response
to this request. If it is null, a listener object is created internally.cons
- constraints specific to the operationLDAPEntry
,
LDAPResponseListener
,
LDAPConstraints
public LDAPResponseListener bind(int version, java.lang.String dn, java.lang.String passwd, LDAPResponseListener listener) throws LDAPException
version
- required LDAP protocol versiondn
- if non-null and non-empty, specifies that the connection
and all operations through it should authenticate with dn as the
distinguished namepasswd
- if non-null and non-empty, specifies that the connection
and all operations through it should authenticate with dn as the
distinguished name and passwd as passwordlistener
- handler for messages returned from a server in response
to this request. If it is null, a listener object is created internally.LDAPResponseListener
public LDAPResponseListener bind(java.lang.String dn, java.lang.String passwd, LDAPResponseListener listener) throws LDAPException
dn
- if non-null and non-empty, specifies that the connection
and all operations through it should authenticate with dn as the
distinguished namepasswd
- if non-null and non-empty, specifies that the connection
and all operations through it should authenticate with dn as the
distinguished name and passwd as passwordlistener
- handler for messages returned from a server in response
to this request. If it is null, a listener object is created internally.LDAPResponseListener
public LDAPResponseListener bind(java.lang.String dn, java.lang.String passwd, LDAPResponseListener listener, LDAPConstraints cons) throws LDAPException
LDAPConstraints
object. If the object
has been disconnected from an LDAP server, this method attempts to
reconnect to the server. If the object had already authenticated, the
old authentication is discarded.dn
- if non-null and non-empty, specifies that the connection
and all operations through it should authenticate with dn as the
distinguished namepasswd
- if non-null and non-empty, specifies that the connection
and all operations through it should authenticate with dn as the
distinguished name and passwd as passwordlistener
- handler for messages returned from a server in response
to this request. If it is null, a listener object is created internally.cons
- constraints specific to the operationLDAPResponseListener
,
LDAPConstraints
public LDAPResponseListener bind(int version, java.lang.String dn, java.lang.String passwd, LDAPResponseListener listener, LDAPConstraints cons) throws LDAPException
LDAPConstraints
object. If the object
has been disconnected from an LDAP server, this method attempts to
reconnect to the server. If the object had already authenticated, the
old authentication is discarded.version
- required LDAP protocol versiondn
- if non-null and non-empty, specifies that the connection
and all operations through it should authenticate with dn as the
distinguished namepasswd
- if non-null and non-empty, specifies that the connection
and all operations through it should authenticate with dn as the
distinguished name and passwd as passwordlistener
- handler for messages returned from a server in response
to this request. If it is null, a listener object is created internally.cons
- constraints specific to the operationLDAPResponseListener
,
LDAPConstraints
public LDAPResponseListener delete(java.lang.String dn, LDAPResponseListener listener) throws LDAPException
dn
- distinguished name of the entry to deletelistener
- handler for messages returned from a server in response
to this request. If it is null, a listener object is created internally.LDAPResponseListener
,
LDAPConstraints
public LDAPResponseListener delete(java.lang.String dn, LDAPResponseListener listener, LDAPConstraints cons) throws LDAPException
dn
- distinguished name of the entry to deletelistener
- handler for messages returned from a server in response
to this request. If it is null, a listener object is created internally.cons
- constraints specific to the operationLDAPResponseListener
,
LDAPConstraints
public LDAPResponseListener modify(java.lang.String dn, LDAPModification mod, LDAPResponseListener listener) throws LDAPException
dn
- distinguished name of the entry to modifymod
- a single change to make to an entrylistener
- handler for messages returned from a server in response
to this request. If it is null, a listener object is created internally.LDAPModification
,
LDAPResponseListener
public LDAPResponseListener modify(java.lang.String dn, LDAPModification mod, LDAPResponseListener listener, LDAPConstraints cons) throws LDAPException
dn
- distinguished name of the entry to modifymod
- a single change to make to an entrylistener
- handler for messages returned from a server in response
to this request. If it is null, a listener object is created internally.cons
- constraints specific to the operationLDAPModification
,
LDAPResponseListener
,
LDAPConstraints
public LDAPResponseListener modify(java.lang.String dn, LDAPModificationSet mods, LDAPResponseListener listener) throws LDAPException
dn
- distinguished name of the entry to modifymods
- a set of changes to make to the entrylistener
- handler for messages returned from a server in response
to this request. If it is null, a listener object is created internally.LDAPModificationSet
,
LDAPResponseListener
public LDAPResponseListener modify(java.lang.String dn, LDAPModificationSet mods, LDAPResponseListener listener, LDAPConstraints cons) throws LDAPException
dn
- distinguished name of the entry to modifymods
- a set of changes to make to the entrylistener
- handler for messages returned from a server in response
to this request. If it is null, a listener object is created internally.cons
- Constraints specific to the operationLDAPModificationSet
,
LDAPResponseListener
,
LDAPConstraints
public LDAPResponseListener rename(java.lang.String dn, java.lang.String newRdn, boolean deleteOldRdn, LDAPResponseListener listener) throws LDAPException
dn
- current distinguished name of the entrynewRdn
- new relative distinguished name for the entrydeleteOldRdn
- if true, the old name is not retained as an
attribute valuelistener
- handler for messages returned from a server in response
to this request. If it is null, a listener object is created internally.LDAPResponseListener
public LDAPResponseListener rename(java.lang.String dn, java.lang.String newRdn, boolean deleteOldRdn, LDAPResponseListener listener, LDAPConstraints cons) throws LDAPException
dn
- current distinguished name of the entrynewRdn
- new relative distinguished name for the entrydeleteOldRdn
- if true, the old name is not retained as an attribute
valuelistener
- handler for messages returned from a server in response
to this request. If it is null, a listener object is created internally.cons
- constraints specific to the operationLDAPResponseListener
,
LDAPConstraints
public LDAPSearchListener search(java.lang.String base, int scope, java.lang.String filter, java.lang.String[] attrs, boolean typesOnly, LDAPSearchListener listener) throws LDAPException
To abandon the search, use the abandon
method.
base
- the base distinguished name from which to searchscope
- the scope of the entries to search. You can specify one
of the following:
LDAPv2.SCOPE_BASE
(search only the base DN)
LDAPv2.SCOPE_ONE
(search only entries under the base DN)
LDAPv2.SCOPE_SUB
(search the base DN and all entries within its subtree)
filter
- search filter specifying the search criteriaattrs
- list of attributes that you want returned in the
search resultstypesOnly
- if true, returns the names but not the values of the
attributes found. If false, returns the names and values for
attributes foundlistener
- handler for messages returned from a server in response
to this request. If it is null, a listener object is created internally.abandon(netscape.ldap.LDAPSearchListener)
public LDAPSearchListener search(java.lang.String base, int scope, java.lang.String filter, java.lang.String[] attrs, boolean typesOnly, LDAPSearchListener listener, LDAPSearchConstraints cons) throws LDAPException
To abandon the search, use the abandon
method.
base
- the base distinguished name from which to searchscope
- the scope of the entries to search. You can specify one
of the following:
LDAPv2.SCOPE_BASE
(search only the base DN)
LDAPv2.SCOPE_ONE
(search only entries under the base DN)
LDAPv2.SCOPE_SUB
(search the base DN and all entries within its subtree)
filter
- search filter specifying the search criteriaattrs
- list of attributes that you want returned in the search
resultstypesOnly
- if true, returns the names but not the values of the
attributes found. If false, returns the names and values for
attributes found.listener
- handler for messages returned from a server in response
to this request. If it is null, a listener object is created internally.cons
- constraints specific to this search (for example, the
maximum number of entries to return)abandon(netscape.ldap.LDAPSearchListener)
public LDAPResponseListener compare(java.lang.String dn, LDAPAttribute attr, LDAPResponseListener listener) throws LDAPException
getResultCode
on the
LDAPResponse
from the LDAPResponseListener
.
The code will be LDAPException.COMPARE_TRUE
or
LDAPException.COMPARE_FALSE
.dn
- distinguished name of the entry to compareattr
- attribute with a value to comparelistener
- handler for messages returned from a server in response
to this request. If it is null, a listener object is created internally.public LDAPResponseListener compare(java.lang.String dn, LDAPAttribute attr, LDAPResponseListener listener, LDAPConstraints cons) throws LDAPException
getResultCode
on the
LDAPResponse
from the LDAPResponseListener
.
The code will be LDAPException.COMPARE_TRUE
or
LDAPException.COMPARE_FALSE
.dn
- distinguished name of the entry to compareattr
- attribute with a value to comparelistener
- handler for messages returned from a server in response
to this request. If it is null, a listener object is created internally.cons
- constraints specific to this operationpublic void abandon(int id) throws LDAPException
id
- an LDAP request idpublic void abandon(LDAPSearchListener searchlistener) throws LDAPException
searchlistener
- a search listener returned from a searchpublic java.lang.Object getOption(int option) throws LDAPException
LDAPConnection
object.
These options represent the constraints for the current connection.
To get all constraints for the current connection, call the
getSearchConstraints
method.
By default, the constraints apply to all operations performed through the current connection. You can change these constraints:
LDAPConstraints
object (or a
LDAPSearchConstraints
object for a search or find operation)
with your new constraints
and pass it to the LDAPConnection
method that performs the
operation.
setOption
method to change the constraint.
For example, the following section of code gets and prints the
maximum number of search results that are returned for searches
performed through this connection. (This applies to all searches
unless a different set of search constraints is specified in an
LDAPSearchConstraints
object.)
LDAPConnection ld = new LDAPConnection(); int sizeLimit = ( (Integer)ld.getOption( LDAPv2.SIZELIMIT ) ).intValue(); System.out.println( "Maximum number of results: " + sizeLimit );
option
- you can specify one of the following options:
Option | Data Type | Description |
---|---|---|
LDAPv2.PROTOCOL_VERSION |
Integer |
Specifies the version of the LDAP protocol used by the
client.
By default, the value of this option is 2. |
LDAPv2.DEREF |
Integer |
Specifies when your client dereferences aliases.
Legal values for this option are: DEREF_NEVER Aliases are never dereferenced. DEREF_FINDING Aliases are dereferenced when find- ing the starting point for the search (but not when searching under that starting entry). DEREF_SEARCHING Aliases are dereferenced when searching the entries beneath the starting point of the search (but not when finding the starting entry). DEREF_ALWAYS Aliases are always dereferenced. By default, the value of this option is
|
LDAPv2.SIZELIMIT |
Integer |
Specifies the maximum number of search results to return.
If this option is set to 0, there is no maximum limit.
By default, the value of this option is 1000. |
LDAPv2.TIMELIMIT |
Integer |
Specifies the maximum number of milliseconds to wait for results
before timing out. If this option is set to 0, there is no maximum
time limit.
By default, the value of this option is 0. |
LDAPv2.REFERRALS |
Boolean |
Specifies whether or not your client follows referrals automatically.
If true , your client follows referrals automatically.
If false , an LDAPReferralException is raised
when referral is detected.
By default, the value of this option is |
LDAPv2.REFERRALS_REBIND_PROC |
LDAPRebind |
Specifies an object with a class that implements the
LDAPRebind interface. You must define this class and
the getRebindAuthentication method that will be used to
get the distinguished name and password to use for authentication.
Modifying this option sets the LDAPv2.BIND option to null.
By default, the value of this option is |
LDAPv2.BIND>/CODE> |
LDAPBind |
Specifies an object with a class that implements the
LDAPBind
interface. You must define this class and the
bind method that will be used to authenticate
to the server on referrals. Modifying this option sets the
LDAPv2.REFERRALS_REBIND_PROC to null.
By default, the value of this option is |
LDAPv2.REFERRALS_HOP_LIMIT |
Integer |
Specifies the maximum number of referrals in a sequence that
your client will follow. (For example, if REFERRALS_HOP_LIMIT is 5,
your client will follow no more than 5 referrals in a row when resolving
a single LDAP request.)
By default, the value of this option is 10. |
LDAPv2.BATCHSIZE |
Integer |
Specifies the number of search results to return at a time.
(For example, if BATCHSIZE is 1, results are returned one at a time.)
By default, the value of this option is 1. |
LDAPv3.CLIENTCONTROLS |
LDAPControl[] |
Specifies the client controls that may affect the handling of LDAP operations in the LDAP classes. These controls are used by the client and are not passed to the LDAP server. At this time, no client controls are defined for clients built with the Netscape LDAP classes. |
LDAPv3.SERVERCONTROLS |
LDAPControl[] |
Specifies the server controls that are passed to the LDAP server on each LDAP operation. Not all servers support server controls; a particular server may or may not support a given server control. |
MAXBACKLOG |
Integer |
Specifies the maximum number of search results to accumulate in an
LDAPSearchResults before suspending the reading of input from the server.
By default, the value of this option is 100. |
Integer
.)LDAPRebind
,
LDAPConstraints
,
LDAPSearchConstraints
,
LDAPReferralException
,
LDAPControl
,
getSearchConstraints()
,
search(java.lang.String, int, java.lang.String, java.lang.String[], boolean, netscape.ldap.LDAPSearchConstraints)
public void setOption(int option, java.lang.Object value) throws LDAPException
LDAPConnection
object.
These options represent the constraints for the current
connection.
To get all constraints for the current connection, call the
getSearchConstraints
method.
By default, the option that you set applies to all subsequent
operations performed through the current connection. If you want to
set a constraint only for a particular operation, create an
LDAPConstraints
object (or a
LDAPSearchConstraints
object for a search or find operation)
with your new constraints
and pass it to the LDAPConnection
method that performs the
operation.
For example, the following section of code changes the constraint for
the maximum number of search results that are returned for searches
performed through this connection. (This applies to all searches
unless a different set of search constraints is specified in an
LDAPSearchConstraints
object.)
LDAPConnection ld = new LDAPConnection(); Integer newLimit = new Integer( 20 ); ld.setOption( LDAPv2.SIZELIMIT, newLimit ); System.out.println( "Changed the maximum number of results to " + newLimit.intValue() );
option
- you can specify one of the following options:
Option | Data Type | Description |
---|---|---|
LDAPv2.PROTOCOL_VERSION |
Integer |
Specifies the version of the LDAP protocol used by the
client.
By default, the value of this option is 2. If you want to use LDAP v3 features (such as extended operations or controls), you need to set this value to 3. |
LDAPv2.DEREF |
Integer |
Specifies when your client dereferences aliases.
Legal values for this option are: DEREF_NEVER Aliases are never dereferenced. DEREF_FINDING Aliases are dereferenced when find- ing the starting point for the search (but not when searching under that starting entry). DEREF_SEARCHING Aliases are dereferenced when searching the entries beneath the starting point of the search (but not when finding the starting entry). DEREF_ALWAYS Aliases are always dereferenced. By default, the value of this option is
|
LDAPv2.SIZELIMIT |
Integer |
Specifies the maximum number of search results to return.
If this option is set to 0, there is no maximum limit.
By default, the value of this option is 1000. |
LDAPv2.TIMELIMIT |
Integer |
Specifies the maximum number of milliseconds to wait for results
before timing out. If this option is set to 0, there is no maximum
time limit.
By default, the value of this option is 0. |
LDAPv2.REFERRALS |
Boolean |
Specifies whether or not your client follows referrals automatically.
If true , your client follows referrals automatically.
If false , an LDAPReferralException is
raised when a referral is detected.
By default, the value of this option is |
LDAPv2.REFERRALS_REBIND_PROC |
LDAPRebind |
Specifies an object with a class that implements the
LDAPRebind
interface. You must define this class and the
getRebindAuthentication method that will be used to get
the distinguished name and password to use for authentication.
Modifying this option sets the LDAPv2.BIND option to null.
By default, the value of this option is |
LDAPv2.BIND>/CODE> |
LDAPBind |
Specifies an object with a class that implements the
LDAPBind
interface. You must define this class and the
bind method that will be used to autheniticate
to the server on referrals. Modifying this option sets the
LDAPv2.REFERRALS_REBIND_PROC to null.
By default, the value of this option is |
LDAPv2.REFERRALS_HOP_LIMIT |
Integer |
Specifies the maximum number of referrals in a sequence that
your client will follow. (For example, if REFERRALS_HOP_LIMIT is 5,
your client will follow no more than 5 referrals in a row when resolving
a single LDAP request.)
By default, the value of this option is 10. |
LDAPv2.BATCHSIZE |
Integer |
Specifies the number of search results to return at a time.
(For example, if BATCHSIZE is 1, results are returned one at a time.)
By default, the value of this option is 1. |
LDAPv3.CLIENTCONTROLS |
LDAPControl[] |
Specifies the client controls that may affect handling of LDAP operations in the LDAP classes. These controls are used by the client and are not passed to the server. At this time, no client controls are defined for clients built with the Netscape LDAP classes. |
LDAPv3.SERVERCONTROLS |
LDAPControl[] |
Specifies the server controls that are passed to the LDAP server on each LDAP operation. Not all servers support server controls; a particular server may or may not support a particular control. |
MAXBACKLOG |
Integer |
Specifies the maximum number of search results to accumulate in an
LDAPSearchResults before suspending the reading of input from the server.
By default, the value of this option is 100. |
value
- the value to assign to the option. The value must be
the java.lang object wrapper for the appropriate parameter
(e.g. boolean->Boolean,
integer->Integer)LDAPRebind
,
LDAPConstraints
,
LDAPSearchConstraints
,
LDAPReferralException
,
LDAPControl
,
getSearchConstraints()
,
search(java.lang.String, int, java.lang.String, java.lang.String[], boolean, netscape.ldap.LDAPSearchConstraints)
public LDAPControl[] getResponseControls()
To retrieve the controls from a search result, call the
getResponseControls
method from the LDAPSearchResults
object returned with the result.
LDAPControl
,
LDAPSearchResults.getResponseControls()
public LDAPConstraints getConstraints()
Note that if you want to get individual constraints (rather than
getting the
entire set of constraints), call the getOption
method.
Typically, you might call the getConstraints
method
to create a slightly different set of constraints for a particular
operation.
For example, the following section of code changes the timeout to 3000 milliseconds for a specific rename. Rather than construct a new set of constraints from scratch, the example gets the current settings for the connections and just changes the setting for the timeout.
Note that this change only applies to the searches performed with this custom set of constraints. All other searches performed through this connection use the original set of search constraints.
... LDAPConstraints myOptions = ld.getConstraints(); myOptions.setTimeout( 3000 ); ld.search( "cn=William Jensen, ou=Accounting, o=Ace Industry,c=US", "cn=Will Jensen", null, false, myOptions ); ...
LDAPConstraints
object representing the
set of constraints that apply (by default) to all operations
performed through this connection.LDAPConstraints
,
getOption(int)
public LDAPSearchConstraints getSearchConstraints()
search
method).
Note that if you want to get individual constraints (rather than
getting the
entire set of constraints), call the getOption
method.
Typically, you might call the getSearchConstraints
method
to create a slightly different set of search constraints
to apply to a particular search.
For example, the following section of code changes the maximum number of results to 10 for a specific search. Rather than construct a new set of search constraints from scratch, the example gets the current settings for the connections and just changes the setting for the maximum results.
Note that this change only applies to the searches performed with this custom set of constraints. All other searches performed through this connection use the original set of search constraints.
... LDAPSearchConstraints myOptions = ld.getSearchConstraints(); myOptions.setMaxResults( 10 ); String[] myAttrs = { "objectclass" }; LDAPSearchResults myResults = ld.search( "o=Ace Industry,c=US", LDAPv2.SCOPE_SUB, "(objectclass=*)", myAttrs, false, myOptions ); ...
LDAPSearchConstraints
object
representing the set of search constraints that apply (by default) to
all searches performed through this connection.LDAPSearchConstraints
,
getOption(int)
,
search(java.lang.String, int, java.lang.String, java.lang.String[], boolean, netscape.ldap.LDAPSearchConstraints)
public void setConstraints(LDAPConstraints cons)
cons
- LDAPConstraints
object to use as the default
constraint setgetConstraints()
,
LDAPConstraints
public void setSearchConstraints(LDAPSearchConstraints cons)
cons
- LDAPSearchConstraints
object to use as the
default constraint setgetSearchConstraints()
,
LDAPSearchConstraints
public java.io.InputStream getInputStream()
null
if there is nonepublic void setInputStream(java.io.InputStream is)
is
- the stream for reading from the listener socketpublic java.io.OutputStream getOutputStream()
null
if there is nonepublic void setOutputStream(java.io.OutputStream os)
os
- the stream for writing to the socket, if there is onepublic java.lang.Object clone()
LDAPConnection
object that
contains the same information as the current connection, including:
LDAPconnection
object representing the
new object.public static boolean isNetscape()
true if the class is running in a Netscape browser.
public static void main(java.lang.String[] args)
java netscape.ldap.LDAPConnection
args
- not currently used
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |