Class FileAuditSink
- All Implemented Interfaces:
AutoCloseable, AuditIntegrityService, AuditService, AuditSink
AuditSink provider storing audit events as daily gzip
files.
ServiceLoader compatibility
This sink supports ServiceLoader by providing a public
no-arg constructor.
Storage layout
baseDir/
YYYY/
MM/
YYYY-MM-DD.audit.log.gz
Encoding
Each event is encoded as a single UTF-8 line and appended as its own gzip member. Members are concatenated to enable append-only writes.
Security properties
- Best-effort permissions: directories 0700, files 0600 on POSIX.
- No event payload is logged. Corrupted records are skipped without logging the record content.
-
Constructor Summary
ConstructorsConstructorDescriptionFileAuditSink(Path baseDir) Creates the sink with an explicit base directory. -
Method Summary
Modifier and TypeMethodDescriptionRecovers and returns the current chain head, seeding it from disk if needed.Retrieves an audit event by id if the implementation assigns stable ids.voidrecord(AuditEvent event) Persists an audit event.search(AuditQuery query) Searches audit events by query constraints.verifyAnchoredPrefix(AuditChainHead anchor) Verifies internal chain consistency and thatanchoris an authentic prefix of the log.verifyIntegrity(Optional<AuditChainHead> expectedHead) Verifies the tamper-evident hash chain over the entire durable audit log.
-
Constructor Details
-
FileAuditSink
Creates the sink with an explicit base directory.- Parameters:
baseDir- base directory
-
-
Method Details
-
record
Description copied from interface:AuditSinkPersists an audit event.- Specified by:
recordin interfaceAuditService- Specified by:
recordin interfaceAuditSink- Parameters:
event- audit event
-
verifyIntegrity
Verifies the tamper-evident hash chain over the entire durable audit log.Records are recovered from every daily file and ordered by their global sequence, so verification is independent of physical file placement. It detects content mutation, deletion (a sequence gap), duplication, and broken links; when an
expectedHeadanchor is supplied it additionally detects whole-tail truncation. The returned report is payload-free.- Specified by:
verifyIntegrityin interfaceAuditIntegrityService- Parameters:
expectedHead- optional independently-retained trusted head anchor- Returns:
- a safe integrity report
-
verifyAnchoredPrefix
Description copied from interface:AuditIntegrityServiceVerifies internal chain consistency and thatanchoris an authentic prefix of the log.Unlike
AuditIntegrityService.verifyIntegrity(Optional), which requires the supplied head to equal the current final head, this tolerates records appended after the anchored sequence (legitimate growth, including after a crash restart). It fails when the anchored sequence is missing (truncation below the anchor), when its record hash differs (history before the anchor was rewritten), or when the chain is internally broken. A genesis anchor (AuditChainHead.empty()) is a valid prefix of any consistent chain.- Specified by:
verifyAnchoredPrefixin interfaceAuditIntegrityService- Parameters:
anchor- durable trusted prefix anchor from a separate store- Returns:
- payload-free integrity report whose observed head is the current log head
-
currentHead
Recovers and returns the current chain head, seeding it from disk if needed.- Returns:
- the current tamper-evident head anchor
-
search
Description copied from interface:AuditServiceSearches audit events by query constraints.- Specified by:
searchin interfaceAuditService- Parameters:
query- query constraints- Returns:
- matching audit events
-
get
Description copied from interface:AuditServiceRetrieves an audit event by id if the implementation assigns stable ids.- Specified by:
getin interfaceAuditService- Parameters:
eventId- event id- Returns:
- audit event if present
-
getById
-