feat: Move security events into core

Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
2026-08-05 22:14:22 -04:00
parent a73ca3abd6
commit 649fa47c68
9 changed files with 28 additions and 26 deletions
+1 -1
View File
@@ -13,7 +13,7 @@ use KTXC\Service\TenantFirewallRuleService;
use KTXC\Service\TenantFirewallStatusService; use KTXC\Service\TenantFirewallStatusService;
use KTXF\Event\DeliveryMode; use KTXF\Event\DeliveryMode;
use KTXF\Event\EventListenerRegistrarInterface; use KTXF\Event\EventListenerRegistrarInterface;
use KTXF\Event\SecurityEvent; use KTXC\Security\Event\SecurityEvent;
use KTXF\Module\ModuleBrowserInterface; use KTXF\Module\ModuleBrowserInterface;
use KTXF\Module\ModuleConsoleInterface; use KTXF\Module\ModuleConsoleInterface;
use KTXF\Module\ModuleInstanceAbstract; use KTXF\Module\ModuleInstanceAbstract;
@@ -2,7 +2,9 @@
declare(strict_types=1); declare(strict_types=1);
namespace KTXF\Event; namespace KTXC\Security\Event;
use KTXF\Event\Event;
/** /**
* Security-specific event for authentication and access control events * Security-specific event for authentication and access control events
+1 -1
View File
@@ -7,7 +7,7 @@ namespace KTXC\Service;
use KTXC\Models\Firewall\FirewallRuleObject; use KTXC\Models\Firewall\FirewallRuleObject;
use KTXC\Stores\FirewallStore; use KTXC\Stores\FirewallStore;
use KTXF\Event\EventDispatcherInterface; use KTXF\Event\EventDispatcherInterface;
use KTXF\Event\SecurityEvent; use KTXC\Security\Event\SecurityEvent;
use KTXF\IpUtils; use KTXF\IpUtils;
final class FirewallRuleManager final class FirewallRuleManager
+1 -1
View File
@@ -10,7 +10,7 @@ use KTXC\Models\Firewall\FirewallLogObject;
use KTXC\Stores\FirewallStore; use KTXC\Stores\FirewallStore;
use KTXC\Context\TenantContextInterface; use KTXC\Context\TenantContextInterface;
use KTXF\Event\EventDispatcherInterface; use KTXF\Event\EventDispatcherInterface;
use KTXF\Event\SecurityEvent; use KTXC\Security\Event\SecurityEvent;
use KTXF\IpUtils; use KTXF\IpUtils;
/** /**
+1 -1
View File
@@ -6,7 +6,7 @@ namespace KTXC\Service;
use KTXC\Models\Tenant\TenantConfiguration; use KTXC\Models\Tenant\TenantConfiguration;
use KTXF\Event\EventDispatcherInterface; use KTXF\Event\EventDispatcherInterface;
use KTXF\Event\SecurityEvent; use KTXC\Security\Event\SecurityEvent;
final class FirewallSettingsService final class FirewallSettingsService
{ {
+1 -1
View File
@@ -17,7 +17,7 @@ use KTXC\Service\SystemFirewallStatusService;
use KTXC\Service\TenantFirewallRuleService; use KTXC\Service\TenantFirewallRuleService;
use KTXF\Event\DeliveryMode; use KTXF\Event\DeliveryMode;
use KTXC\Event\EventListenerRegistry; use KTXC\Event\EventListenerRegistry;
use KTXF\Event\SecurityEvent; use KTXC\Security\Event\SecurityEvent;
use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\Attributes\TestDox; use PHPUnit\Framework\Attributes\TestDox;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
@@ -11,7 +11,7 @@ use KTXC\Service\FirewallRuleManager;
use KTXC\Service\FirewallRuleScope; use KTXC\Service\FirewallRuleScope;
use KTXC\Stores\FirewallStore; use KTXC\Stores\FirewallStore;
use KTXF\Event\EventDispatcherInterface; use KTXF\Event\EventDispatcherInterface;
use KTXF\Event\SecurityEvent; use KTXC\Security\Event\SecurityEvent;
use PHPUnit\Framework\Attributes\AllowMockObjectsWithoutExpectations; use PHPUnit\Framework\Attributes\AllowMockObjectsWithoutExpectations;
use PHPUnit\Framework\Attributes\TestDox; use PHPUnit\Framework\Attributes\TestDox;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
+18 -18
View File
@@ -210,7 +210,7 @@ class FirewallServiceTest extends TestCase
&& $log->getEventType() === FirewallLogObject::EVENT_RULE_MATCH; && $log->getEventType() === FirewallLogObject::EVENT_RULE_MATCH;
})) }))
->willReturnArgument(0); ->willReturnArgument(0);
$event = \KTXF\Event\SecurityEvent::accessDenied( $event = \KTXC\Security\Event\SecurityEvent::accessDenied(
'203.0.113.10', '203.0.113.10',
null, null,
'tenant-rule', 'tenant-rule',
@@ -234,7 +234,7 @@ class FirewallServiceTest extends TestCase
&& $log->getRuleScope() === FirewallRuleObject::SCOPE_SYSTEM; && $log->getRuleScope() === FirewallRuleObject::SCOPE_SYSTEM;
})) }))
->willReturnArgument(0); ->willReturnArgument(0);
$event = \KTXF\Event\SecurityEvent::accessDenied( $event = \KTXC\Security\Event\SecurityEvent::accessDenied(
'203.0.113.10', '203.0.113.10',
null, null,
'system-rule', 'system-rule',
@@ -252,7 +252,7 @@ class FirewallServiceTest extends TestCase
$this->store->expects($this->never())->method('createLog'); $this->store->expects($this->never())->method('createLog');
$this->service->logSecurityEvent( $this->service->logSecurityEvent(
\KTXF\Event\SecurityEvent::authFailure('203.0.113.10') \KTXC\Security\Event\SecurityEvent::authFailure('203.0.113.10')
); );
} }
@@ -271,7 +271,7 @@ class FirewallServiceTest extends TestCase
&& $metadata['windowSeconds'] === 60; && $metadata['windowSeconds'] === 60;
})) }))
->willReturnArgument(0); ->willReturnArgument(0);
$event = \KTXF\Event\SecurityEvent::rateLimitExceeded( $event = \KTXC\Security\Event\SecurityEvent::rateLimitExceeded(
'203.0.113.10', '203.0.113.10',
101, 101,
60, 60,
@@ -296,8 +296,8 @@ class FirewallServiceTest extends TestCase
&& $log->getMetadata()['detector'] === 'payload-signature'; && $log->getMetadata()['detector'] === 'payload-signature';
})) }))
->willReturnArgument(0); ->willReturnArgument(0);
$event = \KTXF\Event\SecurityEvent::create( $event = \KTXC\Security\Event\SecurityEvent::create(
\KTXF\Event\SecurityEvent::SUSPICIOUS_ACTIVITY, \KTXC\Security\Event\SecurityEvent::SUSPICIOUS_ACTIVITY,
'203.0.113.20', '203.0.113.20',
null, null,
['detector' => 'payload-signature'] ['detector' => 'payload-signature']
@@ -323,8 +323,8 @@ class FirewallServiceTest extends TestCase
&& $log->getIdentityId() === 'operator'; && $log->getIdentityId() === 'operator';
})) }))
->willReturnArgument(0); ->willReturnArgument(0);
$event = new \KTXF\Event\SecurityEvent( $event = new \KTXC\Security\Event\SecurityEvent(
\KTXF\Event\SecurityEvent::FIREWALL_RULE_DISABLED, \KTXC\Security\Event\SecurityEvent::FIREWALL_RULE_DISABLED,
[ [
'ruleId' => 'rule-123', 'ruleId' => 'rule-123',
'ruleScope' => FirewallRuleObject::SCOPE_SYSTEM, 'ruleScope' => FirewallRuleObject::SCOPE_SYSTEM,
@@ -349,8 +349,8 @@ class FirewallServiceTest extends TestCase
&& $log->getMetadata()['changeReason'] === 'Tighten controls' && $log->getMetadata()['changeReason'] === 'Tighten controls'
)) ))
->willReturnArgument(0); ->willReturnArgument(0);
$event = new \KTXF\Event\SecurityEvent( $event = new \KTXC\Security\Event\SecurityEvent(
\KTXF\Event\SecurityEvent::FIREWALL_SETTINGS_UPDATED, \KTXC\Security\Event\SecurityEvent::FIREWALL_SETTINGS_UPDATED,
['changeReason' => 'Tighten controls'] ['changeReason' => 'Tighten controls']
); );
$event->setTenantId('tenant-a')->setIdentityId('operator'); $event->setTenantId('tenant-a')->setIdentityId('operator');
@@ -376,7 +376,7 @@ class FirewallServiceTest extends TestCase
->willReturn(4); ->willReturn(4);
$this->events->expects($this->never())->method('dispatch'); $this->events->expects($this->never())->method('dispatch');
$event = \KTXF\Event\SecurityEvent::authFailure('203.0.113.10'); $event = \KTXC\Security\Event\SecurityEvent::authFailure('203.0.113.10');
$event->setTenantId('tenant-a'); $event->setTenantId('tenant-a');
$this->service->handleAuthFailure($event); $this->service->handleAuthFailure($event);
@@ -400,7 +400,7 @@ class FirewallServiceTest extends TestCase
->with('tenant-a', '203.0.113.10', 300) ->with('tenant-a', '203.0.113.10', 300)
->willReturn(0); ->willReturn(0);
$event = \KTXF\Event\SecurityEvent::authFailure('203.0.113.10'); $event = \KTXC\Security\Event\SecurityEvent::authFailure('203.0.113.10');
$event->setTenantId('tenant-a'); $event->setTenantId('tenant-a');
$this->service->handleAuthFailure($event); $this->service->handleAuthFailure($event);
} }
@@ -449,12 +449,12 @@ class FirewallServiceTest extends TestCase
&$lifecycleOrigin &$lifecycleOrigin
): void { ): void {
$publishedTenants[] = $event->getTenantId(); $publishedTenants[] = $event->getTenantId();
if ($event->getName() === \KTXF\Event\SecurityEvent::FIREWALL_RULE_CREATED) { if ($event->getName() === \KTXC\Security\Event\SecurityEvent::FIREWALL_RULE_CREATED) {
$lifecycleOrigin = $event->get('origin'); $lifecycleOrigin = $event->get('origin');
} }
}); });
$event = \KTXF\Event\SecurityEvent::authFailure('203.0.113.10'); $event = \KTXC\Security\Event\SecurityEvent::authFailure('203.0.113.10');
$event->setTenantId('tenant-event'); $event->setTenantId('tenant-event');
$this->service->handleAuthFailure($event); $this->service->handleAuthFailure($event);
@@ -478,7 +478,7 @@ class FirewallServiceTest extends TestCase
$this->events->expects($this->never())->method('dispatch'); $this->events->expects($this->never())->method('dispatch');
$this->service->handleAuthFailure( $this->service->handleAuthFailure(
\KTXF\Event\SecurityEvent::authFailure('203.0.113.10') \KTXC\Security\Event\SecurityEvent::authFailure('203.0.113.10')
); );
} }
@@ -492,7 +492,7 @@ class FirewallServiceTest extends TestCase
->willReturn(0); ->willReturn(0);
$this->service->handleAuthFailure( $this->service->handleAuthFailure(
\KTXF\Event\SecurityEvent::authFailure('203.0.113.10') \KTXC\Security\Event\SecurityEvent::authFailure('203.0.113.10')
); );
} }
@@ -504,7 +504,7 @@ class FirewallServiceTest extends TestCase
$this->store->expects($this->never())->method('depositRule'); $this->store->expects($this->never())->method('depositRule');
$this->service->handleAuthFailure( $this->service->handleAuthFailure(
\KTXF\Event\SecurityEvent::authFailure('203.0.113.10') \KTXC\Security\Event\SecurityEvent::authFailure('203.0.113.10')
); );
} }
@@ -518,7 +518,7 @@ class FirewallServiceTest extends TestCase
->method('countRecentFailures') ->method('countRecentFailures')
->with('tenant-a', '203.0.113.10', 300) ->with('tenant-a', '203.0.113.10', 300)
->willReturn(1); ->willReturn(1);
$event = \KTXF\Event\SecurityEvent::authFailure('203.0.113.10'); $event = \KTXC\Security\Event\SecurityEvent::authFailure('203.0.113.10');
$eventId = $event->getEventId(); $eventId = $event->getEventId();
$this->service->handleAuthFailure($event); $this->service->handleAuthFailure($event);
@@ -9,7 +9,7 @@ use KTXC\Models\Tenant\TenantObject;
use KTXC\Service\FirewallSettingsService; use KTXC\Service\FirewallSettingsService;
use KTXC\Service\TenantService; use KTXC\Service\TenantService;
use KTXF\Event\EventDispatcherInterface; use KTXF\Event\EventDispatcherInterface;
use KTXF\Event\SecurityEvent; use KTXC\Security\Event\SecurityEvent;
use PHPUnit\Framework\Attributes\TestDox; use PHPUnit\Framework\Attributes\TestDox;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;