public final class LdapConnection extends Object implements Closeable
Connection
interface (e.g. migration to Promises).Modifier and Type | Method and Description |
---|---|
org.forgerock.opendj.ldap.responses.Result |
add(org.forgerock.opendj.ldap.requests.AddRequest request)
Adds an entry to the Directory Server using the provided add request.
|
org.forgerock.opendj.ldap.responses.Result |
add(org.forgerock.opendj.ldap.Entry entry)
Adds the provided entry to the Directory Server.
|
org.forgerock.opendj.ldap.responses.Result |
add(String... ldifLines)
Adds an entry to the Directory Server using the provided lines of LDIF.
|
org.forgerock.opendj.ldap.responses.BindResult |
bind(org.forgerock.opendj.ldap.requests.BindRequest request)
Authenticates to the Directory Server using the provided bind request.
|
org.forgerock.opendj.ldap.responses.BindResult |
bind(String name,
char[] password)
Authenticates to the Directory Server using simple authentication and the
provided user name and password.
|
void |
close()
Releases any resources associated with this connection.
|
org.forgerock.opendj.ldap.responses.CompareResult |
compare(org.forgerock.opendj.ldap.requests.CompareRequest request)
Compares an entry in the Directory Server using the provided compare
request.
|
org.forgerock.opendj.ldap.responses.CompareResult |
compare(String name,
String attributeDescription,
String assertionValue)
Compares the named entry in the Directory Server against the provided
attribute value assertion.
|
org.forgerock.opendj.ldap.responses.Result |
delete(org.forgerock.opendj.ldap.requests.DeleteRequest request)
Deletes an entry from the Directory Server using the provided delete
request.
|
org.forgerock.opendj.ldap.responses.Result |
delete(String name)
Deletes the named entry from the Directory Server.
|
org.forgerock.opendj.ldap.responses.Result |
deleteSubtree(String name)
Deletes the named entry and all of its subordinates from the Directory
Server.
|
org.forgerock.opendj.ldap.responses.Result |
modify(org.forgerock.opendj.ldap.requests.ModifyRequest request)
Modifies an entry in the Directory Server using the provided modify
request.
|
org.forgerock.opendj.ldap.responses.Result |
modify(String... ldifLines)
Modifies an entry in the Directory Server using the provided lines of
LDIF.
|
org.forgerock.opendj.ldap.responses.Result |
modifyDN(org.forgerock.opendj.ldap.requests.ModifyDNRequest request)
Renames an entry in the Directory Server using the provided modify DN
request.
|
org.forgerock.opendj.ldap.responses.Result |
modifyDN(String name,
String newRDN)
Renames the named entry in the Directory Server using the provided new
RDN.
|
org.forgerock.opendj.ldap.responses.SearchResultEntry |
readEntry(org.forgerock.opendj.ldap.DN name,
String... attributeDescriptions)
Reads the named entry from the Directory Server.
|
org.forgerock.opendj.ldap.responses.SearchResultEntry |
readEntry(String name,
String... attributeDescriptions)
Reads the named entry from the Directory Server.
|
org.forgerock.opendj.ldif.ConnectionEntryReader |
search(org.forgerock.opendj.ldap.requests.SearchRequest request)
Searches the Directory Server using the provided search parameters.
|
org.forgerock.opendj.ldap.responses.Result |
search(org.forgerock.opendj.ldap.requests.SearchRequest request,
Collection<? super org.forgerock.opendj.ldap.responses.SearchResultEntry> entries)
Searches the Directory Server using the provided search request.
|
org.forgerock.opendj.ldap.responses.Result |
search(org.forgerock.opendj.ldap.requests.SearchRequest request,
Collection<? super org.forgerock.opendj.ldap.responses.SearchResultEntry> entries,
Collection<? super org.forgerock.opendj.ldap.responses.SearchResultReference> references)
Searches the Directory Server using the provided search request.
|
org.forgerock.opendj.ldif.ConnectionEntryReader |
search(String baseObject,
org.forgerock.opendj.ldap.SearchScope scope,
String filter,
String... attributeDescriptions)
Searches the Directory Server using the provided search parameters.
|
org.forgerock.opendj.ldap.responses.SearchResultEntry |
searchSingleEntry(org.forgerock.opendj.ldap.requests.SearchRequest request)
Searches the Directory Server for a single entry using the provided
search request.
|
org.forgerock.opendj.ldap.responses.SearchResultEntry |
searchSingleEntry(String baseObject,
org.forgerock.opendj.ldap.SearchScope scope,
String filter,
String... attributeDescriptions)
Searches the Directory Server for a single entry using the provided
search parameters.
|
public org.forgerock.opendj.ldap.responses.Result add(org.forgerock.opendj.ldap.requests.AddRequest request) throws org.forgerock.opendj.ldap.LdapException
request
- The add request.org.forgerock.opendj.ldap.LdapException
- If the result code indicates that the request failed for some
reason.UnsupportedOperationException
- If this connection does not support add operations.IllegalStateException
- If this connection has already been closed, i.e. if
isClosed() == true
.NullPointerException
- If request
was null
.public org.forgerock.opendj.ldap.responses.Result add(org.forgerock.opendj.ldap.Entry entry) throws org.forgerock.opendj.ldap.LdapException
This method is equivalent to the following code:
AddRequest request = newAddRequest(entry);
connection.add(request);
entry
- The entry to be added.org.forgerock.opendj.ldap.LdapException
- If the result code indicates that the request failed for some
reason.UnsupportedOperationException
- If this connection does not support add operations.IllegalStateException
- If this connection has already been closed, i.e. if
isClosed() == true
.NullPointerException
- If entry
was null
.public org.forgerock.opendj.ldap.responses.Result add(String... ldifLines) throws org.forgerock.opendj.ldap.LdapException
This method is equivalent to the following code:
AddRequest request = newAddRequest(ldifLines);
connection.add(request);
ldifLines
- Lines of LDIF containing the an LDIF add change record or an
LDIF entry record.org.forgerock.opendj.ldap.LdapException
- If the result code indicates that the request failed for some
reason.UnsupportedOperationException
- If this connection does not support add operations.org.forgerock.i18n.LocalizedIllegalArgumentException
- If ldifLines
was empty, or contained invalid LDIF, or
could not be decoded using the default schema.IllegalStateException
- If this connection has already been closed, i.e. if
isClosed() == true
.NullPointerException
- If ldifLines
was null
.public org.forgerock.opendj.ldap.responses.BindResult bind(org.forgerock.opendj.ldap.requests.BindRequest request) throws org.forgerock.opendj.ldap.LdapException
request
- The bind request.org.forgerock.opendj.ldap.LdapException
- If the result code indicates that the request failed for some
reason.UnsupportedOperationException
- If this connection does not support bind operations.IllegalStateException
- If this connection has already been closed, i.e. if
isClosed() == true
.NullPointerException
- If request
was null
.public org.forgerock.opendj.ldap.responses.BindResult bind(String name, char[] password) throws org.forgerock.opendj.ldap.LdapException
This method is equivalent to the following code:
BindRequest request = newSimpleBindRequest(name, password);
connection.bind(request);
name
- The distinguished name of the Directory object that the client
wishes to bind as, which may be empty.password
- The password of the Directory object that the client wishes to
bind as, which may be empty.org.forgerock.opendj.ldap.LdapException
- If the result code indicates that the request failed for some
reason.org.forgerock.i18n.LocalizedIllegalArgumentException
- If name
could not be decoded using the default
schema.UnsupportedOperationException
- If this connection does not support bind operations.IllegalStateException
- If this connection has already been closed, i.e. if
isClosed() == true
.NullPointerException
- If name
or password
was null
.public void close()
Other connection implementations may behave differently, and may choose not to send an unbind request if its use is inappropriate (for example a pooled connection will be released and returned to its connection pool without ever issuing an unbind request).
This method is equivalent to the following code:
UnbindRequest request = new UnbindRequest();
connection.close(request);
Calling close
on a connection that is already closed has no
effect.
close
in interface Closeable
close
in interface AutoCloseable
Connections.uncloseable(Connection)
public org.forgerock.opendj.ldap.responses.CompareResult compare(org.forgerock.opendj.ldap.requests.CompareRequest request) throws org.forgerock.opendj.ldap.LdapException
request
- The compare request.org.forgerock.opendj.ldap.LdapException
- If the result code indicates that the request failed for some
reason.UnsupportedOperationException
- If this connection does not support compare operations.IllegalStateException
- If this connection has already been closed, i.e. if
isClosed() == true
.NullPointerException
- If request
was null
.public org.forgerock.opendj.ldap.responses.CompareResult compare(String name, String attributeDescription, String assertionValue) throws org.forgerock.opendj.ldap.LdapException
This method is equivalent to the following code:
CompareRequest request = newCompareRequest(name, attributeDescription, assertionValue);
connection.compare(request);
name
- The distinguished name of the entry to be compared.attributeDescription
- The name of the attribute to be compared.assertionValue
- The assertion value to be compared.org.forgerock.opendj.ldap.LdapException
- If the result code indicates that the request failed for some
reason.org.forgerock.i18n.LocalizedIllegalArgumentException
- If name
or AttributeDescription
could not be
decoded using the default schema.UnsupportedOperationException
- If this connection does not support compare operations.IllegalStateException
- If this connection has already been closed, i.e. if
isClosed() == true
.NullPointerException
- If name
, attributeDescription
, or
assertionValue
was null
.public org.forgerock.opendj.ldap.responses.Result delete(org.forgerock.opendj.ldap.requests.DeleteRequest request) throws org.forgerock.opendj.ldap.LdapException
request
- The delete request.org.forgerock.opendj.ldap.LdapException
- If the result code indicates that the request failed for some
reason.UnsupportedOperationException
- If this connection does not support delete operations.IllegalStateException
- If this connection has already been closed, i.e. if
isClosed() == true
.NullPointerException
- If request
was null
.public org.forgerock.opendj.ldap.responses.Result delete(String name) throws org.forgerock.opendj.ldap.LdapException
This method is equivalent to the following code:
DeleteRequest request = newDeleteRequest(name);
connection.delete(request);
name
- The distinguished name of the entry to be deleted.org.forgerock.opendj.ldap.LdapException
- If the result code indicates that the request failed for some
reason.org.forgerock.i18n.LocalizedIllegalArgumentException
- If name
could not be decoded using the default
schema.UnsupportedOperationException
- If this connection does not support delete operations.IllegalStateException
- If this connection has already been closed, i.e. if
isClosed() == true
.NullPointerException
- If name
was null
.public org.forgerock.opendj.ldap.responses.Result deleteSubtree(String name) throws org.forgerock.opendj.ldap.LdapException
This method is equivalent to the following code:
DeleteRequest request = newDeleteRequest(name).addControl(SubtreeDeleteRequestControl.newControl(true)));
connection.delete(request);
name
- The distinguished name of the subtree base entry to be
deleted.org.forgerock.opendj.ldap.LdapException
- If the result code indicates that the request failed for some
reason.org.forgerock.i18n.LocalizedIllegalArgumentException
- If name
could not be decoded using the default
schema.UnsupportedOperationException
- If this connection does not support delete operations.IllegalStateException
- If this connection has already been closed, i.e. if
isClosed() == true
.NullPointerException
- If name
was null
.public org.forgerock.opendj.ldap.responses.Result modify(org.forgerock.opendj.ldap.requests.ModifyRequest request) throws org.forgerock.opendj.ldap.LdapException
request
- The modify request.org.forgerock.opendj.ldap.LdapException
- If the result code indicates that the request failed for some
reason.UnsupportedOperationException
- If this connection does not support modify operations.IllegalStateException
- If this connection has already been closed, i.e. if
isClosed() == true
.NullPointerException
- If request
was null
.public org.forgerock.opendj.ldap.responses.Result modify(String... ldifLines) throws org.forgerock.opendj.ldap.LdapException
This method is equivalent to the following code:
ModifyRequest request = newModifyRequest(ldifLines);
connection.modify(request);
ldifLines
- Lines of LDIF containing the a single LDIF modify change
record.org.forgerock.opendj.ldap.LdapException
- If the result code indicates that the request failed for some
reason.UnsupportedOperationException
- If this connection does not support modify operations.org.forgerock.i18n.LocalizedIllegalArgumentException
- If ldifLines
was empty, or contained invalid LDIF, or
could not be decoded using the default schema.IllegalStateException
- If this connection has already been closed, i.e. if
isClosed() == true
.NullPointerException
- If ldifLines
was null
.public org.forgerock.opendj.ldap.responses.Result modifyDN(org.forgerock.opendj.ldap.requests.ModifyDNRequest request) throws org.forgerock.opendj.ldap.LdapException
request
- The modify DN request.org.forgerock.opendj.ldap.LdapException
- If the result code indicates that the request failed for some
reason.UnsupportedOperationException
- If this connection does not support modify DN operations.IllegalStateException
- If this connection has already been closed, i.e. if
isClosed() == true
.NullPointerException
- If request
was null
.public org.forgerock.opendj.ldap.responses.Result modifyDN(String name, String newRDN) throws org.forgerock.opendj.ldap.LdapException
This method is equivalent to the following code:
ModifyDNRequest request = newModifyDNRequest(name, newRDN);
connection.modifyDN(request);
name
- The distinguished name of the entry to be renamed.newRDN
- The new RDN of the entry.org.forgerock.opendj.ldap.LdapException
- If the result code indicates that the request failed for some
reason.org.forgerock.i18n.LocalizedIllegalArgumentException
- If name
or newRDN
could not be decoded using
the default schema.UnsupportedOperationException
- If this connection does not support modify DN operations.IllegalStateException
- If this connection has already been closed, i.e. if
isClosed() == true
.NullPointerException
- If name
or newRDN
was null
.public org.forgerock.opendj.ldap.responses.SearchResultEntry readEntry(org.forgerock.opendj.ldap.DN name, String... attributeDescriptions) throws org.forgerock.opendj.ldap.LdapException
If the requested entry is not returned by the Directory Server then the
request will fail with an EntryNotFoundException
. More
specifically, this method will never return null
.
This method is equivalent to the following code:
SearchRequest request =
new SearchRequest(name, SearchScope.BASE_OBJECT, "(objectClass=*)", attributeDescriptions);
connection.searchSingleEntry(request);
name
- The distinguished name of the entry to be read.attributeDescriptions
- The names of the attributes to be included with the entry,
which may be null
or empty indicating that all user
attributes should be returned.org.forgerock.opendj.ldap.LdapException
- If the result code indicates that the request failed for some
reason.UnsupportedOperationException
- If this connection does not support search operations.IllegalStateException
- If this connection has already been closed, i.e. if
isClosed() == true
.NullPointerException
- If the name
was null
.public org.forgerock.opendj.ldap.responses.SearchResultEntry readEntry(String name, String... attributeDescriptions) throws org.forgerock.opendj.ldap.LdapException
If the requested entry is not returned by the Directory Server then the
request will fail with an EntryNotFoundException
. More
specifically, this method will never return null
.
This method is equivalent to the following code:
SearchRequest request =
new SearchRequest(name, SearchScope.BASE_OBJECT, "(objectClass=*)", attributeDescriptions);
connection.searchSingleEntry(request);
name
- The distinguished name of the entry to be read.attributeDescriptions
- The names of the attributes to be included with the entry.org.forgerock.opendj.ldap.LdapException
- If the result code indicates that the request failed for some
reason.org.forgerock.i18n.LocalizedIllegalArgumentException
- If baseObject
could not be decoded using the default
schema.UnsupportedOperationException
- If this connection does not support search operations.IllegalStateException
- If this connection has already been closed, i.e. if
isClosed() == true
.NullPointerException
- If the name
was null
.public org.forgerock.opendj.ldif.ConnectionEntryReader search(org.forgerock.opendj.ldap.requests.SearchRequest request)
ConnectionEntryReader
.
Unless otherwise specified, calling this method is equivalent to:
ConnectionEntryReader reader = new ConnectionEntryReader(this, request);
request
- The search request.UnsupportedOperationException
- If this connection does not support search operations.IllegalStateException
- If this connection has already been closed, i.e. if
isClosed() == true
.NullPointerException
- If request
or entries
was null
.public org.forgerock.opendj.ldap.responses.Result search(org.forgerock.opendj.ldap.requests.SearchRequest request, Collection<? super org.forgerock.opendj.ldap.responses.SearchResultEntry> entries) throws org.forgerock.opendj.ldap.LdapException
entries
,
even if the final search result indicates that the search failed. Search
result references will be discarded.
Warning: Usage of this method is discouraged if the search request
is expected to yield a large number of search results since the entire
set of results will be stored in memory, potentially causing an
OutOfMemoryError
.
This method is equivalent to the following code:
connection.search(request, entries, null);
request
- The search request.entries
- The collection to which matching entries should be added.org.forgerock.opendj.ldap.LdapException
- If the result code indicates that the request failed for some
reason.UnsupportedOperationException
- If this connection does not support search operations.IllegalStateException
- If this connection has already been closed, i.e. if
isClosed() == true
.NullPointerException
- If request
or entries
was null
.public org.forgerock.opendj.ldap.responses.Result search(org.forgerock.opendj.ldap.requests.SearchRequest request, Collection<? super org.forgerock.opendj.ldap.responses.SearchResultEntry> entries, Collection<? super org.forgerock.opendj.ldap.responses.SearchResultReference> references) throws org.forgerock.opendj.ldap.LdapException
entries
,
even if the final search result indicates that the search failed.
Similarly, search result references returned by the search will be added
to references
.
Warning: Usage of this method is discouraged if the search request
is expected to yield a large number of search results since the entire
set of results will be stored in memory, potentially causing an
OutOfMemoryError
.
request
- The search request.entries
- The collection to which matching entries should be added.references
- The collection to which search result references should be
added, or null
if references are to be discarded.org.forgerock.opendj.ldap.LdapException
- If the result code indicates that the request failed for some
reason.UnsupportedOperationException
- If this connection does not support search operations.IllegalStateException
- If this connection has already been closed, i.e. if
isClosed() == true
.NullPointerException
- If request
or entries
was null
.public org.forgerock.opendj.ldif.ConnectionEntryReader search(String baseObject, org.forgerock.opendj.ldap.SearchScope scope, String filter, String... attributeDescriptions)
EntryReader
interface.
Warning: When using a queue with an optional capacity bound, the connection will stop reading responses and wait if necessary for space to become available.
This method is equivalent to the following code:
SearchRequest request = new SearchRequest(baseDN, scope, filter, attributeDescriptions);
connection.search(request, new LinkedBlockingQueue<Response>());
baseObject
- The distinguished name of the base entry relative to which the
search is to be performed.scope
- The scope of the search.filter
- The filter that defines the conditions that must be fulfilled
in order for an entry to be returned.attributeDescriptions
- The names of the attributes to be included with each entry.UnsupportedOperationException
- If this connection does not support search operations.IllegalStateException
- If this connection has already been closed, i.e. if
isClosed() == true
.NullPointerException
- If the baseObject
, scope
, or filter
were null
.public org.forgerock.opendj.ldap.responses.SearchResultEntry searchSingleEntry(org.forgerock.opendj.ldap.requests.SearchRequest request) throws org.forgerock.opendj.ldap.LdapException
If the requested entry is not returned by the Directory Server then the
request will fail with an EntryNotFoundException
. More
specifically, this method will never return null
. If multiple
matching entries are returned by the Directory Server then the request
will fail with an MultipleEntriesFoundException
.
request
- The search request.org.forgerock.opendj.ldap.LdapException
- If the result code indicates that the request failed for some
reason.UnsupportedOperationException
- If this connection does not support search operations.IllegalStateException
- If this connection has already been closed, i.e. if
isClosed() == true
.NullPointerException
- If the request
was null
.public org.forgerock.opendj.ldap.responses.SearchResultEntry searchSingleEntry(String baseObject, org.forgerock.opendj.ldap.SearchScope scope, String filter, String... attributeDescriptions) throws org.forgerock.opendj.ldap.LdapException
If the requested entry is not returned by the Directory Server then the
request will fail with an EntryNotFoundException
. More
specifically, this method will never return null
. If multiple
matching entries are returned by the Directory Server then the request
will fail with an MultipleEntriesFoundException
.
This method is equivalent to the following code:
SearchRequest request = new SearchRequest(baseObject, scope, filter, attributeDescriptions);
connection.searchSingleEntry(request);
baseObject
- The distinguished name of the base entry relative to which the
search is to be performed.scope
- The scope of the search.filter
- The filter that defines the conditions that must be fulfilled
in order for an entry to be returned.attributeDescriptions
- The names of the attributes to be included with each entry.org.forgerock.opendj.ldap.LdapException
- If the result code indicates that the request failed for some
reason.org.forgerock.i18n.LocalizedIllegalArgumentException
- If baseObject
could not be decoded using the default
schema or if filter
is not a valid LDAP string
representation of a filter.UnsupportedOperationException
- If this connection does not support search operations.IllegalStateException
- If this connection has already been closed, i.e. if
isClosed() == true
.NullPointerException
- If the baseObject
, scope
, or filter
were null
.Copyright © 2025 Open Identity Platform Community. All rights reserved.