mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-21 09:35:49 +02:00
Fixed coding style.
This commit is contained in:
parent
a5e1f02d27
commit
ae75e6844f
41 changed files with 147 additions and 163 deletions
|
@ -1,4 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
|
@ -20,22 +23,18 @@
|
|||
|
||||
namespace App\EventSubscriber\LogSystem;
|
||||
|
||||
|
||||
use App\Entity\LogSystem\SecurityEventLogEntry;
|
||||
use App\Events\SecurityEvent;
|
||||
use App\Events\SecurityEvents;
|
||||
use App\Services\LogSystem\EventLogger;
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
|
||||
/**
|
||||
* This subscriber writes entries to log if an security related event happens (e.g. the user changes its password).
|
||||
* @package App\EventSubscriber\LogSystem
|
||||
*/
|
||||
final class SecurityEventLoggerSubscriber implements EventSubscriberInterface
|
||||
{
|
||||
|
||||
private $requestStack;
|
||||
private $gpdr_compliant;
|
||||
private $eventLogger;
|
||||
|
@ -47,27 +46,6 @@ final class SecurityEventLoggerSubscriber implements EventSubscriberInterface
|
|||
$this->eventLogger = $eventLogger;
|
||||
}
|
||||
|
||||
protected function addLog(string $type, SecurityEvent $event): void
|
||||
{
|
||||
$anonymize = $this->gpdr_compliant;
|
||||
|
||||
$request = $this->requestStack->getCurrentRequest();
|
||||
if ($request !== null) {
|
||||
$ip = $request->getClientIp() ?? 'unknown';
|
||||
} else {
|
||||
$ip = "Console";
|
||||
//Dont try to apply IP filter rules to non numeric string
|
||||
$anonymize = false;
|
||||
}
|
||||
|
||||
$log = new SecurityEventLogEntry($type, $ip, $anonymize);
|
||||
$log->setTargetElement($event->getTargetUser());
|
||||
$this->eventLogger->logAndFlush($log);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public static function getSubscribedEvents()
|
||||
{
|
||||
return [
|
||||
|
@ -127,4 +105,22 @@ final class SecurityEventLoggerSubscriber implements EventSubscriberInterface
|
|||
{
|
||||
$this->addLog(SecurityEvents::TRUSTED_DEVICE_RESET, $event);
|
||||
}
|
||||
}
|
||||
|
||||
private function addLog(string $type, SecurityEvent $event): void
|
||||
{
|
||||
$anonymize = $this->gpdr_compliant;
|
||||
|
||||
$request = $this->requestStack->getCurrentRequest();
|
||||
if (null !== $request) {
|
||||
$ip = $request->getClientIp() ?? 'unknown';
|
||||
} else {
|
||||
$ip = 'Console';
|
||||
//Dont try to apply IP filter rules to non numeric string
|
||||
$anonymize = false;
|
||||
}
|
||||
|
||||
$log = new SecurityEventLogEntry($type, $ip, $anonymize);
|
||||
$log->setTargetElement($event->getTargetUser());
|
||||
$this->eventLogger->logAndFlush($log);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue