public final class MemoryBackend extends Object implements RequestHandler<RequestContext>
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 and Description |
---|
MemoryBackend()
Creates a new empty memory backend which will use the default schema.
|
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.
|
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.
|
Modifier and Type | Method and Description |
---|---|
MemoryBackend |
clear()
Clears the contents of this memory backend so that it does not contain
any entries.
|
boolean |
contains(DN dn)
Returns
true if the named entry exists in this memory backend. |
boolean |
contains(String dn)
Returns
true if the named entry exists in this memory backend. |
Entry |
get(DN dn)
Returns the named entry contained in this memory backend, or
null
if it does not exist. |
Entry |
get(String dn)
Returns the named entry contained in this memory backend, or
null
if it does not exist. |
Collection<Entry> |
getAll()
Returns a collection containing all of the entries in this memory
backend.
|
void |
handleAdd(RequestContext requestContext,
AddRequest request,
IntermediateResponseHandler intermediateResponseHandler,
LdapResultHandler<Result> resultHandler)
Invoked when an add request is received from a client.
|
void |
handleBind(RequestContext requestContext,
int version,
BindRequest request,
IntermediateResponseHandler intermediateResponseHandler,
LdapResultHandler<BindResult> resultHandler)
Invoked when a bind request is received from a client.
|
void |
handleCompare(RequestContext requestContext,
CompareRequest request,
IntermediateResponseHandler intermediateResponseHandler,
LdapResultHandler<CompareResult> resultHandler)
Invoked when a compare request is received from a client.
|
void |
handleDelete(RequestContext requestContext,
DeleteRequest request,
IntermediateResponseHandler intermediateResponseHandler,
LdapResultHandler<Result> resultHandler)
Invoked when a delete request is received from a client.
|
<R extends ExtendedResult> |
handleExtendedRequest(RequestContext requestContext,
ExtendedRequest<R> request,
IntermediateResponseHandler intermediateResponseHandler,
LdapResultHandler<R> resultHandler)
Invoked when an extended request is received from a client.
|
void |
handleModify(RequestContext requestContext,
ModifyRequest request,
IntermediateResponseHandler intermediateResponseHandler,
LdapResultHandler<Result> resultHandler)
Invoked when a modify request is received from a client.
|
void |
handleModifyDN(RequestContext requestContext,
ModifyDNRequest request,
IntermediateResponseHandler intermediateResponseHandler,
LdapResultHandler<Result> resultHandler)
Invoked when a modify DN request is received from a client.
|
void |
handleSearch(RequestContext requestContext,
SearchRequest request,
IntermediateResponseHandler intermediateResponseHandler,
SearchResultHandler entryHandler,
LdapResultHandler<Result> resultHandler)
Invoked when a search request is received from a client.
|
boolean |
isEmpty()
Returns
true if this memory backend does not contain any entries. |
MemoryBackend |
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.
|
int |
size()
Returns the number of entries contained in this memory backend.
|
public MemoryBackend()
public MemoryBackend(EntryReader reader) throws IOException
reader
- The entry reader.IOException
- If an unexpected IO error occurred while reading the entries,
or if duplicate entries are detected.public MemoryBackend(Schema schema)
schema
- The schema to use for decoding filters, etc.public MemoryBackend(Schema schema, EntryReader reader) throws IOException
schema
- The schema to use for decoding filters, etc.reader
- The entry reader.IOException
- If an unexpected IO error occurred while reading the entries,
or if duplicate entries are detected.public MemoryBackend clear()
public boolean contains(DN dn)
true
if the named entry exists in this memory backend.dn
- The name of the entry.true
if the named entry exists in this memory backend.public boolean contains(String dn)
true
if the named entry exists in this memory backend.dn
- The name of the entry.true
if the named entry exists in this memory backend.public Entry get(DN dn)
null
if it does not exist.dn
- The name of the entry to be returned.public Entry get(String dn)
null
if it does not exist.dn
- The name of the entry to be returned.public Collection<Entry> getAll()
public void handleAdd(RequestContext requestContext, AddRequest request, IntermediateResponseHandler intermediateResponseHandler, LdapResultHandler<Result> resultHandler)
RequestHandler
handleAdd
in interface RequestHandler<RequestContext>
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.public void handleBind(RequestContext requestContext, int version, BindRequest request, IntermediateResponseHandler intermediateResponseHandler, LdapResultHandler<BindResult> resultHandler)
RequestHandler
handleBind
in interface RequestHandler<RequestContext>
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.public void handleCompare(RequestContext requestContext, CompareRequest request, IntermediateResponseHandler intermediateResponseHandler, LdapResultHandler<CompareResult> resultHandler)
RequestHandler
handleCompare
in interface RequestHandler<RequestContext>
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.public void handleDelete(RequestContext requestContext, DeleteRequest request, IntermediateResponseHandler intermediateResponseHandler, LdapResultHandler<Result> resultHandler)
RequestHandler
handleDelete
in interface RequestHandler<RequestContext>
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.public <R extends ExtendedResult> void handleExtendedRequest(RequestContext requestContext, ExtendedRequest<R> request, IntermediateResponseHandler intermediateResponseHandler, LdapResultHandler<R> resultHandler)
RequestHandler
handleExtendedRequest
in interface RequestHandler<RequestContext>
R
- The type of result returned by the extended request.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.public void handleModify(RequestContext requestContext, ModifyRequest request, IntermediateResponseHandler intermediateResponseHandler, LdapResultHandler<Result> resultHandler)
RequestHandler
handleModify
in interface RequestHandler<RequestContext>
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.public void handleModifyDN(RequestContext requestContext, ModifyDNRequest request, IntermediateResponseHandler intermediateResponseHandler, LdapResultHandler<Result> resultHandler)
RequestHandler
handleModifyDN
in interface RequestHandler<RequestContext>
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.public void handleSearch(RequestContext requestContext, SearchRequest request, IntermediateResponseHandler intermediateResponseHandler, SearchResultHandler entryHandler, LdapResultHandler<Result> resultHandler)
RequestHandler
handleSearch
in interface RequestHandler<RequestContext>
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.public boolean isEmpty()
true
if this memory backend does not contain any entries.true
if this memory backend does not contain any entries.public MemoryBackend load(EntryReader reader, boolean overwrite) throws IOException
reader
- The entry reader.overwrite
- true
if existing entries should be replaced, or
false
if an error should be returned when duplicate
entries are encountered.IOException
- If an unexpected IO error occurred while reading the entries,
or if duplicate entries are detected and overwrite
is
false
.public int size()
Copyright 2010-2017 ForgeRock AS.