@Mutable @ThreadSafety(level=COMPLETELY_THREADSAFE) public final class InMemoryRequestHandler extends LDAPListenerRequestHandler
Constructor and Description |
---|
InMemoryRequestHandler(InMemoryDirectoryServerConfig config)
Creates a new instance of this request handler with an initially-empty
data set.
|
Modifier and Type | Method and Description |
---|---|
void |
addEntries(java.util.List<? extends Entry> entries)
Attempts to add all of the provided entries to the server.
|
void |
addEntry(Entry entry,
boolean ignoreNoUserModification)
Attempts to add the provided entry to the in-memory data set.
|
void |
assertAttributeExists(java.lang.String dn,
java.util.Collection<java.lang.String> attributeNames)
Ensures that the specified entry exists in the directory with all of the
specified attributes.
|
void |
assertAttributeMissing(java.lang.String dn,
java.util.Collection<java.lang.String> attributeNames)
Ensures that the specified entry exists in the directory but does not
contain any of the specified attributes.
|
void |
assertEntriesExist(java.util.Collection<java.lang.String> dns)
Ensures that all of the entries with the provided DNs exist in the
directory.
|
void |
assertEntryExists(Entry entry)
Ensures that an entry exists in the directory with the same DN and all
attribute values contained in the provided entry.
|
void |
assertEntryExists(java.lang.String dn)
Ensures that an entry with the provided DN exists in the directory.
|
void |
assertEntryExists(java.lang.String dn,
java.lang.String filter)
Ensures that an entry with the provided DN exists in the directory.
|
void |
assertEntryMissing(java.lang.String dn)
Ensures that the specified entry does not exist in the directory.
|
void |
assertValueExists(java.lang.String dn,
java.lang.String attributeName,
java.util.Collection<java.lang.String> attributeValues)
Ensures that the specified entry exists in the directory with all of the
specified values for the given attribute.
|
void |
assertValueMissing(java.lang.String dn,
java.lang.String attributeName,
java.util.Collection<java.lang.String> attributeValues)
Ensures that the specified entry exists in the directory but does not
contain any of the specified attribute values.
|
void |
clear()
Removes all entries currently held in the server.
|
int |
countEntries(boolean includeChangeLog)
Retrieves the number of entries currently held in the server.
|
int |
countEntriesBelow(java.lang.String baseDN)
Retrieves the number of entries currently held in the server whose DN
matches or is subordinate to the provided base DN.
|
InMemoryDirectoryServerSnapshot |
createSnapshot()
Creates a point-in-time snapshot of the information contained in this
in-memory request handler.
|
int |
deleteSubtree(java.lang.String baseDN)
Removes the entry with the specified DN and any subordinate entries it may
have.
|
boolean |
entryExists(Entry entry)
Indicates whether the specified entry exists in the server.
|
boolean |
entryExists(java.lang.String dn)
Indicates whether the specified entry exists in the server.
|
boolean |
entryExists(java.lang.String dn,
java.lang.String filter)
Indicates whether the specified entry exists in the server and matches the
given filter.
|
int |
exportToLDIF(LDIFWriter ldifWriter,
boolean excludeGeneratedAttrs,
boolean excludeChangeLog,
boolean closeWriter)
Writes all entries contained in the server to LDIF using the provided
writer.
|
java.util.Map<DN,byte[]> |
getAdditionalBindCredentials()
Retrieves an unmodifiable map containing the defined set of additional bind
credentials, mapped from bind DN to password bytes.
|
byte[] |
getAdditionalBindCredentials(DN dn)
Retrieves the password for the given DN from the set of additional bind
credentials.
|
DN |
getAuthenticatedDN()
Retrieves the DN of the user currently authenticated on the connection
associated with this request handler instance.
|
java.util.List<DN> |
getBaseDNs()
Retrieves a list of the base DNs configured for use by the server.
|
LDAPListenerClientConnection |
getClientConnection()
Retrieves the client connection associated with this request handler
instance.
|
java.util.Map<java.lang.String,java.lang.Object> |
getConnectionState()
Retrieves a map that may be used to hold state information specific to the
connection associated with this request handler instance.
|
DN |
getDNForAuthzID(java.lang.String authzID)
Attempts to identify the DN of the user referenced by the provided
authorization ID string.
|
ReadOnlyEntry |
getEntry(DN dn)
Retrieves a read-only representation the entry with the specified DN, if
it exists.
|
ReadOnlyEntry |
getEntry(java.lang.String dn)
Retrieves a read-only representation the entry with the specified DN, if
it exists.
|
java.util.List<java.lang.String> |
getMissingAttributeNames(java.lang.String dn,
java.util.Collection<java.lang.String> attributeNames)
Retrieves a list containing all of the named attributes which do not exist
in the target entry.
|
java.util.List<java.lang.String> |
getMissingAttributeValues(java.lang.String dn,
java.lang.String attributeName,
java.util.Collection<java.lang.String> attributeValues)
Retrieves a list of all provided attribute values which are missing from
the specified entry.
|
java.util.List<java.lang.String> |
getMissingEntryDNs(java.util.Collection<java.lang.String> dns)
Retrieves a list containing the DNs of the entries which are missing from
the directory server.
|
long |
getProcessingDelayMillis()
Retrieves the delay in milliseconds that the server should impose before
beginning processing for operations.
|
Schema |
getSchema()
Retrieves the schema that will be used by the server, if any.
|
int |
importFromLDIF(boolean clear,
LDIFReader ldifReader)
Reads entries from the provided LDIF reader and adds them to the server,
optionally clearing any existing entries before beginning to add the new
entries.
|
void |
modifyEntry(java.lang.String dn,
java.util.List<Modification> mods)
Attempts to apply the provided set of modifications to the specified entry.
|
InMemoryRequestHandler |
newInstance(LDAPListenerClientConnection connection)
Creates a new instance of this request handler that will be used to process
requests read by the provided connection.
|
LDAPMessage |
processAddRequest(int messageID,
AddRequestProtocolOp request,
java.util.List<Control> controls)
Attempts to add an entry to the in-memory data set.
|
LDAPMessage |
processBindRequest(int messageID,
BindRequestProtocolOp request,
java.util.List<Control> controls)
Attempts to process the provided bind request.
|
LDAPMessage |
processCompareRequest(int messageID,
CompareRequestProtocolOp request,
java.util.List<Control> controls)
Attempts to process the provided compare request.
|
LDAPMessage |
processDeleteRequest(int messageID,
DeleteRequestProtocolOp request,
java.util.List<Control> controls)
Attempts to process the provided delete request.
|
LDAPMessage |
processExtendedRequest(int messageID,
ExtendedRequestProtocolOp request,
java.util.List<Control> controls)
Attempts to process the provided extended request, if an extended operation
handler is defined for the given request OID.
|
LDAPMessage |
processModifyDNRequest(int messageID,
ModifyDNRequestProtocolOp request,
java.util.List<Control> controls)
Attempts to process the provided modify DN request.
|
LDAPMessage |
processModifyRequest(int messageID,
ModifyRequestProtocolOp request,
java.util.List<Control> controls)
Attempts to process the provided modify request.
|
LDAPMessage |
processSearchRequest(int messageID,
SearchRequestProtocolOp request,
java.util.List<Control> controls)
Attempts to process the provided search request.
|
void |
restoreSnapshot(InMemoryDirectoryServerSnapshot snapshot)
Updates the content of this in-memory request handler to match what it was
at the time the snapshot was created.
|
java.util.List<ReadOnlyEntry> |
search(java.lang.String baseDN,
SearchScope scope,
Filter filter)
Retrieves a list of all entries in the server which match the given
search criteria.
|
void |
setAuthenticatedDN(DN authenticatedDN)
Sets the DN of the user currently authenticated on the connection
associated with this request handler instance.
|
void |
setProcessingDelayMillis(long processingDelayMillis)
Specifies the delay in milliseconds that the server should impose before
beginning processing for operations.
|
closeInstance, processAbandonRequest, processUnbindRequest
public InMemoryRequestHandler(InMemoryDirectoryServerConfig config) throws LDAPException
config
- The configuration that should be used for the in-memory
directory server.LDAPException
- If there is a problem with the provided
configuration.public InMemoryRequestHandler newInstance(LDAPListenerClientConnection connection) throws LDAPException
newInstance
in class LDAPListenerRequestHandler
connection
- The connection with which this request handler instance
will be associated.LDAPException
- If the connection should not be accepted.public InMemoryDirectoryServerSnapshot createSnapshot()
restoreSnapshot(com.unboundid.ldap.listener.InMemoryDirectoryServerSnapshot)
method.public void restoreSnapshot(InMemoryDirectoryServerSnapshot snapshot)
snapshot
- The snapshot to be restored. It must not be
null
.public Schema getSchema()
null
if
none has been configured.public java.util.List<DN> getBaseDNs()
public LDAPListenerClientConnection getClientConnection()
null
if this instance is not associated with
any client connection.public DN getAuthenticatedDN()
DN#NULL_DN
if the connection is unauthenticated or is
authenticated as the anonymous user.public void setAuthenticatedDN(DN authenticatedDN)
authenticatedDN
- The DN of the user currently authenticated on the
connection associated with this request handler.
It may be null
or DN.NULL_DN
to
indicate that the connection is unauthenticated.public java.util.Map<DN,byte[]> getAdditionalBindCredentials()
public byte[] getAdditionalBindCredentials(DN dn)
dn
- The DN for which to retrieve the corresponding password.null
if the
additional bind credentials does not include information for the
provided DN.public java.util.Map<java.lang.String,java.lang.Object> getConnectionState()
public long getProcessingDelayMillis()
public void setProcessingDelayMillis(long processingDelayMillis)
processingDelayMillis
- The delay in milliseconds that the server
should impose before beginning processing
for operations. A value less than or equal
to zero may be used to indicate that there
should be no delay.public LDAPMessage processAddRequest(int messageID, AddRequestProtocolOp request, java.util.List<Control> controls)
processAddRequest
in class LDAPListenerRequestHandler
messageID
- The message ID of the LDAP message containing the add
request.request
- The add request that was included in the LDAP message
that was received.controls
- The set of controls included in the LDAP message. It
may be empty if there were no controls, but will not be
null
.LDAPMessage
containing the response to send to the
client. The protocol op in the LDAPMessage
must be an
AddResponseProtocolOp
.public LDAPMessage processBindRequest(int messageID, BindRequestProtocolOp request, java.util.List<Control> controls)
processBindRequest
in class LDAPListenerRequestHandler
messageID
- The message ID of the LDAP message containing the bind
request.request
- The bind request that was included in the LDAP message
that was received.controls
- The set of controls included in the LDAP message. It
may be empty if there were no controls, but will not be
null
.LDAPMessage
containing the response to send to the
client. The protocol op in the LDAPMessage
must be a
BindResponseProtocolOp
.public LDAPMessage processCompareRequest(int messageID, CompareRequestProtocolOp request, java.util.List<Control> controls)
processCompareRequest
in class LDAPListenerRequestHandler
messageID
- The message ID of the LDAP message containing the
compare request.request
- The compare request that was included in the LDAP
message that was received.controls
- The set of controls included in the LDAP message. It
may be empty if there were no controls, but will not be
null
.LDAPMessage
containing the response to send to the
client. The protocol op in the LDAPMessage
must be a
CompareResponseProtocolOp
.public LDAPMessage processDeleteRequest(int messageID, DeleteRequestProtocolOp request, java.util.List<Control> controls)
processDeleteRequest
in class LDAPListenerRequestHandler
messageID
- The message ID of the LDAP message containing the delete
request.request
- The delete request that was included in the LDAP message
that was received.controls
- The set of controls included in the LDAP message. It
may be empty if there were no controls, but will not be
null
.LDAPMessage
containing the response to send to the
client. The protocol op in the LDAPMessage
must be a
DeleteResponseProtocolOp
.public LDAPMessage processExtendedRequest(int messageID, ExtendedRequestProtocolOp request, java.util.List<Control> controls)
processExtendedRequest
in class LDAPListenerRequestHandler
messageID
- The message ID of the LDAP message containing the
extended request.request
- The extended request that was included in the LDAP
message that was received.controls
- The set of controls included in the LDAP message. It
may be empty if there were no controls, but will not be
null
.LDAPMessage
containing the response to send to the
client. The protocol op in the LDAPMessage
must be an
ExtendedResponseProtocolOp
.public LDAPMessage processModifyRequest(int messageID, ModifyRequestProtocolOp request, java.util.List<Control> controls)
processModifyRequest
in class LDAPListenerRequestHandler
messageID
- The message ID of the LDAP message containing the modify
request.request
- The modify request that was included in the LDAP message
that was received.controls
- The set of controls included in the LDAP message. It
may be empty if there were no controls, but will not be
null
.LDAPMessage
containing the response to send to the
client. The protocol op in the LDAPMessage
must be an
ModifyResponseProtocolOp
.public LDAPMessage processModifyDNRequest(int messageID, ModifyDNRequestProtocolOp request, java.util.List<Control> controls)
processModifyDNRequest
in class LDAPListenerRequestHandler
messageID
- The message ID of the LDAP message containing the modify
DN request.request
- The modify DN request that was included in the LDAP
message that was received.controls
- The set of controls included in the LDAP message. It
may be empty if there were no controls, but will not be
null
.LDAPMessage
containing the response to send to the
client. The protocol op in the LDAPMessage
must be an
ModifyDNResponseProtocolOp
.public LDAPMessage processSearchRequest(int messageID, SearchRequestProtocolOp request, java.util.List<Control> controls)
processSearchRequest
in class LDAPListenerRequestHandler
messageID
- The message ID of the LDAP message containing the search
request.request
- The search request that was included in the LDAP message
that was received.controls
- The set of controls included in the LDAP message. It
may be empty if there were no controls, but will not be
null
.LDAPMessage
containing the response to send to the
client. The protocol op in the LDAPMessage
must be an
SearchResultDoneProtocolOp
.public int countEntries(boolean includeChangeLog)
includeChangeLog
- Indicates whether to include entries that are
part of the changelog in the count.public int countEntriesBelow(java.lang.String baseDN) throws LDAPException
baseDN
- The base DN to use for the determination.LDAPException
- If the provided string cannot be parsed as a valid
DN.public void clear()
public int importFromLDIF(boolean clear, LDIFReader ldifReader) throws LDAPException
clear
is given with a value of true
).clear
- Indicates whether to remove all existing entries prior
to adding entries read from LDIF.ldifReader
- The LDIF reader to use to obtain the entries to be
imported.LDAPException
- If a problem occurs while reading entries or adding
them to the server.public int exportToLDIF(LDIFWriter ldifWriter, boolean excludeGeneratedAttrs, boolean excludeChangeLog, boolean closeWriter) throws LDAPException
ldifWriter
- The LDIF writer to use when writing the
entries. It must not be null
.excludeGeneratedAttrs
- Indicates whether to exclude automatically
generated operational attributes like
entryUUID, entryDN, creatorsName, etc.excludeChangeLog
- Indicates whether to exclude entries
contained in the changelog.closeWriter
- Indicates whether the LDIF writer should be
closed after all entries have been written.LDAPException
- If a problem is encountered while attempting to
write an entry to LDIF.public void addEntry(Entry entry, boolean ignoreNoUserModification) throws LDAPException
entry
- The entry to be added. It must not be
null
.ignoreNoUserModification
- Indicates whether to ignore constraints
normally imposed by the
NO-USER-MODIFICATION element in attribute
type definitions.LDAPException
- If a problem occurs while attempting to add the
provided entry.public void addEntries(java.util.List<? extends Entry> entries) throws LDAPException
entries
- The collection of entries to be added.LDAPException
- If a problem was encountered while attempting to
add any of the entries to the server.public int deleteSubtree(java.lang.String baseDN) throws LDAPException
baseDN
- The DN of the entry to be deleted. It must not be
null
or represent the null DN.LDAPException
- If the provided base DN is not a valid DN, or is
the DN of an entry that cannot be deleted (e.g.,
the null DN).public void modifyEntry(java.lang.String dn, java.util.List<Modification> mods) throws LDAPException
dn
- The DN of the entry to be modified.mods
- The set of modifications to be applied to the entry.LDAPException
- If a problem is encountered while attempting to
update the specified entry.public ReadOnlyEntry getEntry(java.lang.String dn) throws LDAPException
dn
- The DN of the entry to retrieve.null
if no entry exists with the
given DN.LDAPException
- If the provided DN is malformed.public ReadOnlyEntry getEntry(DN dn)
dn
- The DN of the entry to retrieve.null
if no entry exists with the
given DN.public java.util.List<ReadOnlyEntry> search(java.lang.String baseDN, SearchScope scope, Filter filter) throws LDAPException
baseDN
- The base DN to use for the search. It must not be
null
.scope
- The scope to use for the search. It must not be
null
.filter
- The filter to use for the search. It must not be
null
.LDAPException
- If a problem is encountered while performing the
search.public DN getDNForAuthzID(java.lang.String authzID) throws LDAPException
authzID
- The authorization ID to resolve to a user DN.LDAPException
- If a problem prevents resolving the authorization
ID to a user DN.public boolean entryExists(java.lang.String dn) throws LDAPException
dn
- The DN of the entry for which to make the determination.true
if the entry exists, or false
if not.LDAPException
- If a problem is encountered while trying to
communicate with the directory server.public boolean entryExists(java.lang.String dn, java.lang.String filter) throws LDAPException
dn
- The DN of the entry for which to make the determination.filter
- The filter the entry is expected to match.true
if the entry exists and matches the specified filter,
or false
if not.LDAPException
- If a problem is encountered while trying to
communicate with the directory server.public boolean entryExists(Entry entry) throws LDAPException
true
only if the target entry exists and contains all values
for all attributes of the provided entry. The entry will be allowed to
have attribute values not included in the provided entry.entry
- The entry to compare against the directory server.true
if the entry exists in the server and is a superset
of the provided entry, or false
if not.LDAPException
- If a problem is encountered while trying to
communicate with the directory server.public void assertEntryExists(java.lang.String dn) throws LDAPException, java.lang.AssertionError
dn
- The DN of the entry for which to make the determination.LDAPException
- If a problem is encountered while trying to
communicate with the directory server.java.lang.AssertionError
- If the target entry does not exist.public void assertEntryExists(java.lang.String dn, java.lang.String filter) throws LDAPException, java.lang.AssertionError
dn
- The DN of the entry for which to make the determination.filter
- A filter that the target entry must match.LDAPException
- If a problem is encountered while trying to
communicate with the directory server.java.lang.AssertionError
- If the target entry does not exist or does not
match the provided filter.public void assertEntryExists(Entry entry) throws LDAPException, java.lang.AssertionError
entry
- The entry expected to be present in the directory server.LDAPException
- If a problem is encountered while trying to
communicate with the directory server.java.lang.AssertionError
- If the target entry does not exist or does not
match the provided filter.public java.util.List<java.lang.String> getMissingEntryDNs(java.util.Collection<java.lang.String> dns) throws LDAPException
dns
- The DNs of the entries to try to find in the server.LDAPException
- If a problem is encountered while trying to
communicate with the directory server.public void assertEntriesExist(java.util.Collection<java.lang.String> dns) throws LDAPException, java.lang.AssertionError
dns
- The DNs of the entries for which to make the determination.LDAPException
- If a problem is encountered while trying to
communicate with the directory server.java.lang.AssertionError
- If any of the target entries does not exist.public java.util.List<java.lang.String> getMissingAttributeNames(java.lang.String dn, java.util.Collection<java.lang.String> attributeNames) throws LDAPException
dn
- The DN of the entry to examine.attributeNames
- The names of the attributes expected to be present
in the target entry.null
if the target
entry does not exist.LDAPException
- If a problem is encountered while trying to
communicate with the directory server.public void assertAttributeExists(java.lang.String dn, java.util.Collection<java.lang.String> attributeNames) throws LDAPException, java.lang.AssertionError
dn
- The DN of the entry to examine.attributeNames
- The names of the attributes that are expected to be
present in the provided entry.LDAPException
- If a problem is encountered while trying to
communicate with the directory server.java.lang.AssertionError
- If the target entry does not exist or does not
contain all of the specified attributes.public java.util.List<java.lang.String> getMissingAttributeValues(java.lang.String dn, java.lang.String attributeName, java.util.Collection<java.lang.String> attributeValues) throws LDAPException
dn
- The DN of the entry to examine.attributeName
- The attribute expected to be present in the target
entry with the given values.attributeValues
- The values expected to be present in the target
entry.null
if the target entry does not exist.LDAPException
- If a problem is encountered while trying to
communicate with the directory server.public void assertValueExists(java.lang.String dn, java.lang.String attributeName, java.util.Collection<java.lang.String> attributeValues) throws LDAPException, java.lang.AssertionError
dn
- The DN of the entry to examine.attributeName
- The name of the attribute to examine.attributeValues
- The set of values which must exist for the given
attribute.LDAPException
- If a problem is encountered while trying to
communicate with the directory server.java.lang.AssertionError
- If the target entry does not exist, does not
contain the specified attribute, or that attribute
does not have all of the specified values.public void assertEntryMissing(java.lang.String dn) throws LDAPException, java.lang.AssertionError
dn
- The DN of the entry expected to be missing.LDAPException
- If a problem is encountered while trying to
communicate with the directory server.java.lang.AssertionError
- If the target entry is found in the server.public void assertAttributeMissing(java.lang.String dn, java.util.Collection<java.lang.String> attributeNames) throws LDAPException, java.lang.AssertionError
dn
- The DN of the entry expected to be present.attributeNames
- The names of the attributes expected to be missing
from the entry.LDAPException
- If a problem is encountered while trying to
communicate with the directory server.java.lang.AssertionError
- If the target entry is missing from the server, or
if it contains any of the target attributes.public void assertValueMissing(java.lang.String dn, java.lang.String attributeName, java.util.Collection<java.lang.String> attributeValues) throws LDAPException, java.lang.AssertionError
dn
- The DN of the entry expected to be present.attributeName
- The name of the attribute to examine.attributeValues
- The values expected to be missing from the target
entry.LDAPException
- If a problem is encountered while trying to
communicate with the directory server.java.lang.AssertionError
- If the target entry is missing from the server, or
if it contains any of the target attribute values.