Package org.forgerock.services.context
Class RequestAuditContext
- java.lang.Object
-
- org.forgerock.services.context.AbstractContext
-
- org.forgerock.services.context.RequestAuditContext
-
- All Implemented Interfaces:
Context
public class RequestAuditContext extends AbstractContext
A context for audit information for an incoming request.
-
-
Field Summary
-
Fields inherited from class org.forgerock.services.context.AbstractContext
data
-
-
Constructor Summary
Constructors Constructor Description RequestAuditContext(JsonValue savedContext, ClassLoader classLoader)
Restores a saved context.RequestAuditContext(Context parent)
Deprecated.Prefer usingRequestAuditContext(Context, Instant)
not to rely on the system clock.RequestAuditContext(Context parent, Clock clock)
Deprecated.Prefer usingRequestAuditContext(Context, Instant)
.RequestAuditContext(Context parent, Instant requestReceivedTime)
Constructs a new context using the specified parent and the current time as the request received time.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addTrackingId(String trackingId)
Adds a tracking ID to the context.long
getRequestReceivedTime()
Get the time in milliseconds since the epoch that the request was received.Set<String>
getTrackingIds()
Get all tracking IDs stored in this context.String
getUserId()
Get the user ID stored in this context.void
setUserId(String userId)
Set the user ID on the context.JsonValue
toJsonValue()
Return this Context as a JsonValue (for persistence).-
Methods inherited from class org.forgerock.services.context.AbstractContext
as, asContext, containsContext, containsContext, get, getContext, getContextName, getId, getParent, getRootId, isRootContext, toString
-
-
-
-
Constructor Detail
-
RequestAuditContext
@Deprecated(since="26.2.0") public RequestAuditContext(Context parent)
Deprecated.Prefer usingRequestAuditContext(Context, Instant)
not to rely on the system clock.Constructs a new context using the specified parent and the current time as the request received time.- Parameters:
parent
- The parent context.
-
RequestAuditContext
@Deprecated public RequestAuditContext(Context parent, Clock clock)
Deprecated.Prefer usingRequestAuditContext(Context, Instant)
.Constructs a new context using the specified parent and the current time as the request received time.- Parameters:
parent
- The parent context.clock
- The instance ofClock
to use.
-
RequestAuditContext
public RequestAuditContext(Context parent, Instant requestReceivedTime)
Constructs a new context using the specified parent and the current time as the request received time.- Parameters:
parent
- The parent context.requestReceivedTime
- The time at which the request was received.
-
RequestAuditContext
public RequestAuditContext(JsonValue savedContext, ClassLoader classLoader)
Restores a saved context.- Parameters:
savedContext
- The saved state.classLoader
- TheClassLoader
to use.
-
-
Method Detail
-
addTrackingId
public void addTrackingId(String trackingId)
Adds a tracking ID to the context. If already present, it will be ignored. Note thattrackingIds
will not be serialized if empty.- Parameters:
trackingId
- The tracking ID to add.
-
getTrackingIds
public Set<String> getTrackingIds()
Get all tracking IDs stored in this context. This is an unmodifiable collection.- Returns:
- The tracking IDs stored in this context.
-
setUserId
public void setUserId(String userId)
Set the user ID on the context. This supports setting the user ID once it is known to the system, for example after sign-on. Note thatuserId
will not be serialized ifnull
.- Parameters:
userId
- the user ID
-
getUserId
public String getUserId()
Get the user ID stored in this context.- Returns:
- the user ID
-
toJsonValue
public JsonValue toJsonValue()
Description copied from interface:Context
Return this Context as a JsonValue (for persistence).- Specified by:
toJsonValue
in interfaceContext
- Overrides:
toJsonValue
in classAbstractContext
- Returns:
- the Context data as a JsonValue.
-
getRequestReceivedTime
public long getRequestReceivedTime()
Get the time in milliseconds since the epoch that the request was received.- Returns:
- The request received time.
-
-