Record Class AuditEvent

java.lang.Object
java.lang.Record
cloud.opencode.base.log.audit.AuditEvent

public record AuditEvent(String eventId, Instant timestamp, String userId, String action, String target, String targetId, String result, String ip, String userAgent, Map<String,Object> details) extends Record
Audit Event - Immutable Audit Log Entry 审计事件 - 不可变的审计日志条目

This record represents an audit event containing information about user actions, including who, what, when, where, and result.

此记录表示包含用户操作信息的审计事件,包括谁、什么、何时、何地和结果。

Example | 示例:

AuditEvent event = AuditEvent.builder("USER_LOGIN")
    .userId("user123")
    .target("system")
    .success()
    .ip("192.168.1.1")
    .detail("browser", "Chrome")
    .build();

Features | 主要功能:

  • Immutable audit event record - 不可变的审计事件记录
  • Builder pattern for flexible construction - 构建器模式,灵活构造
  • Auto-generated event ID and timestamp - 自动生成事件 ID 和时间戳
  • Defensive copy of details map - 详情映射的防御性拷贝

Security | 安全性:

  • Thread-safe: Yes (immutable record) - 线程安全: 是(不可变记录)
  • Null-safe: No (action must not be null) - 空值安全: 否(操作不能为 null)
Since:
JDK 25, opencode-base-log V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Field Details

    • RESULT_SUCCESS

      public static final String RESULT_SUCCESS
      Result constant for success. 成功结果常量。
      See Also:
    • RESULT_FAILURE

      public static final String RESULT_FAILURE
      Result constant for failure. 失败结果常量。
      See Also:
  • Constructor Details

  • Method Details

    • builder

      public static AuditEvent.Builder builder(String action)
      Creates a builder for the specified action. 为指定操作创建构建器。
      Parameters:
      action - the action - 操作
      Returns:
      the builder - 构建器
    • isSuccess

      public boolean isSuccess()
      Checks if the event was successful. 检查事件是否成功。
      Returns:
      true if successful - 如果成功返回 true
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • eventId

      public String eventId()
      Returns the value of the eventId record component.
      Returns:
      the value of the eventId record component
    • timestamp

      public Instant timestamp()
      Returns the value of the timestamp record component.
      Returns:
      the value of the timestamp record component
    • userId

      public String userId()
      Returns the value of the userId record component.
      Returns:
      the value of the userId record component
    • action

      public String action()
      Returns the value of the action record component.
      Returns:
      the value of the action record component
    • target

      public String target()
      Returns the value of the target record component.
      Returns:
      the value of the target record component
    • targetId

      public String targetId()
      Returns the value of the targetId record component.
      Returns:
      the value of the targetId record component
    • result

      public String result()
      Returns the value of the result record component.
      Returns:
      the value of the result record component
    • ip

      public String ip()
      Returns the value of the ip record component.
      Returns:
      the value of the ip record component
    • userAgent

      public String userAgent()
      Returns the value of the userAgent record component.
      Returns:
      the value of the userAgent record component
    • details

      public Map<String,Object> details()
      Returns the value of the details record component.
      Returns:
      the value of the details record component