@Mutable @NotExtensible @ThreadSafety(level=NOT_THREADSAFE) public class LDAPConnection extends java.lang.Object
LDAPConnection
class should be used instead.Modifier and Type | Field and Description |
---|---|
static int |
DEREF_ALWAYS
The integer value for the DEREF_ALWAYS dereference policy.
|
static int |
DEREF_FINDING
The integer value for the DEREF_FINDING dereference policy.
|
static int |
DEREF_NEVER
The integer value for the DEREF_NEVER dereference policy.
|
static int |
DEREF_SEARCHING
The integer value for the DEREF_SEARCHING dereference policy.
|
static int |
SCOPE_BASE
The integer value for the SCOPE_BASE search scope.
|
static int |
SCOPE_ONE
The integer value for the SCOPE_ONE search scope.
|
static int |
SCOPE_SUB
The integer value for the SCOPE_SUB search scope.
|
Constructor and Description |
---|
LDAPConnection()
Creates a new LDAP connection which will use the default socket factory.
|
LDAPConnection(LDAPSocketFactory socketFactory)
Creates a new LDAP connection which will use the provided socket factory.
|
Modifier and Type | Method and Description |
---|---|
void |
abandon(int id)
Sends a request to abandon the request with the specified message ID.
|
void |
abandon(LDAPSearchResults searchResults)
Sends a request to abandon the provided search operation.
|
void |
add(LDAPEntry entry)
Adds the provided entry to the directory.
|
void |
add(LDAPEntry entry,
LDAPConstraints constraints)
Adds the provided entry to the directory.
|
void |
authenticate(int version,
java.lang.String dn,
java.lang.String password)
Authenticates to the directory server using a simple bind with the provided
information.
|
void |
authenticate(int version,
java.lang.String dn,
java.lang.String password,
LDAPConstraints constraints)
Authenticates to the directory server using a simple bind with the provided
information.
|
void |
authenticate(java.lang.String dn,
java.lang.String password)
Authenticates to the directory server using a simple bind with the provided
information.
|
void |
authenticate(java.lang.String dn,
java.lang.String password,
LDAPConstraints constraints)
Authenticates to the directory server using a simple bind with the provided
information.
|
void |
bind(int version,
java.lang.String dn,
java.lang.String password)
Authenticates to the directory server using a simple bind with the provided
information.
|
void |
bind(int version,
java.lang.String dn,
java.lang.String password,
LDAPConstraints constraints)
Authenticates to the directory server using a simple bind with the provided
information.
|
void |
bind(java.lang.String dn,
java.lang.String password)
Authenticates to the directory server using a simple bind with the provided
information.
|
void |
bind(java.lang.String dn,
java.lang.String password,
LDAPConstraints constraints)
Authenticates to the directory server using a simple bind with the provided
information.
|
boolean |
compare(java.lang.String dn,
LDAPAttribute attribute)
Indicates whether the specified entry has the given attribute value.
|
boolean |
compare(java.lang.String dn,
LDAPAttribute attribute,
LDAPConstraints constraints)
Indicates whether the specified entry has the given attribute value.
|
void |
connect(int version,
java.lang.String host,
int port,
java.lang.String dn,
java.lang.String password)
Attempts to establish and authenticate this connection with the provided
information.
|
void |
connect(int version,
java.lang.String host,
int port,
java.lang.String dn,
java.lang.String password,
LDAPConstraints constraints)
Attempts to establish and authenticate this connection with the provided
information.
|
void |
connect(java.lang.String host,
int port)
Attempts to establish this connection with the provided information.
|
void |
connect(java.lang.String host,
int port,
java.lang.String dn,
java.lang.String password)
Attempts to establish and authenticate this connection with the provided
information.
|
void |
connect(java.lang.String host,
int port,
java.lang.String dn,
java.lang.String password,
LDAPConstraints constraints)
Attempts to establish and authenticate this connection with the provided
information.
|
void |
delete(java.lang.String dn)
Removes an entry from the directory.
|
void |
delete(java.lang.String dn,
LDAPConstraints constraints)
Removes an entry from the directory.
|
void |
disconnect()
Unbinds and disconnects from the directory server.
|
LDAPExtendedOperation |
extendedOperation(LDAPExtendedOperation extendedOperation)
Processes an extended operation in the directory.
|
LDAPExtendedOperation |
extendedOperation(LDAPExtendedOperation extendedOperation,
LDAPConstraints constraints)
Processes an extended operation in the directory.
|
protected void |
finalize()
Closes the connection to the server if the client forgets to do so.
|
java.lang.String |
getAuthenticationDN()
Retrieves the DN of the user that last authenticated on this connection.
|
java.lang.String |
getAuthenticationPassword()
Retrieves the password of the user that last authenticated on this
connection.
|
int |
getConnectTimeout()
Retrieves the maximum length of time to wait for the connection to be
established, in seconds.
|
LDAPConstraints |
getConstraints()
Retrieves the constraints for this connection.
|
java.lang.String |
getHost()
Retrieves the address to which the connection is established.
|
int |
getPort()
Retrieves the port to which the connection is established.
|
LDAPControl[] |
getResponseControls()
Retrieves the response controls from the last operation processed on this
connection.
|
LDAPConnection |
getSDKConnection()
Retrieves the
LDAPConnection object used to
back this connection. |
LDAPSearchConstraints |
getSearchConstraints()
Retrieves the search constraints for this connection.
|
LDAPSocketFactory |
getSocketFactory()
Retrieves the socket factory for this LDAP connection, if specified.
|
boolean |
isConnected()
Indicates whether this connection is currently established.
|
void |
modify(java.lang.String dn,
LDAPModification mod)
Modifies an entry in the directory.
|
void |
modify(java.lang.String dn,
LDAPModification[] mods)
Modifies an entry in the directory.
|
void |
modify(java.lang.String dn,
LDAPModification[] mods,
LDAPConstraints constraints)
Modifies an entry in the directory.
|
void |
modify(java.lang.String dn,
LDAPModification mod,
LDAPConstraints constraints)
Modifies an entry in the directory.
|
void |
modify(java.lang.String dn,
LDAPModificationSet mods)
Modifies an entry in the directory.
|
void |
modify(java.lang.String dn,
LDAPModificationSet mods,
LDAPConstraints constraints)
Modifies an entry in the directory.
|
LDAPEntry |
read(java.lang.String dn)
Retrieves an entry from the directory server.
|
LDAPEntry |
read(java.lang.String dn,
LDAPSearchConstraints constraints)
Retrieves an entry from the directory server.
|
LDAPEntry |
read(java.lang.String dn,
java.lang.String[] attrs)
Retrieves an entry from the directory server.
|
LDAPEntry |
read(java.lang.String dn,
java.lang.String[] attrs,
LDAPSearchConstraints constraints)
Retrieves an entry from the directory server.
|
void |
reconnect()
Disconnects from the directory server and attempts to re-connect and
re-authenticate.
|
void |
rename(java.lang.String dn,
java.lang.String newRDN,
boolean deleteOldRDN)
Alters the DN of an entry in the directory.
|
void |
rename(java.lang.String dn,
java.lang.String newRDN,
boolean deleteOldRDN,
LDAPConstraints constraints)
Alters the DN of an entry in the directory.
|
void |
rename(java.lang.String dn,
java.lang.String newRDN,
java.lang.String newParentDN,
boolean deleteOldRDN)
Alters the DN of an entry in the directory.
|
void |
rename(java.lang.String dn,
java.lang.String newRDN,
java.lang.String newParentDN,
boolean deleteOldRDN,
LDAPConstraints constraints)
Alters the DN of an entry in the directory.
|
LDAPSearchResults |
search(java.lang.String baseDN,
int scope,
java.lang.String filter,
java.lang.String[] attributes,
boolean typesOnly)
Processes a search in the directory server.
|
LDAPSearchResults |
search(java.lang.String baseDN,
int scope,
java.lang.String filter,
java.lang.String[] attributes,
boolean typesOnly,
LDAPSearchConstraints constraints)
Processes a search in the directory server.
|
void |
setConnectTimeout(int timeout)
Specifies the maximum length of time to wait for the connection to be
established, in seconds.
|
void |
setConstraints(LDAPConstraints constraints)
Updates the constraints for this connection.
|
void |
setSearchConstraints(LDAPSearchConstraints searchConstraints)
Updates the search constraints for this connection.
|
void |
setSocketFactory(LDAPSocketFactory socketFactory)
Sets the socket factory for this LDAP connection.
|
public static final int DEREF_NEVER
public static final int DEREF_SEARCHING
public static final int DEREF_FINDING
public static final int DEREF_ALWAYS
public static final int SCOPE_BASE
public static final int SCOPE_ONE
public static final int SCOPE_SUB
public LDAPConnection()
public LDAPConnection(LDAPSocketFactory socketFactory)
socketFactory
- The socket factory to use when creating the socket
to use for communicating with the server.protected void finalize() throws java.lang.Throwable
finalize
in class java.lang.Object
java.lang.Throwable
- If a problem occurs.public LDAPConnection getSDKConnection()
LDAPConnection
object used to
back this connection.com.unboundid.ldap.sdk.LDAPConnection
object used to
back this connection.public java.lang.String getHost()
public int getPort()
public java.lang.String getAuthenticationDN()
null
if it is not available.public java.lang.String getAuthenticationPassword()
null
if it is not available.public int getConnectTimeout()
public void setConnectTimeout(int timeout)
timeout
- The maximum length of time to wait for the connection to
be established.public LDAPSocketFactory getSocketFactory()
null
if
none has been provided.public void setSocketFactory(LDAPSocketFactory socketFactory)
socketFactory
- The socket factory for this LDAP connection.public LDAPConstraints getConstraints()
public void setConstraints(LDAPConstraints constraints)
constraints
- The constraints for this connection.public LDAPSearchConstraints getSearchConstraints()
public void setSearchConstraints(LDAPSearchConstraints searchConstraints)
searchConstraints
- The search constraints for this connection.public LDAPControl[] getResponseControls()
null
if there were none.public boolean isConnected()
true
if this connection is currently established, or
false
if not.public void connect(java.lang.String host, int port) throws LDAPException
host
- The address of the server to which the connection should be
established.port
- The port of the server to which the connection should be
established.LDAPException
- If a problem occurs while attempting to establish
this connection.public void connect(java.lang.String host, int port, java.lang.String dn, java.lang.String password) throws LDAPException
host
- The address of the server to which the connection should
be established.port
- The port of the server to which the connection should be
established.dn
- The DN to use to bind to the server.password
- The password to use to bind to the server.LDAPException
- If a problem occurs while attempting to establish
or authenticate this connection. If an exception
is thrown, then the connection will not be
established.public void connect(java.lang.String host, int port, java.lang.String dn, java.lang.String password, LDAPConstraints constraints) throws LDAPException
host
- The address of the server to which the connection
should be established.port
- The port of the server to which the connection should
be established.dn
- The DN to use to bind to the server.password
- The password to use to bind to the server.constraints
- The constraints to use when processing the bind.LDAPException
- If a problem occurs while attempting to establish
or authenticate this connection. If an exception
is thrown, then the connection will not be
established.public void connect(int version, java.lang.String host, int port, java.lang.String dn, java.lang.String password) throws LDAPException
version
- The LDAP protocol version to use for the connection.
This will be ignored, since this implementation only
supports LDAPv3.host
- The address of the server to which the connection should
be established.port
- The port of the server to which the connection should be
established.dn
- The DN to use to bind to the server.password
- The password to use to bind to the server.LDAPException
- If a problem occurs while attempting to establish
or authenticate this connection. If an exception
is thrown, then the connection will not be
established.public void connect(int version, java.lang.String host, int port, java.lang.String dn, java.lang.String password, LDAPConstraints constraints) throws LDAPException
version
- The LDAP protocol version to use for the connection.
This will be ignored, since this implementation only
supports LDAPv3.host
- The address of the server to which the connection
should be established.port
- The port of the server to which the connection should
be established.dn
- The DN to use to bind to the server.password
- The password to use to bind to the server.constraints
- The constraints to use when processing the bind.LDAPException
- If a problem occurs while attempting to establish
or authenticate this connection. If an exception
is thrown, then the connection will not be
established.public void disconnect() throws LDAPException
LDAPException
- If a problem occurs.public void reconnect() throws LDAPException
LDAPException
- If a problem occurs. If an exception is thrown,
the connection will have been closed.public void abandon(int id) throws LDAPException
id
- The message ID of the operation to abandon.LDAPException
- If a problem occurs while sending the request.public void abandon(LDAPSearchResults searchResults) throws LDAPException
searchResults
- The search results object for the search to abandon.LDAPException
- If a problem occurs while sending the request.public void add(LDAPEntry entry) throws LDAPException
entry
- The entry to be added.LDAPException
- If a problem occurs while adding the entry.public void add(LDAPEntry entry, LDAPConstraints constraints) throws LDAPException
entry
- The entry to be added.constraints
- The constraints to use for the add operation.LDAPException
- If a problem occurs while adding the entry.public void authenticate(java.lang.String dn, java.lang.String password) throws LDAPException
dn
- The DN of the user for the bind.password
- The password to use for the bind.LDAPException
- If the bind attempt fails.public void authenticate(java.lang.String dn, java.lang.String password, LDAPConstraints constraints) throws LDAPException
dn
- The DN of the user for the bind.password
- The password to use for the bind.constraints
- The constraints to use for the bind operation.LDAPException
- If the bind attempt fails.public void authenticate(int version, java.lang.String dn, java.lang.String password) throws LDAPException
version
- The LDAP protocol version to use. This will be ignored,
since this implementation only supports LDAPv3.dn
- The DN of the user for the bind.password
- The password to use for the bind.LDAPException
- If the bind attempt fails.public void authenticate(int version, java.lang.String dn, java.lang.String password, LDAPConstraints constraints) throws LDAPException
version
- The LDAP protocol version to use. This will be
ignored, since this implementation only supports
LDAPv3.dn
- The DN of the user for the bind.password
- The password to use for the bind.constraints
- The constraints to use for the bind operation.LDAPException
- If the bind attempt fails.public void bind(java.lang.String dn, java.lang.String password) throws LDAPException
dn
- The DN of the user for the bind.password
- The password to use for the bind.LDAPException
- If the bind attempt fails.public void bind(java.lang.String dn, java.lang.String password, LDAPConstraints constraints) throws LDAPException
dn
- The DN of the user for the bind.password
- The password to use for the bind.constraints
- The constraints to use for the bind operation.LDAPException
- If the bind attempt fails.public void bind(int version, java.lang.String dn, java.lang.String password) throws LDAPException
version
- The LDAP protocol version to use. This will be ignored,
since this implementation only supports LDAPv3.dn
- The DN of the user for the bind.password
- The password to use for the bind.LDAPException
- If the bind attempt fails.public void bind(int version, java.lang.String dn, java.lang.String password, LDAPConstraints constraints) throws LDAPException
version
- The LDAP protocol version to use. This will be
ignored, since this implementation only supports
LDAPv3.dn
- The DN of the user for the bind.password
- The password to use for the bind.constraints
- The constraints to use for the bind operation.LDAPException
- If the bind attempt fails.public boolean compare(java.lang.String dn, LDAPAttribute attribute) throws LDAPException
dn
- The DN of the entry to compare.attribute
- The attribute (which must have exactly one value) to use
for the comparison.true
if the compare matched the target entry, or
false
if not.LDAPException
- If a problem occurs while processing the compare.public boolean compare(java.lang.String dn, LDAPAttribute attribute, LDAPConstraints constraints) throws LDAPException
dn
- The DN of the entry to compare.attribute
- The attribute (which must have exactly one value) to
use for the comparison.constraints
- The constraints to use for the compare operation.true
if the compare matched the target entry, or
false
if not.LDAPException
- If a problem occurs while processing the compare.public void delete(java.lang.String dn) throws LDAPException
dn
- The DN of the entry to delete.LDAPException
- If a problem occurs while processing the delete.public void delete(java.lang.String dn, LDAPConstraints constraints) throws LDAPException
dn
- The DN of the entry to delete.constraints
- The constraints to use for the delete operation.LDAPException
- If a problem occurs while processing the delete.public LDAPExtendedOperation extendedOperation(LDAPExtendedOperation extendedOperation) throws LDAPException
extendedOperation
- The extended operation to process.LDAPException
- If a problem occurs while processing the operation.public LDAPExtendedOperation extendedOperation(LDAPExtendedOperation extendedOperation, LDAPConstraints constraints) throws LDAPException
extendedOperation
- The extended operation to process.constraints
- The constraints to use for the operation.LDAPException
- If a problem occurs while processing the operation.public void modify(java.lang.String dn, LDAPModification mod) throws LDAPException
dn
- The DN of the entry to modify.mod
- The modification to apply to the entry.LDAPException
- If a problem occurs while processing the delete.public void modify(java.lang.String dn, LDAPModification[] mods) throws LDAPException
dn
- The DN of the entry to modify.mods
- The modifications to apply to the entry.LDAPException
- If a problem occurs while processing the delete.public void modify(java.lang.String dn, LDAPModification mod, LDAPConstraints constraints) throws LDAPException
dn
- The DN of the entry to modify.mod
- The modification to apply to the entry.constraints
- The constraints to use for the modify operation.LDAPException
- If a problem occurs while processing the delete.public void modify(java.lang.String dn, LDAPModification[] mods, LDAPConstraints constraints) throws LDAPException
dn
- The DN of the entry to modify.mods
- The modifications to apply to the entry.constraints
- The constraints to use for the modify operation.LDAPException
- If a problem occurs while processing the delete.public void modify(java.lang.String dn, LDAPModificationSet mods) throws LDAPException
dn
- The DN of the entry to modify.mods
- The modifications to apply to the entry.LDAPException
- If a problem occurs while processing the delete.public void modify(java.lang.String dn, LDAPModificationSet mods, LDAPConstraints constraints) throws LDAPException
dn
- The DN of the entry to modify.mods
- The modifications to apply to the entry.constraints
- The constraints to use for the modify operation.LDAPException
- If a problem occurs while processing the delete.public LDAPEntry read(java.lang.String dn) throws LDAPException
dn
- The DN of the entry to retrieve.LDAPException
- If a problem occurs while performing the search.public LDAPEntry read(java.lang.String dn, LDAPSearchConstraints constraints) throws LDAPException
dn
- The DN of the entry to retrieve.constraints
- The constraints to use for the search operation.LDAPException
- If a problem occurs while performing the search.public LDAPEntry read(java.lang.String dn, java.lang.String[] attrs) throws LDAPException
dn
- The DN of the entry to retrieve.attrs
- The set of attributes to request.LDAPException
- If a problem occurs while performing the search.public LDAPEntry read(java.lang.String dn, java.lang.String[] attrs, LDAPSearchConstraints constraints) throws LDAPException
dn
- The DN of the entry to retrieve.attrs
- The set of attributes to request.constraints
- The constraints to use for the search operation.LDAPException
- If a problem occurs while performing the search.public void rename(java.lang.String dn, java.lang.String newRDN, boolean deleteOldRDN) throws LDAPException
dn
- The DN of the entry to modify.newRDN
- The new RDN to use for the entry.deleteOldRDN
- Indicates whether to remove the old RDN value(s).LDAPException
- If a problem occurs while processing the delete.public void rename(java.lang.String dn, java.lang.String newRDN, boolean deleteOldRDN, LDAPConstraints constraints) throws LDAPException
dn
- The DN of the entry to modify.newRDN
- The new RDN to use for the entry.deleteOldRDN
- Indicates whether to remove the old RDN value(s).constraints
- The constraints to use for the modify operation.LDAPException
- If a problem occurs while processing the delete.public void rename(java.lang.String dn, java.lang.String newRDN, java.lang.String newParentDN, boolean deleteOldRDN) throws LDAPException
dn
- The DN of the entry to modify.newRDN
- The new RDN to use for the entry.newParentDN
- The DN of the new parent, or null
if it
should not be moved below a new parent.deleteOldRDN
- Indicates whether to remove the old RDN value(s).LDAPException
- If a problem occurs while processing the delete.public void rename(java.lang.String dn, java.lang.String newRDN, java.lang.String newParentDN, boolean deleteOldRDN, LDAPConstraints constraints) throws LDAPException
dn
- The DN of the entry to modify.newRDN
- The new RDN to use for the entry.newParentDN
- The DN of the new parent, or null
if it
should not be moved below a new parent.deleteOldRDN
- Indicates whether to remove the old RDN value(s).constraints
- The constraints to use for the modify operation.LDAPException
- If a problem occurs while processing the delete.public LDAPSearchResults search(java.lang.String baseDN, int scope, java.lang.String filter, java.lang.String[] attributes, boolean typesOnly) throws LDAPException
baseDN
- The base DN for the search.scope
- The scope for the search.filter
- The filter for the search.attributes
- The set of attributes to request.typesOnly
- Indicates whether to return attribute types only or
both types and values.LDAPException
- If a problem occurs while performing the search.public LDAPSearchResults search(java.lang.String baseDN, int scope, java.lang.String filter, java.lang.String[] attributes, boolean typesOnly, LDAPSearchConstraints constraints) throws LDAPException
baseDN
- The base DN for the search.scope
- The scope for the search.filter
- The filter for the search.attributes
- The set of attributes to request.typesOnly
- Indicates whether to return attribute types only or
both types and values.constraints
- The constraints to use for the search operation.LDAPException
- If a problem occurs while performing the search.