feat: Introduce typed authentication failure event

Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
2026-08-05 22:50:38 -04:00
parent 52afd35d6f
commit 5c65c8592c
9 changed files with 175 additions and 53 deletions
+8 -6
View File
@@ -9,8 +9,10 @@ use KTXC\Models\Firewall\FirewallRuleObject;
use KTXC\Models\Firewall\FirewallLogObject;
use KTXC\Stores\FirewallStore;
use KTXC\Context\TenantContextInterface;
use KTXF\Event\EventDispatcherInterface;
use KTXC\Security\Event\AuthenticationFailedEvent;
use KTXC\Security\Event\SecurityEvent;
use KTXC\Security\Event\SecurityEventInterface;
use KTXF\Event\EventDispatcherInterface;
use KTXF\IpUtils;
/**
@@ -130,7 +132,7 @@ class FirewallService
/**
* Handle authentication failure event
*/
public function handleAuthFailure(SecurityEvent $event): void
public function handleAuthFailure(AuthenticationFailedEvent $event): void
{
$ipAddress = $event->getIpAddress();
$tenantId = $event->getTenantId() ?? $this->tenantContext->identifier();
@@ -225,7 +227,7 @@ class FirewallService
/**
* Log security event to firewall logs
*/
public function logSecurityEvent(SecurityEvent $event): void
public function logSecurityEvent(SecurityEventInterface $event): void
{
$log = $this->securityLog($event);
if ($log !== null) {
@@ -233,7 +235,7 @@ class FirewallService
}
}
private function securityLog(SecurityEvent $event): ?FirewallLogObject
private function securityLog(SecurityEventInterface $event): ?FirewallLogObject
{
$tenantId = $event->getTenantId() ?? $this->tenantContext->identifier();
$ruleScope = $event->get('ruleScope');
@@ -264,7 +266,7 @@ class FirewallService
private function mapEventToLogType(string $eventName): string
{
return match ($eventName) {
SecurityEvent::AUTH_FAILURE => FirewallLogObject::EVENT_AUTH_FAILURE,
AuthenticationFailedEvent::class => FirewallLogObject::EVENT_AUTH_FAILURE,
SecurityEvent::AUTH_SUCCESS => FirewallLogObject::EVENT_ACCESS_CHECK,
SecurityEvent::BRUTE_FORCE_DETECTED => FirewallLogObject::EVENT_BRUTE_FORCE,
SecurityEvent::RATE_LIMIT_EXCEEDED => FirewallLogObject::EVENT_RATE_LIMIT,
@@ -283,7 +285,7 @@ class FirewallService
/**
* Map security event to result
*/
private function mapEventToResult(SecurityEvent $event): string
private function mapEventToResult(SecurityEventInterface $event): string
{
return match ($event->getName()) {
SecurityEvent::AUTH_SUCCESS,