public final class MemoryBackend extends Object
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 = newInternalConnection(backend::handleRequest);To create a simple LDAP server listening on 0.0.0.0:1389:
MemoryBackend backend = new MemoryBackend();
LdapServer server = new LdapServer(1389, session -> backend::handleRequest);
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. |
MemoryBackend |
enableVirtualAttributes(boolean enabled)
Indicates whether search responses should include the
hasSubordinates and numSubordinates
virtual attributes if requested. |
Entry |
get(Dn dn)
Returns a deep copy of the named entry contained in this memory backend, or
null if it does not exist. |
Entry |
get(String dn)
Returns a deep copy of 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.
|
Flowable<Response> |
handleRequest(int msgId,
Request request)
Returns a
Flowable which, when subscribed, will apply the provided request to this memory
backend. |
Flowable<Response> |
handleRequest(Request request)
Returns a
Flowable which, when subscribed, will apply the provided request to this memory
backend. |
boolean |
hasSubordinates(Dn dn)
Returns
true if the named entry exists and has at least one child entry. |
boolean |
hasSubordinates(String dn)
Returns
true if the named entry exists and has at least one child entry. |
boolean |
isEmpty()
Returns
true if this memory backend does not contain any entries. |
MemoryBackend |
loadNoOverwrite(EntryReader reader)
Reads all of the entries from the provided entry reader and adds them to
the content of this memory backend.
|
MemoryBackend |
loadOverwrite(EntryReader reader)
Reads all of the entries from the provided entry reader and adds them to
the content of this memory backend replacing any existing entries having
the same name.
|
int |
numSubordinates(Dn dn)
Returns the number of entries which are immediately subordinate to the named entry, or
0 if the named
entry does not exist. |
int |
numSubordinates(String dn)
Returns the number of entries which are immediately subordinate to the named entry, or
0 if the named
entry does not exist. |
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 enableVirtualAttributes(boolean enabled)
hasSubordinates
and numSubordinates
virtual attributes if requested.enabled
- true
if the virtual attributes should be included.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.null
if it does not exist.public Entry get(String dn)
null
if it does not exist.dn
- The name of the entry to be returned.null
if it does not exist.public Collection<Entry> getAll()
public boolean hasSubordinates(String dn)
true
if the named entry exists and has at least one child entry.dn
- The name of the entry.true
if the named entry exists and has at least one child entry.public boolean hasSubordinates(Dn dn)
true
if the named entry exists and has at least one child entry.dn
- The name of the entry.true
if the named entry exists and has at least one child entry.public int numSubordinates(String dn)
0
if the named
entry does not exist.dn
- The name of the entry.public int numSubordinates(Dn dn)
0
if the named
entry does not exist.dn
- The name of the entry.public Flowable<Response> handleRequest(int msgId, Request request)
Flowable
which, when subscribed, will apply the provided request
to this memory
backend. This method is provided to facilitate creation of simple LDAP servers using LdapServer
as well
as in-memory connections for unit testing using
Connections.newInternalConnection(io.reactivex.functions.BiFunction)
.msgId
- The request's message ID.request
- The request.Flowable
which, when subscribed, will apply the provided request
to this memory
backend.public Flowable<Response> handleRequest(Request request)
Flowable
which, when subscribed, will apply the provided request
to this memory
backend.request
- The request.Flowable
which, when subscribed, will apply the provided request
to this memory
backend.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 loadNoOverwrite(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 loadOverwrite(EntryReader reader) throws IOException
reader
- The entry reader.IOException
- If an unexpected IO error occurred while reading the entries.public int size()
Copyright 2010-2022 ForgeRock AS.