Class AuditLogRepository

java.lang.Object
com.serinity.accesscontrol.repository.base.BaseRepository<AuditLog,Long>
com.serinity.accesscontrol.repository.AuditLogRepository

public final class AuditLogRepository extends BaseRepository<AuditLog,Long>
Repository class for performing CRUD operations on AuditLog entities.

This class provides methods to create, read, update, and delete audit logs in the database using Hibernate ORM. It abstracts database interactions for the AuditLog entity and allows querying audit records by session, action type, or creation timestamp.


// Example usage
EntityManager em = SkinnedRatOrmEntityManager.getEntityManager();
AuditLogRepository auditRepo = new AuditLogRepository(em);

AuditLog log = new AuditLog();
log.setAction("USER_LOGIN");
log.setSession(session);

auditRepo.save(log);

Typical use cases:

  • Tracking authentication events (login, logout, sign-up)
  • Recording security-sensitive operations
  • Auditing user activity per session
Since:
2026-02-17
Version:
1.0
Author:
@ZouariOmar
See Also:
  • Constructor Details

    • AuditLogRepository

      public AuditLogRepository(org.zouarioss.skinnedratorm.core.EntityManager em)
      Creates a repository instance for audit logs.
      Parameters:
      em - entity manager used for persistence operations
  • Method Details

    • findByAuthSessionId

      public List<AuditLog> findByAuthSessionId(UUID authSessionId)
      Returns all audit log entries associated with a given session.
      Parameters:
      authSessionId - the UUID of the AuthSession
      Returns:
      list of audit logs for the session, or an empty list on error
    • findAllByUserId

      public List<AuditLog> findAllByUserId(UUID userId)
      Returns all audit log entries for every session belonging to the given user.

      Fetches all sessions for the user (1 query) then fetches all audit logs and filters by session ID in memory (1 query), reducing N+1 queries down to 2.

      Parameters:
      userId - the UUID of the user
      Returns:
      all audit logs across the user's sessions, or an empty list on error