Package org.forgerock.opendj.server.core
Class RequestContext
- java.lang.Object
-
- org.forgerock.opendj.server.core.AbstractContext
-
- org.forgerock.opendj.server.core.RequestContext
-
- All Implemented Interfaces:
org.forgerock.services.context.Context
public class RequestContext extends AbstractContext
A context that maintains information about a request.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
RequestContext.RequestFlag
Distinguishes operations from server components, not directly from LDAP clients.
-
Constructor Summary
Constructors Constructor Description RequestContext(int messageId, long operationId, org.forgerock.services.context.Context parent)
Creates a new request context.RequestContext(int messageId, long operationId, org.forgerock.services.context.Context parent, Set<RequestContext.RequestFlag> requestFlags)
Creates a new request context, by also specifying additional request settings.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addAdditionalLogItem(AdditionalLogItem item)
Adds aAdditionalLogItem
to the list for logging.void
addCancelRequestListener(CancelRequestListener listener)
Registers the provided cancellation listener with this request context so that it can be notified if a cancellation request is received and processing of the request should be aborted if possible.void
appendMaskedErrorMessage(LocalizableMessage maskedMessage)
Appends the provided message to the real, masked error message buffer.void
cannotCancel(LocalizableMessage cannotCancelReason)
Marks the request associated to this request context as not cancellable.void
checkIfCancelled(boolean signalTooLate)
ThrowsCancelledResultException
if a cancellation request has been received and processing of the request should be aborted if possible.RequestContext
etimeStarted(CoreConfigManager.EtimeService timeService)
Sets the time at which processing started for this request.RequestContext
etimeStopped()
Sets the time at which the processing stopped for this request.List<AdditionalLogItem>
getAdditionalLogItems()
Returns additional information to be logged, as a potentially emptyList
ofAdditionalLogItem
.Dn
getAuthenticationDn()
Returns the authentication Dn for logging.LocalizableMessage
getAuthFailureReason()
Returns a human-readable message providing the reason why the authentication failed, if available.Dn
getAuthorizationDn()
Returns the authorization Dn for logging, which could be from proxy auth.FlowableOperator<Response,Response>
getCancellationOperator()
Returns a probe monitoring the response sent to the client in order to maintain the cancellation state.ConnectionContext
getConnectionContext()
Returns the connection context associated to this context.Entry
getEntryAsAddedByServer()
Returns the entry as added by the server, with all additional operational attributes.LocalizableMessageBuilder
getMaskedErrorMessage()
Retrieves the real, masked error message for this operation.ResultCode
getMaskedResultCode()
Retrieves the real, masked result code for this operation.int
getMessageId()
Returns the message id associated to the request.List<Modification>
getModificationsAsAppliedByServer()
Returns the list of modifications applied by the server.long
getOperationId()
Returns the operation id associated to the request.long
getProcessingTime()
Returns the processing time for the request.TimeUnit
getProcessingTimeUnit()
Returns the processing time unit for the request.Dn
getProxiedAuthorizationDn()
Returns the proxied authorization DN if proxy authorization has been requested.int
getSearchNumberOfEntriesReturned()
Returns the number of entries sent by the search request associated to this context.boolean
hasFlag(RequestContext.RequestFlag requestFlag)
Returns whether this request has the provided flag.boolean
hasPrivilege(Privilege privilege)
Returnstrue
if the authorized user has the specified privilege.void
setAdditionalLogItems(List<AdditionalLogItem> items)
Sets theAdditionalLogItem
s.void
setAuthFailureReason(LocalizableMessage reason)
Specifies the reason why authentication failed.void
setCancelled()
Notifies the request has been aborted.void
setEntryAsAddedByServer(Entry entryAsAddedByServer)
Sets the entry added as added by the server in the DIT.RequestContext
setMaskedResultCode(ResultCode maskedResultCode)
Specifies the real, masked result code for this operation.void
setModificationsAsAppliedByServer(List<Modification> modificationsAsAppliedByServer)
Sets the list of modifications applied to an entry by the server while processing a Modify request.RequestContext
setProxiedAuthorizationDn(Dn proxiedAuthorizationDn)
Set the proxied authorization DN for this operation if any.void
setSearchNumberOfEntriesReturned(int searchNumberOfEntriesReturned)
Sets the number of entries returned by the search request associated to this context.boolean
shouldSendResult()
Returnstrue
if the result should be forwarded to the client.-
Methods inherited from class org.forgerock.opendj.server.core.AbstractContext
asContext, containsContext, containsContext, getContext, getContextName, getId, getParent, getRootId, isRootContext, toJsonValue, toString
-
-
-
-
Constructor Detail
-
RequestContext
public RequestContext(int messageId, long operationId, org.forgerock.services.context.Context parent)
Creates a new request context.- Parameters:
messageId
- The message id associated to this request.operationId
- The operation id associated to this request.parent
- The parent context.
-
RequestContext
public RequestContext(int messageId, long operationId, org.forgerock.services.context.Context parent, Set<RequestContext.RequestFlag> requestFlags)
Creates a new request context, by also specifying additional request settings.- Parameters:
messageId
- The message id associated to this request.operationId
- The operation id associated to this request.parent
- The parent context.requestFlags
- The set of additional flags for this request
-
-
Method Detail
-
getAuthenticationDn
public Dn getAuthenticationDn()
Returns the authentication Dn for logging.- Returns:
- a
Dn
-
getAuthorizationDn
public Dn getAuthorizationDn()
Returns the authorization Dn for logging, which could be from proxy auth.- Returns:
- a
Dn
ornull
if there is nothing to log.
-
getEntryAsAddedByServer
public Entry getEntryAsAddedByServer()
Returns the entry as added by the server, with all additional operational attributes.May differ from the entry specified in the Add request as attributes may be encoded, audit log will preferentially use the server entry.
- Returns:
- the entry as added by the server, with all additional operational attributes
-
setEntryAsAddedByServer
public void setEntryAsAddedByServer(Entry entryAsAddedByServer)
Sets the entry added as added by the server in the DIT.- Parameters:
entryAsAddedByServer
- the entry added by the server
-
getModificationsAsAppliedByServer
public List<Modification> getModificationsAsAppliedByServer()
Returns the list of modifications applied by the server.May differ from client specified modifications as some attributes may be encoded, audit log will preferentially use the returned list.
- Returns:
- the list of modifications applied by the server
-
setModificationsAsAppliedByServer
public void setModificationsAsAppliedByServer(List<Modification> modificationsAsAppliedByServer)
Sets the list of modifications applied to an entry by the server while processing a Modify request.- Parameters:
modificationsAsAppliedByServer
- the list of modifications generated by the server
-
getCancellationOperator
public FlowableOperator<Response,Response> getCancellationOperator()
Returns a probe monitoring the response sent to the client in order to maintain the cancellation state.- Returns:
- The response probe instance of this request context.
-
addCancelRequestListener
public void addCancelRequestListener(CancelRequestListener listener)
Registers the provided cancellation listener with this request context so that it can be notified if a cancellation request is received and processing of the request should be aborted if possible. Requests may be cancelled as a result of an abandon request or a cancel extended request sent from the client, or by the server itself (e.g. during server shutdown). This method provides an event notification mechanism which can be used by asynchronous request handler implementations to detect cancellation of requests.- Parameters:
listener
- The listener which should be notified if processing of the request should be aborted if possible.- Throws:
NullPointerException
- If thelistener
wasnull
.- See Also:
checkIfCancelled(boolean)
-
checkIfCancelled
public void checkIfCancelled(boolean signalTooLate) throws CancelledResultException
ThrowsCancelledResultException
if a cancellation request has been received and processing of the request should be aborted if possible. Requests may be cancelled as a result of an abandon request or a cancel extended request sent from the client, or by the server itself (e.g. during server shutdown). This method provides a polling mechanism which can be used by synchronous request handler implementations to detect cancellation of requests.- Parameters:
signalTooLate
-true
to signal that, after this method returns, processing of the request will have proceeded too far for it to be aborted by subsequent cancellation requests.- Throws:
CancelledResultException
- If processing of the request should be aborted if possible.- See Also:
addCancelRequestListener(org.forgerock.opendj.server.core.CancelRequestListener)
-
setCancelled
public void setCancelled()
Notifies the request has been aborted.
-
cannotCancel
public void cannotCancel(LocalizableMessage cannotCancelReason)
Marks the request associated to this request context as not cancellable. Any cancellation request will then be rejected with aResultCode.CANNOT_CANCEL
and the provided reason.- Parameters:
cannotCancelReason
- The reason which will be provided in the cancel responses.
-
shouldSendResult
public boolean shouldSendResult()
Returnstrue
if the result should be forwarded to the client. Results are dropped for abandoned requests.- Returns:
true
if the result should be forwarded to the client.
-
hasFlag
public boolean hasFlag(RequestContext.RequestFlag requestFlag)
Returns whether this request has the provided flag.- Parameters:
requestFlag
- the request flag to test for- Returns:
true
if this request has the provided flag
-
getMessageId
public int getMessageId()
Returns the message id associated to the request.- Returns:
- the message id
-
getOperationId
public long getOperationId()
Returns the operation id associated to the request.- Returns:
- the operation id
-
hasPrivilege
public boolean hasPrivilege(Privilege privilege)
Returnstrue
if the authorized user has the specified privilege.- Parameters:
privilege
- The required privilege.- Returns:
true
if the authorized user has the specified privilege.
-
getConnectionContext
public ConnectionContext getConnectionContext()
Returns the connection context associated to this context.- Returns:
- the connection context
-
etimeStarted
public RequestContext etimeStarted(CoreConfigManager.EtimeService timeService)
Sets the time at which processing started for this request.- Parameters:
timeService
- theCoreConfigManager.EtimeService
for computing processing time for the request- Returns:
- the current context
-
etimeStopped
public RequestContext etimeStopped()
Sets the time at which the processing stopped for this request.- Returns:
- the current context
-
getProcessingTime
public long getProcessingTime()
Returns the processing time for the request.- Returns:
- the processing time for the request
-
getProcessingTimeUnit
public TimeUnit getProcessingTimeUnit()
Returns the processing time unit for the request.- Returns:
- the processing time unit for the request
-
getMaskedResultCode
public ResultCode getMaskedResultCode()
Retrieves the real, masked result code for this operation.- Returns:
- The real, masked result code associated for this operation, or
null
if there is no need for one
-
setMaskedResultCode
public RequestContext setMaskedResultCode(ResultCode maskedResultCode)
Specifies the real, masked result code for this operation. This method may not be called by post-response plugins. Anull
value will reset to not having a masked error code to log.- Parameters:
maskedResultCode
- The real, masked result code for this operation Ifnull
, the masked error message will be removed.- Returns:
- the current context
-
getMaskedErrorMessage
public LocalizableMessageBuilder getMaskedErrorMessage()
Retrieves the real, masked error message for this operation. Its contents may be altered by pre-parse, pre-operation, and post-operation plugins, but not by post-response plugins.- Returns:
- The real, masked error message for this operation or
null
if none has been set
-
appendMaskedErrorMessage
public final void appendMaskedErrorMessage(LocalizableMessage maskedMessage)
Appends the provided message to the real, masked error message buffer. If the buffer has not yet been created, then this will create it first and then add the provided message. This method may not be called by post-response plugins.- Parameters:
maskedMessage
- The message to append to the real, masked error message
-
getAuthFailureReason
public LocalizableMessage getAuthFailureReason()
Returns a human-readable message providing the reason why the authentication failed, if available.- Returns:
- a human-readable message providing the reason why the authentication failed, or
null
if none is available.
-
setAuthFailureReason
public void setAuthFailureReason(LocalizableMessage reason)
Specifies the reason why authentication failed.- Parameters:
reason
- the message describing why authentication failed
-
getProxiedAuthorizationDn
public Dn getProxiedAuthorizationDn()
Returns the proxied authorization DN if proxy authorization has been requested.- Returns:
- the proxied Authorization DN or
null
is proxy authorization has not been requested
-
setProxiedAuthorizationDn
public RequestContext setProxiedAuthorizationDn(Dn proxiedAuthorizationDn)
Set the proxied authorization DN for this operation if any.- Parameters:
proxiedAuthorizationDn
- The proxied authorization DN. ifnull
this operation will have no proxy authorization.- Returns:
- the current context
-
getSearchNumberOfEntriesReturned
public int getSearchNumberOfEntriesReturned()
Returns the number of entries sent by the search request associated to this context.- Returns:
- the number of entries sent by the search request associated to this context.
-
setSearchNumberOfEntriesReturned
public void setSearchNumberOfEntriesReturned(int searchNumberOfEntriesReturned)
Sets the number of entries returned by the search request associated to this context.- Parameters:
searchNumberOfEntriesReturned
- the number of entries sent
-
getAdditionalLogItems
public List<AdditionalLogItem> getAdditionalLogItems()
Returns additional information to be logged, as a potentially emptyList
ofAdditionalLogItem
.- Returns:
- additional information to be logged, as a potentially empty
List
ofAdditionalLogItem
-
addAdditionalLogItem
public void addAdditionalLogItem(AdditionalLogItem item)
Adds aAdditionalLogItem
to the list for logging.null
items will be ignored.- Parameters:
item
- the additional log item to add
-
setAdditionalLogItems
public void setAdditionalLogItems(List<AdditionalLogItem> items)
Sets theAdditionalLogItem
s. All existing elements will be deleted.- Parameters:
items
- the new log items
-
-