fix(firewall): account for authentication failures exactly once
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
@@ -260,6 +260,30 @@ class FirewallStore
|
||||
return $log;
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert an event-backed log once, using the event ID as MongoDB's unique key.
|
||||
*/
|
||||
public function createLogOnce(FirewallLogObject $log): bool
|
||||
{
|
||||
$eventId = $log->getEventId();
|
||||
if ($eventId === null || $eventId === '') {
|
||||
throw new \InvalidArgumentException('Idempotent firewall logs require an event ID.');
|
||||
}
|
||||
|
||||
$data = $log->jsonSerialize();
|
||||
unset($data['id']);
|
||||
$data['_id'] = $eventId;
|
||||
|
||||
$result = $this->dataStore->selectCollection(self::LOGS_COLLECTION)->updateOne(
|
||||
['_id' => $eventId],
|
||||
['$setOnInsert' => $data],
|
||||
['upsert' => true]
|
||||
);
|
||||
$log->setId($eventId);
|
||||
|
||||
return $result->getUpsertedCount() === 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get logs for a tenant with optional filters
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user