Fixed coding style.

This commit is contained in:
Jan Böhmer 2020-04-10 13:05:08 +02:00
parent a5e1f02d27
commit ae75e6844f
41 changed files with 147 additions and 163 deletions

View file

@ -67,7 +67,6 @@ use Symfony\Component\Serializer\SerializerInterface;
/**
* This event subscriber write to event log when entities are changed, removed, created.
* @package App\EventSubscriber\LogSystem
*/
class EventLoggerSubscriber implements EventSubscriber
{

View file

@ -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,7 +23,6 @@
namespace App\EventSubscriber\LogSystem;
use App\Entity\LogSystem\UserNotAllowedLogEntry;
use App\Services\LogSystem\EventLogger;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
@ -30,7 +32,6 @@ use Symfony\Component\Security\Core\Exception\AccessDeniedException;
/**
* Write to event log when a user tries to access an forbidden page and recevies an 403 Access Denied message.
* @package App\EventSubscriber\LogSystem
*/
class LogAccessDeniedSubscriber implements EventSubscriberInterface
{
@ -41,14 +42,14 @@ class LogAccessDeniedSubscriber implements EventSubscriberInterface
$this->logger = $logger;
}
public function onKernelException(ExceptionEvent $event)
public function onKernelException(ExceptionEvent $event): void
{
$throwable = $event->getThrowable();
if ($throwable instanceof AccessDeniedHttpException) {
$throwable = $throwable->getPrevious();
}
//Ignore everything except AccessDeniedExceptions
if (!$throwable instanceof AccessDeniedException) {
if (! $throwable instanceof AccessDeniedException) {
return;
}
@ -57,11 +58,8 @@ class LogAccessDeniedSubscriber implements EventSubscriberInterface
$this->logger->logAndFlush($log_entry);
}
/**
* @inheritDoc
*/
public static function getSubscribedEvents()
{
return ['kernel.exception' => 'onKernelException'];
}
}
}

View file

@ -50,7 +50,6 @@ use Doctrine\Migrations\Events;
/**
* This subscriber logs databaseMigrations to Event log.
* @package App\EventSubscriber
*/
class LogDBMigrationSubscriber implements EventSubscriber
{

View file

@ -52,7 +52,6 @@ use Symfony\Component\Security\Http\Logout\LogoutHandlerInterface;
/**
* This handler logs to event log, if a user logs out.
* @package App\EventSubscriber\LogSystem
*/
class LogoutLoggerHandler implements LogoutHandlerInterface
{

View file

@ -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);
}
}

View file

@ -49,7 +49,6 @@ use Symfony\Component\Mime\Email;
/**
* This subscriber set the "From" field for all sent email, based on the global configured sender name and email.
* @package App\EventSubscriber
*/
final class SetMailFromSubscriber implements EventSubscriberInterface
{

View file

@ -42,14 +42,11 @@ declare(strict_types=1);
namespace App\EventSubscriber;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\Event\ResponseEvent;
/**
* This subscriber sets an Header in Debug mode that signals the Symfony Profiler to also update on Ajax requests.
* @package App\EventSubscriber
*/
final class SymfonyDebugToolbarSubscriber implements EventSubscriberInterface
{

View file

@ -53,7 +53,6 @@ use Symfony\Component\Security\Core\Security;
/**
* This subscriber is used to log out a disabled user, as soon as he to do an request.
* It is not possible for him to login again, afterwards.
* @package App\EventSubscriber\UserSystem
*/
final class LogoutDisabledUserSubscriber implements EventSubscriberInterface
{

View file

@ -57,7 +57,6 @@ use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
/**
* This subscriber is used to write U2F keys to DB, after user added them via GUI.
* @package App\EventSubscriber\UserSystem
*/
final class RegisterU2FSubscriber implements EventSubscriberInterface
{