f4df769b3c
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
101 lines
2.7 KiB
PHP
101 lines
2.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace KTXC\Security\Event;
|
|
|
|
use KTXF\Event\Event;
|
|
|
|
final class SuspiciousActivityEvent extends Event implements SecurityRequestEventInterface
|
|
{
|
|
public function __construct(
|
|
private readonly string $ipAddress,
|
|
private readonly string $detector,
|
|
private readonly array $detectionData = [],
|
|
?string $tenantId = null,
|
|
?string $identityId = null,
|
|
private readonly ?string $deviceFingerprint = null,
|
|
private readonly ?string $userAgent = null,
|
|
private readonly ?string $requestPath = null,
|
|
private readonly ?string $requestMethod = null,
|
|
private readonly ?string $userId = null,
|
|
private readonly ?string $reason = null,
|
|
) {
|
|
if ($ipAddress === '') {
|
|
throw new \InvalidArgumentException('Suspicious activity requires an IP address.');
|
|
}
|
|
if ($detector === '') {
|
|
throw new \InvalidArgumentException('Suspicious activity requires a detector.');
|
|
}
|
|
if (array_key_exists('detector', $detectionData)) {
|
|
throw new \InvalidArgumentException('Detection data cannot replace the detector.');
|
|
}
|
|
if (array_key_exists('detector', $detectionData)) {
|
|
throw new \InvalidArgumentException('Detection data cannot replace the detector.');
|
|
}
|
|
if ($requestPath === '') {
|
|
throw new \InvalidArgumentException('A supplied request path cannot be empty.');
|
|
}
|
|
if ($requestMethod === '') {
|
|
throw new \InvalidArgumentException('A supplied request method cannot be empty.');
|
|
}
|
|
|
|
parent::__construct(
|
|
self::class,
|
|
['detector' => $detector] + $detectionData,
|
|
$tenantId,
|
|
$identityId,
|
|
);
|
|
}
|
|
|
|
public function getIpAddress(): string
|
|
{
|
|
return $this->ipAddress;
|
|
}
|
|
|
|
public function getDetector(): string
|
|
{
|
|
return $this->detector;
|
|
}
|
|
|
|
public function getDetectionData(): array
|
|
{
|
|
return $this->detectionData;
|
|
}
|
|
|
|
public function getDeviceFingerprint(): ?string
|
|
{
|
|
return $this->deviceFingerprint;
|
|
}
|
|
|
|
public function getUserAgent(): ?string
|
|
{
|
|
return $this->userAgent;
|
|
}
|
|
|
|
public function getRequestPath(): ?string
|
|
{
|
|
return $this->requestPath;
|
|
}
|
|
|
|
public function getRequestMethod(): ?string
|
|
{
|
|
return $this->requestMethod;
|
|
}
|
|
|
|
public function getUserId(): ?string
|
|
{
|
|
return $this->userId;
|
|
}
|
|
|
|
public function getReason(): ?string
|
|
{
|
|
return $this->reason;
|
|
}
|
|
|
|
public function getSeverity(): int
|
|
{
|
|
return SecurityEvent::SEVERITY_ERROR;
|
|
}
|
|
}
|