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 classRequestContext.RequestFlagDistinguishes 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 voidaddAdditionalLogItem(AdditionalLogItem item)Adds aAdditionalLogItemto the list for logging.voidaddCancelRequestListener(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.voidappendMaskedErrorMessage(LocalizableMessage maskedMessage)Appends the provided message to the real, masked error message buffer.voidcannotCancel(LocalizableMessage cannotCancelReason)Marks the request associated to this request context as not cancellable.voidcheckIfCancelled(boolean signalTooLate)ThrowsCancelledResultExceptionif a cancellation request has been received and processing of the request should be aborted if possible.List<AdditionalLogItem>getAdditionalLogItems()Returns additional information to be logged, as a potentially emptyListofAdditionalLogItem.DngetAuthenticationDn()Returns the authentication Dn for logging.LocalizableMessagegetAuthFailureReason()Returns a human-readable message providing the reason why the authentication failed, if available.DngetAuthorizationDn()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.ConnectionContextgetConnectionContext()Returns the connection context associated to this context.longgetElapsedProcessingTime()Returns the elapsed processing time for the request.longgetElapsedQueueingTime()Returns the elapsed queueing time for the request.TimeUnitgetElapsedTimeUnit()Returns the time unit that is used for reporting elapsed times of the request.longgetElapsedTotalTime()Returns the elapsed total time for the request.EntrygetEntryAsAddedByServer()Returns the entry as added by the server, with all additional operational attributes.longgetLargestEntrySize()Returns the size of the largest entry targeted by the request.LocalizableMessageBuildergetMaskedErrorMessage()Retrieves the real, masked error message for this operation.ResultCodegetMaskedResultCode()Retrieves the real, masked result code for this operation.intgetMessageId()Returns the message id associated to the request.List<Modification>getModificationsAsAppliedByServer()Returns the list of modifications applied by the server.longgetOperationId()Returns the operation id associated to the request.DngetProxiedAuthorizationDn()Returns the proxied authorization DN if proxy authorization has been requested.intgetSearchNumberOfEntriesReturned()Returns the number of entries sent by the search request associated to this context.booleanhasFlag(RequestContext.RequestFlag requestFlag)Returns whether this request has the provided flag.booleanhasPrivilege(Privilege privilege)Returnstrueif the authorized user has the specified privilege.voidnotifyProcessingStarted()Signals that this request is no long queuing and is about to be processed.voidnotifyRequestReceived(CoreConfigManager.EtimeService timeService)Sets the time at which this request was received.voidnotifyResponseSent()Signals that this request has completed processing and its response has been sent.voidsetAdditionalLogItems(List<AdditionalLogItem> items)Sets theAdditionalLogItems.voidsetAuthFailureReason(LocalizableMessage reason)Specifies the reason why authentication failed.voidsetCancelled()Notifies the request has been aborted.voidsetEntryAsAddedByServer(Entry entryAsAddedByServer)Sets the entry added as added by the server in the DIT.voidsetLargestEntrySize(long size)Sets the largest entry size for the request.voidsetMaskedResultCode(ResultCode maskedResultCode)Specifies the real, masked result code for this operation.voidsetModificationsAsAppliedByServer(List<Modification> modificationsAsAppliedByServer)Sets the list of modifications applied to an entry by the server while processing a Modify request.voidsetProxiedAuthorizationDn(Dn proxiedAuthorizationDn)Set the proxied authorization DN for this operation if any.voidsetSearchNumberOfEntriesReturned(int searchNumberOfEntriesReturned)Sets the number of entries returned by the search request associated to this context.booleanshouldSendResult()Returnstrueif the result should be forwarded to the client.-
Methods inherited from class org.forgerock.opendj.server.core.AbstractContext
as, asContext, containsContext, containsContext, get, 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
Dnornullif 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 thelistenerwasnull.- See Also:
checkIfCancelled(boolean)
-
checkIfCancelled
public void checkIfCancelled(boolean signalTooLate) throws CancelledResultExceptionThrowsCancelledResultExceptionif 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-trueto 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_CANCELand the provided reason.- Parameters:
cannotCancelReason- The reason which will be provided in the cancel responses.
-
shouldSendResult
public boolean shouldSendResult()
Returnstrueif the result should be forwarded to the client. Results are dropped for abandoned requests.- Returns:
trueif 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:
trueif 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)
Returnstrueif the authorized user has the specified privilege.- Parameters:
privilege- The required privilege.- Returns:
trueif the authorized user has the specified privilege.
-
getConnectionContext
public ConnectionContext getConnectionContext()
Returns the connection context associated to this context.- Returns:
- the connection context
-
notifyRequestReceived
public void notifyRequestReceived(CoreConfigManager.EtimeService timeService)
Sets the time at which this request was received.- Parameters:
timeService- theCoreConfigManager.EtimeServicefor computing elapsed time for the request
-
notifyProcessingStarted
public void notifyProcessingStarted()
Signals that this request is no long queuing and is about to be processed.
-
notifyResponseSent
public void notifyResponseSent()
Signals that this request has completed processing and its response has been sent.
-
getElapsedProcessingTime
public long getElapsedProcessingTime()
Returns the elapsed processing time for the request.- Returns:
- the elapsed processing time for the request
-
getElapsedQueueingTime
public long getElapsedQueueingTime()
Returns the elapsed queueing time for the request.- Returns:
- the elapsed queueing time for the request
-
getElapsedTotalTime
public long getElapsedTotalTime()
Returns the elapsed total time for the request.- Returns:
- the elapsed total time for the request
-
getElapsedTimeUnit
public TimeUnit getElapsedTimeUnit()
Returns the time unit that is used for reporting elapsed times of the request.- Returns:
- the time unit that is used for reporting elapsed times of 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
nullif there is no need for one
-
setMaskedResultCode
public void setMaskedResultCode(ResultCode maskedResultCode)
Specifies the real, masked result code for this operation. This method may not be called by post-response plugins. Anullvalue 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.
-
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
nullif none has been set
-
appendMaskedErrorMessage
public 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
nullif 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
nullis proxy authorization has not been requested
-
setProxiedAuthorizationDn
public void setProxiedAuthorizationDn(Dn proxiedAuthorizationDn)
Set the proxied authorization DN for this operation if any.- Parameters:
proxiedAuthorizationDn- The proxied authorization DN. ifnullthis operation will have no proxy authorization.
-
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 emptyListofAdditionalLogItem.- Returns:
- additional information to be logged, as a potentially empty
ListofAdditionalLogItem
-
addAdditionalLogItem
public void addAdditionalLogItem(AdditionalLogItem item)
Adds aAdditionalLogItemto the list for logging.nullitems will be ignored.- Parameters:
item- the additional log item to add
-
setAdditionalLogItems
public void setAdditionalLogItems(List<AdditionalLogItem> items)
Sets theAdditionalLogItems. All existing elements will be deleted.- Parameters:
items- the new log items
-
getLargestEntrySize
public long getLargestEntrySize()
Returns the size of the largest entry targeted by the request.- Returns:
- the size of the largest entry targeted by the request.
-
setLargestEntrySize
public void setLargestEntrySize(long size)
Sets the largest entry size for the request.- Parameters:
size- the size of the largest entry
-
-