Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
}

group = 'net.staticstudios'
version = '1.0.0-SNAPSHOT'
version = '1.0.1-SNAPSHOT'

repositories {
mavenCentral()
Expand Down
27 changes: 27 additions & 0 deletions src/main/java/net/staticstudios/audit/Actor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package net.staticstudios.audit;

import org.jetbrains.annotations.NotNull;

import java.util.UUID;

/**
* Represents an actor that can perform actions in the audit log system.
*/
public interface Actor {

/**
* Get the type of actor, e.g., "user", "server", etc.
*
* @return the actor type
*/
@NotNull
String getActorType();

/**
* Get the unique identifier of the actor.
*
* @return the actor ID
*/
@NotNull
UUID getActorId();
}
37 changes: 25 additions & 12 deletions src/main/java/net/staticstudios/audit/AuditLogEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
* Represents an entry in the audit log.
*/
public class AuditLogEntry<T extends ActionData> {
private final @NotNull UUID userId;
private final @NotNull String actorType;
private final @NotNull UUID actorId;
private final @Nullable UUID sessionId;
private final @NotNull String applicationGroup;
private final @NotNull String applicationId;
Expand All @@ -22,16 +23,18 @@ public class AuditLogEntry<T extends ActionData> {
/**
* Creates a new AuditLogEntry.
*
* @param userId the ID of the user who performed the action
* @param actorType the type of actor who performed the action (e.g., "user", "server")
* @param actorId the ID of the actor who performed the action
* @param sessionId the ID of the session in which the action was performed (nullable)
* @param applicationGroup the application group that logged the action
* @param applicationId the application ID that logged the action
* @param timestamp the timestamp when the action was performed
* @param action the action that was performed
* @param data the data associated with the action
*/
public AuditLogEntry(@NotNull UUID userId, @Nullable UUID sessionId, @NotNull String applicationGroup, @NotNull String applicationId, @NotNull Instant timestamp, @NotNull Action<T> action, @NotNull T data) {
this.userId = userId;
public AuditLogEntry(@NotNull String actorType, @NotNull UUID actorId, @Nullable UUID sessionId, @NotNull String applicationGroup, @NotNull String applicationId, @NotNull Instant timestamp, @NotNull Action<T> action, @NotNull T data) {
this.actorType = actorType;
this.actorId = actorId;
this.sessionId = sessionId;
this.applicationGroup = applicationGroup;
this.applicationId = applicationId;
Expand All @@ -41,12 +44,21 @@ public AuditLogEntry(@NotNull UUID userId, @Nullable UUID sessionId, @NotNull St
}

/**
* Gets the ID of the user who performed the action.
* Gets the type of actor who performed the action.
*
* @return the user ID
* @return the actor type (e.g., "user", "server")
*/
public @NotNull UUID getUserId() {
return userId;
public @NotNull String getActorType() {
return actorType;
}

/**
* Gets the ID of the actor who performed the action.
*
* @return the actor ID
*/
public @NotNull UUID getActorId() {
return actorId;
}

/**
Expand Down Expand Up @@ -110,8 +122,8 @@ public AuditLogEntry(@NotNull UUID userId, @Nullable UUID sessionId, @NotNull St
*/
@Override
public String toString() {
return String.format("AuditLogEntry{userId=%s, sessionId=%s, applicationGroup='%s', applicationId='%s', timestamp=%s, action=%s, data=%s}",
userId, sessionId, applicationGroup, applicationId, timestamp, action, data);
return String.format("AuditLogEntry{actorType=%s, actorId=%s, sessionId=%s, applicationGroup='%s', applicationId='%s', timestamp=%s, action=%s, data=%s}",
actorType, actorId, sessionId, applicationGroup, applicationId, timestamp, action, data);
}

/**
Expand All @@ -126,7 +138,8 @@ public boolean equals(Object obj) {
if (obj == null || getClass() != obj.getClass()) return false;
AuditLogEntry<?> that = (AuditLogEntry<?>) obj;
return Objects.equals(action, that.action) && Objects.equals(data, that.data) &&
Objects.equals(userId, that.userId) && Objects.equals(sessionId, that.sessionId) &&
Objects.equals(actorType, that.actorType) &&
Objects.equals(actorId, that.actorId) && Objects.equals(sessionId, that.sessionId) &&
Objects.equals(applicationGroup, that.applicationGroup) && Objects.equals(applicationId, that.applicationId)
&& Objects.equals(timestamp, that.timestamp);
}
Expand All @@ -138,6 +151,6 @@ public boolean equals(Object obj) {
*/
@Override
public int hashCode() {
return Objects.hash(action, data, userId, sessionId, applicationGroup, applicationId, timestamp);
return Objects.hash(action, data, actorType, actorId, sessionId, applicationGroup, applicationId, timestamp);
}
}
16 changes: 11 additions & 5 deletions src/main/java/net/staticstudios/audit/EncodedAuditLogEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,18 @@
import java.util.UUID;

public class EncodedAuditLogEntry {
private final @NotNull UUID userId;
private final @NotNull String actorType;
private final @NotNull UUID actorId;
private final @Nullable UUID sessionId;
private final @NotNull String applicationGroup;
private final @NotNull String applicationId;
private final @NotNull Instant timestamp;
private final @NotNull String actionId;
private final @NotNull String encodedData;

public EncodedAuditLogEntry(@NotNull UUID userId, @Nullable UUID sessionId, @NotNull String applicationGroup, @NotNull String applicationId, @NotNull Instant timestamp, @NotNull String actionId, @NotNull String encodedData) {
this.userId = userId;
public EncodedAuditLogEntry(@NotNull String actorType, @NotNull UUID actorId, @Nullable UUID sessionId, @NotNull String applicationGroup, @NotNull String applicationId, @NotNull Instant timestamp, @NotNull String actionId, @NotNull String encodedData) {
this.actorType = actorType;
this.actorId = actorId;
this.sessionId = sessionId;
this.applicationGroup = applicationGroup;
this.applicationId = applicationId;
Expand All @@ -25,8 +27,12 @@ public EncodedAuditLogEntry(@NotNull UUID userId, @Nullable UUID sessionId, @Not
this.encodedData = encodedData;
}

public @NotNull UUID getUserId() {
return userId;
public @NotNull String getActorType() {
return actorType;
}

public @NotNull UUID getActorId() {
return actorId;
}

public @Nullable UUID getSessionId() {
Expand Down
Loading
Loading