Package org.forgerock.opendj.ldap
Class MemoryBackend
java.lang.Object
org.forgerock.opendj.ldap.MemoryBackend
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 = 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 Summary
ConstructorDescriptionCreates 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 TypeMethodDescriptionaddVirtualAttributes
(AttributeDescription attributeDescription, BiFunction<Dn, MemoryBackend, Attribute> virtualAttributeFactory) Adds a virtual attribute to the backend.clear()
Clears the contents of this memory backend so that it does not contain any entries.boolean
Returnstrue
if the named entry exists in this memory backend.boolean
Returnstrue
if the named entry exists in this memory backend.enableVirtualAttributes
(boolean enabled) Indicates whether search responses should include thehasSubordinates
andnumSubordinates
virtual attributes if requested.Returns a deep copy of the named entry contained in this memory backend, ornull
if it does not exist.Returns a deep copy of the named entry contained in this memory backend, ornull
if it does not exist.getAll()
Returns a collection containing all of the entries in this memory backend.Returns the schema used by this backend.handleRequest
(int msgId, Request request) Returns aFlowable
which, when subscribed, will apply the providedrequest
to this memory backend.handleRequest
(Request request) Returns aFlowable
which, when subscribed, will apply the providedrequest
to this memory backend.boolean
Returnstrue
if the named entry exists and has at least one child entry.boolean
hasSubordinates
(Dn dn) Returnstrue
if the named entry exists and has at least one child entry.boolean
isEmpty()
Returnstrue
if this memory backend does not contain any entries.loadNoOverwrite
(EntryReader reader) Reads all of the entries from the provided entry reader and adds them to the content of this memory backend.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
Returns the number of entries which are immediately subordinate to the named entry, or0
if the named entry does not exist.int
numSubordinates
(Dn dn) Returns the number of entries which are immediately subordinate to the named entry, or0
if the named entry does not exist.void
passwordGenerator
(Supplier<byte[]> passwordGenerator) Adds a password generator to the backend.int
size()
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 thehasSubordinates
andnumSubordinates
virtual attributes if requested.- Parameters:
enabled
-true
if the virtual attributes should be included.- Returns:
- This memory backend.
-
addVirtualAttributes
public MemoryBackend addVirtualAttributes(AttributeDescription attributeDescription, BiFunction<Dn, MemoryBackend, Attribute> virtualAttributeFactory) Adds a virtual attribute to the backend. The memory backend will return the entries with the virtual attribute if the search filter contains this virtual attribute.- Parameters:
attributeDescription
- The attribute description of the virtual attribute.virtualAttributeFactory
- The factory to create the virtual attribute.- Returns:
- The memory backend.
-
passwordGenerator
Adds a password generator to the backend.- Parameters:
passwordGenerator
- The password generator of the backend.
-
clear
Clears the contents of this memory backend so that it does not contain any entries.- Returns:
- This memory backend.
-
contains
Returnstrue
if the named entry exists in this memory backend.- Parameters:
dn
- The name of the entry.- Returns:
true
if the named entry exists in this memory backend.
-
contains
Returnstrue
if the named entry exists in this memory backend.- Parameters:
dn
- The name of the entry.- Returns:
true
if the named entry exists in this memory backend.
-
get
Returns a deep copy of the named entry contained in this memory backend, ornull
if it does not exist.- Parameters:
dn
- The name of the entry to be returned.- Returns:
- The deep copy of the named entry, or
null
if it does not exist.
-
get
Returns a deep copy of the named entry contained in this memory backend, ornull
if it does not exist.- Parameters:
dn
- The name of the entry to be returned.- Returns:
- The deep copy of the named entry, or
null
if it does not exist.
-
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
Returnstrue
if the named entry exists and has at least one child entry.- Parameters:
dn
- The name of the entry.- Returns:
true
if the named entry exists and has at least one child entry.
-
hasSubordinates
Returnstrue
if the named entry exists and has at least one child entry.- Parameters:
dn
- The name of the entry.- Returns:
true
if 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, or0
if 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, or0
if 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.
-
handleRequest
Returns aFlowable
which, when subscribed, will apply the providedrequest
to this memory backend. This method is provided to facilitate creation of simple LDAP servers usingLdapServer
as well as in-memory connections for unit testing usingConnections.newInternalConnection(io.reactivex.rxjava3.functions.BiFunction)
.- Parameters:
msgId
- The request's message ID.request
- The request.- Returns:
- A
Flowable
which, when subscribed, will apply the providedrequest
to this memory backend.
-
handleRequest
Returns aFlowable
which, when subscribed, will apply the providedrequest
to this memory backend.- Parameters:
request
- The request.- Returns:
- A
Flowable
which, when subscribed, will apply the providedrequest
to this memory backend.
-
isEmpty
public boolean isEmpty()Returnstrue
if this memory backend does not contain any entries.- Returns:
true
if this memory backend does not contain any entries.
-
loadNoOverwrite
Reads all of the entries from the provided entry reader and adds them to the content of this memory backend. An error will be thrown if any duplicate entries are detected.- Parameters:
reader
- The entry reader.- Returns:
- This memory backend.
- Throws:
IOException
- If an unexpected IO error occurred while reading the entries, or if duplicate entries are detected.
-
loadOverwrite
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.- Parameters:
reader
- The entry reader.- Returns:
- This memory backend.
- Throws:
IOException
- If an unexpected IO error occurred while reading the entries.
-
size
public int size()Returns the number of entries contained in this memory backend.- Returns:
- The number of entries contained in this memory backend.
-
getSchema
Returns the schema used by this backend.- Returns:
- The schema used by this backend.
-