Class LdapConnection
- java.lang.Object
-
- org.forgerock.openig.ldap.LdapConnection
-
- All Implemented Interfaces:
Closeable,AutoCloseable
public final class LdapConnection extends Object implements Closeable
Provides an adapted view of an OpenDJ LDAP connection exposing only the synchronous methods and protecting against future evolution of theConnectioninterface (e.g. migration to Promises).
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description org.forgerock.opendj.ldap.messages.Resultadd(String... ldifLines)Adds an entry to the Directory Server using the provided lines of LDIF.org.forgerock.opendj.ldap.messages.Resultadd(org.forgerock.opendj.ldap.Entry entry)Adds the provided entry to the Directory Server.org.forgerock.opendj.ldap.messages.Resultadd(org.forgerock.opendj.ldap.messages.AddRequest request)Adds an entry to the Directory Server using the provided add request.org.forgerock.opendj.ldap.messages.BindResultbind(String name, char[] password)Authenticates to the Directory Server using simple authentication and the provided user name and password.org.forgerock.opendj.ldap.messages.BindResultbind(org.forgerock.opendj.ldap.messages.BindRequest request)Authenticates to the Directory Server using the provided bind request.voidclose()Releases any resources associated with this connection.org.forgerock.opendj.ldap.messages.CompareResultcompare(String name, String attributeDescription, String assertionValue)Compares the named entry in the Directory Server against the provided attribute value assertion.org.forgerock.opendj.ldap.messages.CompareResultcompare(org.forgerock.opendj.ldap.messages.CompareRequest request)Compares an entry in the Directory Server using the provided compare request.org.forgerock.opendj.ldap.messages.Resultdelete(String name)Deletes the named entry from the Directory Server.org.forgerock.opendj.ldap.messages.Resultdelete(org.forgerock.opendj.ldap.messages.DeleteRequest request)Deletes an entry from the Directory Server using the provided delete request.org.forgerock.opendj.ldap.messages.ResultdeleteSubtree(String name)Deletes the named entry and all of its subordinates from the Directory Server.org.forgerock.opendj.ldap.messages.Resultmodify(String... ldifLines)Modifies an entry in the Directory Server using the provided lines of LDIF.org.forgerock.opendj.ldap.messages.Resultmodify(org.forgerock.opendj.ldap.messages.ModifyRequest request)Modifies an entry in the Directory Server using the provided modify request.org.forgerock.opendj.ldap.messages.ResultmodifyDN(String name, String newRDN)Renames the named entry in the Directory Server using the provided new RDN.org.forgerock.opendj.ldap.messages.ResultmodifyDN(org.forgerock.opendj.ldap.messages.ModifyDnRequest request)Renames an entry in the Directory Server using the provided modify DN request.org.forgerock.opendj.ldap.messages.SearchResultEntryreadEntry(String name, String... attributeDescriptions)Reads the named entry from the Directory Server.org.forgerock.opendj.ldap.messages.SearchResultEntryreadEntry(org.forgerock.opendj.ldap.Dn name, String... attributeDescriptions)Reads the named entry from the Directory Server.org.forgerock.opendj.ldif.ConnectionEntryReadersearch(String baseObject, org.forgerock.opendj.ldap.SearchScope scope, String filter, String... attributeDescriptions)Searches the Directory Server using the provided search parameters.org.forgerock.opendj.ldif.ConnectionEntryReadersearch(org.forgerock.opendj.ldap.messages.SearchRequest request)Searches the Directory Server using the provided search parameters.org.forgerock.opendj.ldap.messages.Resultsearch(org.forgerock.opendj.ldap.messages.SearchRequest request, Collection<? super org.forgerock.opendj.ldap.messages.SearchResultEntry> entries)Searches the Directory Server using the provided search request.org.forgerock.opendj.ldap.messages.Resultsearch(org.forgerock.opendj.ldap.messages.SearchRequest request, Collection<? super org.forgerock.opendj.ldap.messages.SearchResultEntry> entries, Collection<? super org.forgerock.opendj.ldap.messages.SearchResultReference> references)Searches the Directory Server using the provided search request.org.forgerock.opendj.ldap.messages.SearchResultEntrysearchSingleEntry(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.org.forgerock.opendj.ldap.messages.SearchResultEntrysearchSingleEntry(org.forgerock.opendj.ldap.messages.SearchRequest request)Searches the Directory Server for a single entry using the provided search request.
-
-
-
Method Detail
-
add
public org.forgerock.opendj.ldap.messages.Result add(org.forgerock.opendj.ldap.messages.AddRequest request) throws org.forgerock.opendj.ldap.LdapExceptionAdds an entry to the Directory Server using the provided add request.- Parameters:
request- The add request.- Returns:
- The result of the operation.
- Throws:
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. ifisClosed() == true.NullPointerException- Ifrequestwasnull.
-
add
public org.forgerock.opendj.ldap.messages.Result add(org.forgerock.opendj.ldap.Entry entry) throws org.forgerock.opendj.ldap.LdapExceptionAdds the provided entry to the Directory Server.This method is equivalent to the following code:
AddRequest request = newAddRequest(entry); connection.add(request);- Parameters:
entry- The entry to be added.- Returns:
- The result of the operation.
- Throws:
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. ifisClosed() == true.NullPointerException- Ifentrywasnull.
-
add
public org.forgerock.opendj.ldap.messages.Result add(String... ldifLines) throws org.forgerock.opendj.ldap.LdapException
Adds an entry to the Directory Server using the provided lines of LDIF.This method is equivalent to the following code:
AddRequest request = newAddRequest(ldifLines); connection.add(request);- Parameters:
ldifLines- Lines of LDIF containing the an LDIF add change record or an LDIF entry record.- Returns:
- The result of the operation.
- Throws:
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- IfldifLineswas empty, or contained invalid LDIF, or could not be decoded using the default schema.IllegalStateException- If this connection has already been closed, i.e. ifisClosed() == true.NullPointerException- IfldifLineswasnull.
-
bind
public org.forgerock.opendj.ldap.messages.BindResult bind(org.forgerock.opendj.ldap.messages.BindRequest request) throws org.forgerock.opendj.ldap.LdapExceptionAuthenticates to the Directory Server using the provided bind request.- Parameters:
request- The bind request.- Returns:
- The result of the operation.
- Throws:
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. ifisClosed() == true.NullPointerException- Ifrequestwasnull.
-
bind
public org.forgerock.opendj.ldap.messages.BindResult bind(String name, char[] password) throws org.forgerock.opendj.ldap.LdapException
Authenticates to the Directory Server using simple authentication and the provided user name and password.This method is equivalent to the following code:
BindRequest request = newSimpleBindRequest(name, password); connection.bind(request);- Parameters:
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.- Returns:
- The result of the operation.
- Throws:
org.forgerock.opendj.ldap.LdapException- If the result code indicates that the request failed for some reason.org.forgerock.i18n.LocalizedIllegalArgumentException- Ifnamecould 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. ifisClosed() == true.NullPointerException- Ifnameorpasswordwasnull.
-
close
public void close()
Releases any resources associated with this connection. For physical connections to a Directory Server this will mean that an unbind request is sent and the underlying socket is closed.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
closeon a connection that is already closed has no effect.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- See Also:
Connections.uncloseable(Connection)
-
compare
public org.forgerock.opendj.ldap.messages.CompareResult compare(org.forgerock.opendj.ldap.messages.CompareRequest request) throws org.forgerock.opendj.ldap.LdapExceptionCompares an entry in the Directory Server using the provided compare request.- Parameters:
request- The compare request.- Returns:
- The result of the operation.
- Throws:
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. ifisClosed() == true.NullPointerException- Ifrequestwasnull.
-
compare
public org.forgerock.opendj.ldap.messages.CompareResult compare(String name, String attributeDescription, String assertionValue) throws org.forgerock.opendj.ldap.LdapException
Compares the named entry in the Directory Server against the provided attribute value assertion.This method is equivalent to the following code:
CompareRequest request = newCompareRequest(name, attributeDescription, assertionValue); connection.compare(request);- Parameters:
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.- Returns:
- The result of the operation.
- Throws:
org.forgerock.opendj.ldap.LdapException- If the result code indicates that the request failed for some reason.org.forgerock.i18n.LocalizedIllegalArgumentException- IfnameorAttributeDescriptioncould 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. ifisClosed() == true.NullPointerException- Ifname,attributeDescription, orassertionValuewasnull.
-
delete
public org.forgerock.opendj.ldap.messages.Result delete(org.forgerock.opendj.ldap.messages.DeleteRequest request) throws org.forgerock.opendj.ldap.LdapExceptionDeletes an entry from the Directory Server using the provided delete request.- Parameters:
request- The delete request.- Returns:
- The result of the operation.
- Throws:
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. ifisClosed() == true.NullPointerException- Ifrequestwasnull.
-
delete
public org.forgerock.opendj.ldap.messages.Result delete(String name) throws org.forgerock.opendj.ldap.LdapException
Deletes the named entry from the Directory Server.This method is equivalent to the following code:
DeleteRequest request = newDeleteRequest(name); connection.delete(request);- Parameters:
name- The distinguished name of the entry to be deleted.- Returns:
- The result of the operation.
- Throws:
org.forgerock.opendj.ldap.LdapException- If the result code indicates that the request failed for some reason.org.forgerock.i18n.LocalizedIllegalArgumentException- Ifnamecould 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. ifisClosed() == true.NullPointerException- Ifnamewasnull.
-
deleteSubtree
public org.forgerock.opendj.ldap.messages.Result deleteSubtree(String name) throws org.forgerock.opendj.ldap.LdapException
Deletes the named entry and all of its subordinates from the Directory Server.This method is equivalent to the following code:
DeleteRequest request = newDeleteRequest(name).addControl(SubtreeDeleteRequestControl.newControl(true))); connection.delete(request);- Parameters:
name- The distinguished name of the subtree base entry to be deleted.- Returns:
- The result of the operation.
- Throws:
org.forgerock.opendj.ldap.LdapException- If the result code indicates that the request failed for some reason.org.forgerock.i18n.LocalizedIllegalArgumentException- Ifnamecould 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. ifisClosed() == true.NullPointerException- Ifnamewasnull.
-
modify
public org.forgerock.opendj.ldap.messages.Result modify(org.forgerock.opendj.ldap.messages.ModifyRequest request) throws org.forgerock.opendj.ldap.LdapExceptionModifies an entry in the Directory Server using the provided modify request.- Parameters:
request- The modify request.- Returns:
- The result of the operation.
- Throws:
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. ifisClosed() == true.NullPointerException- Ifrequestwasnull.
-
modify
public org.forgerock.opendj.ldap.messages.Result modify(String... ldifLines) throws org.forgerock.opendj.ldap.LdapException
Modifies an entry in the Directory Server using the provided lines of LDIF.This method is equivalent to the following code:
ModifyRequest request = newModifyRequest(ldifLines); connection.modify(request);- Parameters:
ldifLines- Lines of LDIF containing the a single LDIF modify change record.- Returns:
- The result of the operation.
- Throws:
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- IfldifLineswas empty, or contained invalid LDIF, or could not be decoded using the default schema.IllegalStateException- If this connection has already been closed, i.e. ifisClosed() == true.NullPointerException- IfldifLineswasnull.
-
modifyDN
public org.forgerock.opendj.ldap.messages.Result modifyDN(org.forgerock.opendj.ldap.messages.ModifyDnRequest request) throws org.forgerock.opendj.ldap.LdapExceptionRenames an entry in the Directory Server using the provided modify DN request.- Parameters:
request- The modify DN request.- Returns:
- The result of the operation.
- Throws:
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. ifisClosed() == true.NullPointerException- Ifrequestwasnull.
-
modifyDN
public org.forgerock.opendj.ldap.messages.Result modifyDN(String name, String newRDN) throws org.forgerock.opendj.ldap.LdapException
Renames the named entry in the Directory Server using the provided new RDN.This method is equivalent to the following code:
ModifyDNRequest request = newModifyDNRequest(name, newRDN); connection.modifyDN(request);- Parameters:
name- The distinguished name of the entry to be renamed.newRDN- The new RDN of the entry.- Returns:
- The result of the operation.
- Throws:
org.forgerock.opendj.ldap.LdapException- If the result code indicates that the request failed for some reason.org.forgerock.i18n.LocalizedIllegalArgumentException- IfnameornewRDNcould 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. ifisClosed() == true.NullPointerException- IfnameornewRDNwasnull.
-
readEntry
public org.forgerock.opendj.ldap.messages.SearchResultEntry readEntry(org.forgerock.opendj.ldap.Dn name, String... attributeDescriptions) throws org.forgerock.opendj.ldap.LdapExceptionReads the named entry from the Directory Server.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 returnnull.This method is equivalent to the following code:
SearchRequest request = new SearchRequest(name, SearchScope.BASE_OBJECT, "(objectClass=*)", attributeDescriptions); connection.searchSingleEntry(request);- Parameters:
name- The distinguished name of the entry to be read.attributeDescriptions- The names of the attributes to be included with the entry, which may benullor empty indicating that all user attributes should be returned.- Returns:
- The single search result entry returned from the search.
- Throws:
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. ifisClosed() == true.NullPointerException- If thenamewasnull.
-
readEntry
public org.forgerock.opendj.ldap.messages.SearchResultEntry readEntry(String name, String... attributeDescriptions) throws org.forgerock.opendj.ldap.LdapException
Reads the named entry from the Directory Server.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 returnnull.This method is equivalent to the following code:
SearchRequest request = new SearchRequest(name, SearchScope.BASE_OBJECT, "(objectClass=*)", attributeDescriptions); connection.searchSingleEntry(request);- Parameters:
name- The distinguished name of the entry to be read.attributeDescriptions- The names of the attributes to be included with the entry.- Returns:
- The single search result entry returned from the search.
- Throws:
org.forgerock.opendj.ldap.LdapException- If the result code indicates that the request failed for some reason.org.forgerock.i18n.LocalizedIllegalArgumentException- IfbaseObjectcould 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. ifisClosed() == true.NullPointerException- If thenamewasnull.
-
search
public org.forgerock.opendj.ldif.ConnectionEntryReader search(org.forgerock.opendj.ldap.messages.SearchRequest request)
Searches the Directory Server using the provided search parameters. Any matching entries returned by the search will be exposed through the returnedConnectionEntryReader.Unless otherwise specified, calling this method is equivalent to:
ConnectionEntryReader reader = new ConnectionEntryReader(this, request);- Parameters:
request- The search request.- Returns:
- The result of the operation.
- Throws:
UnsupportedOperationException- If this connection does not support search operations.IllegalStateException- If this connection has already been closed, i.e. ifisClosed() == true.NullPointerException- Ifrequestorentrieswasnull.
-
search
public org.forgerock.opendj.ldap.messages.Result search(org.forgerock.opendj.ldap.messages.SearchRequest request, Collection<? super org.forgerock.opendj.ldap.messages.SearchResultEntry> entries) throws org.forgerock.opendj.ldap.LdapExceptionSearches the Directory Server using the provided search request. Any matching entries returned by the search will be added toentries, 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);- Parameters:
request- The search request.entries- The collection to which matching entries should be added.- Returns:
- The result of the operation.
- Throws:
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. ifisClosed() == true.NullPointerException- Ifrequestorentrieswasnull.
-
search
public org.forgerock.opendj.ldap.messages.Result search(org.forgerock.opendj.ldap.messages.SearchRequest request, Collection<? super org.forgerock.opendj.ldap.messages.SearchResultEntry> entries, Collection<? super org.forgerock.opendj.ldap.messages.SearchResultReference> references) throws org.forgerock.opendj.ldap.LdapExceptionSearches the Directory Server using the provided search request. Any matching entries returned by the search will be added toentries, even if the final search result indicates that the search failed. Similarly, search result references returned by the search will be added toreferences.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.- Parameters:
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, ornullif references are to be discarded.- Returns:
- The result of the operation.
- Throws:
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. ifisClosed() == true.NullPointerException- Ifrequestorentrieswasnull.
-
search
public 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. Any matching entries returned by the search will be exposed through theEntryReaderinterface.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>());- Parameters:
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.- Returns:
- An entry reader exposing the returned entries.
- Throws:
UnsupportedOperationException- If this connection does not support search operations.IllegalStateException- If this connection has already been closed, i.e. ifisClosed() == true.NullPointerException- If thebaseObject,scope, orfilterwerenull.
-
searchSingleEntry
public org.forgerock.opendj.ldap.messages.SearchResultEntry searchSingleEntry(org.forgerock.opendj.ldap.messages.SearchRequest request) throws org.forgerock.opendj.ldap.LdapExceptionSearches the Directory Server for a single entry using the provided search request.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 returnnull. If multiple matching entries are returned by the Directory Server then the request will fail with anMultipleEntriesFoundException.- Parameters:
request- The search request.- Returns:
- The single search result entry returned from the search.
- Throws:
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. ifisClosed() == true.NullPointerException- If therequestwasnull.
-
searchSingleEntry
public org.forgerock.opendj.ldap.messages.SearchResultEntry searchSingleEntry(String baseObject, org.forgerock.opendj.ldap.SearchScope scope, String filter, String... attributeDescriptions) throws org.forgerock.opendj.ldap.LdapException
Searches the Directory Server for a single entry using the provided search parameters.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 returnnull. If multiple matching entries are returned by the Directory Server then the request will fail with anMultipleEntriesFoundException.This method is equivalent to the following code:
SearchRequest request = new SearchRequest(baseObject, scope, filter, attributeDescriptions); connection.searchSingleEntry(request);- Parameters:
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.- Returns:
- The single search result entry returned from the search.
- Throws:
org.forgerock.opendj.ldap.LdapException- If the result code indicates that the request failed for some reason.org.forgerock.i18n.LocalizedIllegalArgumentException- IfbaseObjectcould not be decoded using the default schema or iffilteris 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. ifisClosed() == true.NullPointerException- If thebaseObject,scope, orfilterwerenull.
-
-