Package org.forgerock.audit.events
Class AuditEventBuilder<T extends AuditEventBuilder<T>>
- java.lang.Object
-
- org.forgerock.audit.events.AuditEventBuilder<T>
-
- Type Parameters:
T
- the type of the builder
- Direct Known Subclasses:
AccessAuditEventBuilder
,ActivityAuditEventBuilder
,AuthenticationAuditEventBuilder
,ConfigAuditEventBuilder
public abstract class AuditEventBuilder<T extends AuditEventBuilder<T>> extends Object
Root builder for all audit events.
-
-
Field Summary
Fields Modifier and Type Field Description static String
EVENT_NAME
Event name event payload field name.static DateTimeFormatter
ISO_OFFSET_DATE_TIME_FORMAT
ISO 8601 date-time formatter '2011-12-03T10:15:30.000Z' specifically for UTC/GMT time zone.protected JsonValue
jsonValue
Represents the event as a JSON value.static String
TIMESTAMP
Timestamp event payload field name.static String
TRACKING_IDS
Tracking IDs event payload field name.static String
TRANSACTION_ID
Transaction ID event payload field name.static String
USER_ID
User ID event payload field name.
-
Constructor Summary
Constructors Modifier Constructor Description protected
AuditEventBuilder()
Creates the builder.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description T
eventName(String name)
Sets the provided name for the event.protected void
requireField(String rootFieldName)
Helper method to be used when overridingvalidate()
.protected T
self()
Returns this object, as its actual type.protected void
setDefaults()
Called bytoEvent()
to allow any unset fields to be given their default value.T
timestamp(long timestamp)
Sets the provided time stamp for the event.AuditEvent
toEvent()
Generates the audit event.T
trackingId(String trackingIdValue)
Adds an entry to trackingIds for the event.T
trackingIds(Set<String> trackingIdValues)
Adds the specified entries to trackingIds for the event.T
transactionId(String id)
Sets the provided transactionId for the event.T
transactionIdFromContext(org.forgerock.services.context.Context context)
Sets transactionId from ID ofTransactionIdContext
, if the providedContext
contains aTransactionIdContext
.T
userId(String id)
Sets the provided userId for the event.protected void
validate()
Called bytoEvent()
to ensure that the audit event will be created in a valid state.
-
-
-
Field Detail
-
EVENT_NAME
public static final String EVENT_NAME
Event name event payload field name.- See Also:
- Constant Field Values
-
TIMESTAMP
public static final String TIMESTAMP
Timestamp event payload field name.- See Also:
- Constant Field Values
-
TRANSACTION_ID
public static final String TRANSACTION_ID
Transaction ID event payload field name.- See Also:
- Constant Field Values
-
USER_ID
public static final String USER_ID
User ID event payload field name.- See Also:
- Constant Field Values
-
TRACKING_IDS
public static final String TRACKING_IDS
Tracking IDs event payload field name.- See Also:
- Constant Field Values
-
ISO_OFFSET_DATE_TIME_FORMAT
public static final DateTimeFormatter ISO_OFFSET_DATE_TIME_FORMAT
ISO 8601 date-time formatter '2011-12-03T10:15:30.000Z' specifically for UTC/GMT time zone.
-
jsonValue
protected JsonValue jsonValue
Represents the event as a JSON value.
-
-
Method Detail
-
self
protected final T self()
Returns this object, as its actual type.- Returns:
- this object
-
toEvent
public final AuditEvent toEvent()
Generates the audit event. As a side-effect of calling this method, this builder is reset to its starting state.- Returns:
- the audit event
-
setDefaults
protected void setDefaults()
Called bytoEvent()
to allow any unset fields to be given their default value. When overriding this method, the super class implementation must be called.
-
validate
protected void validate()
Called bytoEvent()
to ensure that the audit event will be created in a valid state. When overriding this method, the super class implementation must be called.- Throws:
IllegalStateException
- if a required field has not been populated.
-
requireField
protected void requireField(String rootFieldName)
Helper method to be used when overridingvalidate()
.- Parameters:
rootFieldName
- The name of the field that must be populated.- Throws:
IllegalStateException
- if the required field has not been populated.
-
eventName
public final T eventName(String name)
Sets the provided name for the event. An event's name will usually be of the form {product}-{component}-{operation}. For example, AM-SESSION-CREATED, AM-CREST-SUCCESSFUL, etc.- Parameters:
name
- the event's name.- Returns:
- this builder
-
timestamp
public final T timestamp(long timestamp)
Sets the provided time stamp for the event.- Parameters:
timestamp
- the time stamp.- Returns:
- this builder
-
transactionId
public final T transactionId(String id)
Sets the provided transactionId for the event.- Parameters:
id
- the transaction id.- Returns:
- this builder
-
userId
public final T userId(String id)
Sets the provided userId for the event.- Parameters:
id
- the user id.- Returns:
- this builder
-
trackingId
public final T trackingId(String trackingIdValue)
Adds an entry to trackingIds for the event.- Parameters:
trackingIdValue
- the unique value associated with the object being tracked.- Returns:
- this builder
-
trackingIds
public final T trackingIds(Set<String> trackingIdValues)
Adds the specified entries to trackingIds for the event.- Parameters:
trackingIdValues
- the set of trackingId entries to be recorded (seetrackingId(java.lang.String)
.- Returns:
- this builder
-
transactionIdFromContext
public final T transactionIdFromContext(org.forgerock.services.context.Context context)
Sets transactionId from ID ofTransactionIdContext
, if the providedContext
contains aTransactionIdContext
.- Parameters:
context
- The CREST context.- Returns:
- this builder
-
-