Package org.forgerock.opendj.ldap
Class MemoryBackend
java.lang.Object
org.forgerock.opendj.ldap.MemoryBackend
- All Implemented Interfaces:
RequestHandler<RequestContext>
A simple in memory back-end which can be used for testing.
The back-end implementations supports the following:
- add, bind (simple), compare, delete, modify, and search operations, but not modifyDN nor extended operations
- assertion, pre-, and post- read controls, subtree delete control, and permissive modify control
- thread safety - supports concurrent operations
- high performance
- secure password storage
- schema checking
- persistence
- indexing
Connections to create simple servers as well as mock LDAP
connections. For example, to create a mock LDAP connection factory:
MemoryBackend backend = new MemoryBackend();
Connection connection = newInternalConnectionFactory(newServerConnectionFactory(backend), null)
.getConnection();
To create a simple LDAP server listening on 0.0.0.0:1389:
MemoryBackend backend = new MemoryBackend();
LDAPListener listener = new LDAPListener(1389, Connections
.<LDAPClientContext> newServerConnectionFactory(backend));
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new empty memory backend which will use the default schema.MemoryBackend(Schema schema) Creates a new empty memory backend which will use the provided schema.MemoryBackend(Schema schema, EntryReader reader) Creates a new memory backend which will use the provided schema, and will contain the entries read from the provided entry reader.MemoryBackend(EntryReader reader) Creates a new memory backend which will use the default schema, and will contain the entries read from the provided entry reader. -
Method Summary
Modifier and TypeMethodDescriptionclear()Clears the contents of this memory backend so that it does not contain any entries.booleanReturnstrueif the named entry exists in this memory backend.booleanReturnstrueif the named entry exists in this memory backend.enableVirtualAttributes(boolean enabled) Indicates whether search responses should include thehasSubordinatesandnumSubordinatesvirtual attributes if requested.Returns the named entry contained in this memory backend, ornullif it does not exist.Returns the named entry contained in this memory backend, ornullif it does not exist.getAll()Returns a collection containing all of the entries in this memory backend.voidhandleAdd(RequestContext requestContext, AddRequest request, IntermediateResponseHandler intermediateResponseHandler, LdapResultHandler<Result> resultHandler) Invoked when an add request is received from a client.voidhandleBind(RequestContext requestContext, int version, BindRequest request, IntermediateResponseHandler intermediateResponseHandler, LdapResultHandler<BindResult> resultHandler) Invoked when a bind request is received from a client.voidhandleCompare(RequestContext requestContext, CompareRequest request, IntermediateResponseHandler intermediateResponseHandler, LdapResultHandler<CompareResult> resultHandler) Invoked when a compare request is received from a client.voidhandleDelete(RequestContext requestContext, DeleteRequest request, IntermediateResponseHandler intermediateResponseHandler, LdapResultHandler<Result> resultHandler) Invoked when a delete request is received from a client.<R extends ExtendedResult>
voidhandleExtendedRequest(RequestContext requestContext, ExtendedRequest<R> request, IntermediateResponseHandler intermediateResponseHandler, LdapResultHandler<R> resultHandler) Invoked when an extended request is received from a client.voidhandleModify(RequestContext requestContext, ModifyRequest request, IntermediateResponseHandler intermediateResponseHandler, LdapResultHandler<Result> resultHandler) Invoked when a modify request is received from a client.voidhandleModifyDN(RequestContext requestContext, ModifyDNRequest request, IntermediateResponseHandler intermediateResponseHandler, LdapResultHandler<Result> resultHandler) Invoked when a modify DN request is received from a client.voidhandleSearch(RequestContext requestContext, SearchRequest request, IntermediateResponseHandler intermediateResponseHandler, SearchResultHandler entryHandler, LdapResultHandler<Result> resultHandler) Invoked when a search request is received from a client.booleanReturnstrueif the named entry exists and has at least one child entry.booleanhasSubordinates(DN dn) Returnstrueif the named entry exists and has at least one child entry.booleanisEmpty()Returnstrueif this memory backend does not contain any entries.load(EntryReader reader, boolean overwrite) Reads all of the entries from the provided entry reader and adds them to the content of this memory backend.intReturns the number of entries which are immediately subordinate to the named entry, or0if the named entry does not exist.intnumSubordinates(DN dn) Returns the number of entries which are immediately subordinate to the named entry, or0if the named entry does not exist.intsize()Returns the number of entries contained in this memory backend.
-
Constructor Details
-
MemoryBackend
public MemoryBackend()Creates a new empty memory backend which will use the default schema. -
MemoryBackend
Creates a new memory backend which will use the default schema, and will contain the entries read from the provided entry reader.- Parameters:
reader- The entry reader.- Throws:
IOException- If an unexpected IO error occurred while reading the entries, or if duplicate entries are detected.
-
MemoryBackend
Creates a new empty memory backend which will use the provided schema.- Parameters:
schema- The schema to use for decoding filters, etc.
-
MemoryBackend
Creates a new memory backend which will use the provided schema, and will contain the entries read from the provided entry reader.- Parameters:
schema- The schema to use for decoding filters, etc.reader- The entry reader.- Throws:
IOException- If an unexpected IO error occurred while reading the entries, or if duplicate entries are detected.
-
-
Method Details
-
enableVirtualAttributes
Indicates whether search responses should include thehasSubordinatesandnumSubordinatesvirtual attributes if requested.- Parameters:
enabled-trueif the virtual attributes should be included.- Returns:
- This memory backend.
-
clear
Clears the contents of this memory backend so that it does not contain any entries.- Returns:
- This memory backend.
-
contains
Returnstrueif the named entry exists in this memory backend.- Parameters:
dn- The name of the entry.- Returns:
trueif the named entry exists in this memory backend.
-
contains
Returnstrueif the named entry exists in this memory backend.- Parameters:
dn- The name of the entry.- Returns:
trueif the named entry exists in this memory backend.
-
get
Returns the named entry contained in this memory backend, ornullif it does not exist.- Parameters:
dn- The name of the entry to be returned.- Returns:
- The named entry.
-
get
Returns the named entry contained in this memory backend, ornullif it does not exist.- Parameters:
dn- The name of the entry to be returned.- Returns:
- The named entry.
-
getAll
Returns a collection containing all of the entries in this memory backend. The returned collection is backed by this memory backend, so changes to the collection are reflected in this memory backend and vice-versa. The returned collection supports entry removal, iteration, and is thread safe, but it does not support addition of new entries.- Returns:
- A collection containing all of the entries in this memory backend.
-
hasSubordinates
Returnstrueif the named entry exists and has at least one child entry.- Parameters:
dn- The name of the entry.- Returns:
trueif the named entry exists and has at least one child entry.
-
hasSubordinates
Returnstrueif the named entry exists and has at least one child entry.- Parameters:
dn- The name of the entry.- Returns:
trueif the named entry exists and has at least one child entry.
-
numSubordinates
Returns the number of entries which are immediately subordinate to the named entry, or0if the named entry does not exist.- Parameters:
dn- The name of the entry.- Returns:
- The number of entries which are immediately subordinate to the named entry.
-
numSubordinates
Returns the number of entries which are immediately subordinate to the named entry, or0if the named entry does not exist.- Parameters:
dn- The name of the entry.- Returns:
- The number of entries which are immediately subordinate to the named entry.
-
handleAdd
public void handleAdd(RequestContext requestContext, AddRequest request, IntermediateResponseHandler intermediateResponseHandler, LdapResultHandler<Result> resultHandler) Description copied from interface:RequestHandlerInvoked when an add request is received from a client.- Specified by:
handleAddin interfaceRequestHandler<RequestContext>- Parameters:
requestContext- The request context.request- The add request.intermediateResponseHandler- The handler which should be used to send back any intermediate responses to the client.resultHandler- The handler which should be used to send back the result to the client.
-
handleBind
public void handleBind(RequestContext requestContext, int version, BindRequest request, IntermediateResponseHandler intermediateResponseHandler, LdapResultHandler<BindResult> resultHandler) Description copied from interface:RequestHandlerInvoked when a bind request is received from a client.- Specified by:
handleBindin interfaceRequestHandler<RequestContext>- Parameters:
requestContext- The request context.version- The protocol version included with the bind request.request- The bind request.intermediateResponseHandler- The handler which should be used to send back any intermediate responses to the client.resultHandler- The handler which should be used to send back the result to the client.
-
handleCompare
public void handleCompare(RequestContext requestContext, CompareRequest request, IntermediateResponseHandler intermediateResponseHandler, LdapResultHandler<CompareResult> resultHandler) Description copied from interface:RequestHandlerInvoked when a compare request is received from a client.- Specified by:
handleComparein interfaceRequestHandler<RequestContext>- Parameters:
requestContext- The request context.request- The compare request.intermediateResponseHandler- The handler which should be used to send back any intermediate responses to the client.resultHandler- The handler which should be used to send back the result to the client.
-
handleDelete
public void handleDelete(RequestContext requestContext, DeleteRequest request, IntermediateResponseHandler intermediateResponseHandler, LdapResultHandler<Result> resultHandler) Description copied from interface:RequestHandlerInvoked when a delete request is received from a client.- Specified by:
handleDeletein interfaceRequestHandler<RequestContext>- Parameters:
requestContext- The request context.request- The delete request.intermediateResponseHandler- The handler which should be used to send back any intermediate responses to the client.resultHandler- The handler which should be used to send back the result to the client.
-
handleExtendedRequest
public <R extends ExtendedResult> void handleExtendedRequest(RequestContext requestContext, ExtendedRequest<R> request, IntermediateResponseHandler intermediateResponseHandler, LdapResultHandler<R> resultHandler) Description copied from interface:RequestHandlerInvoked when an extended request is received from a client.- Specified by:
handleExtendedRequestin interfaceRequestHandler<RequestContext>- Type Parameters:
R- The type of result returned by the extended request.- Parameters:
requestContext- The request context.request- The extended request.intermediateResponseHandler- The handler which should be used to send back any intermediate responses to the client.resultHandler- The handler which should be used to send back the result to the client.
-
handleModify
public void handleModify(RequestContext requestContext, ModifyRequest request, IntermediateResponseHandler intermediateResponseHandler, LdapResultHandler<Result> resultHandler) Description copied from interface:RequestHandlerInvoked when a modify request is received from a client.- Specified by:
handleModifyin interfaceRequestHandler<RequestContext>- Parameters:
requestContext- The request context.request- The modify request.intermediateResponseHandler- The handler which should be used to send back any intermediate responses to the client.resultHandler- The handler which should be used to send back the result to the client.
-
handleModifyDN
public void handleModifyDN(RequestContext requestContext, ModifyDNRequest request, IntermediateResponseHandler intermediateResponseHandler, LdapResultHandler<Result> resultHandler) Description copied from interface:RequestHandlerInvoked when a modify DN request is received from a client.- Specified by:
handleModifyDNin interfaceRequestHandler<RequestContext>- Parameters:
requestContext- The request context.request- The modify DN request.intermediateResponseHandler- The handler which should be used to send back any intermediate responses to the client.resultHandler- The handler which should be used to send back the result to the client.
-
handleSearch
public void handleSearch(RequestContext requestContext, SearchRequest request, IntermediateResponseHandler intermediateResponseHandler, SearchResultHandler entryHandler, LdapResultHandler<Result> resultHandler) Description copied from interface:RequestHandlerInvoked when a search request is received from a client.- Specified by:
handleSearchin interfaceRequestHandler<RequestContext>- Parameters:
requestContext- The request context.request- The search request.intermediateResponseHandler- The handler which should be used to send back any intermediate responses to the client.entryHandler- The entry handler which should be used to send back the search entries results to the client.resultHandler- The handler which should be used to send back the result to the client.
-
isEmpty
Returnstrueif this memory backend does not contain any entries.- Returns:
trueif this memory backend does not contain any entries.
-
load
Reads all of the entries from the provided entry reader and adds them to the content of this memory backend.- Parameters:
reader- The entry reader.overwrite-trueif existing entries should be replaced, orfalseif an error should be returned when duplicate entries are encountered.- Returns:
- This memory backend.
- Throws:
IOException- If an unexpected IO error occurred while reading the entries, or if duplicate entries are detected andoverwriteisfalse.
-
size
Returns the number of entries contained in this memory backend.- Returns:
- The number of entries contained in this memory backend.
-