Fixed service wiring configuration

This commit is contained in:
Jan Böhmer 2023-06-11 14:50:47 +02:00
parent 98dc553938
commit f63b6d7207
14 changed files with 29 additions and 35 deletions

View file

@ -1,65 +0,0 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 - 2022 Jan Böhmer (https://github.com/jbtronics)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace App\EventSubscriber\LogSystem;
use App\Entity\LogSystem\UserLogoutLogEntry;
use App\Entity\UserSystem\User;
use App\Services\LogSystem\EventLogger;
use Symfony\Component\EventDispatcher\Attribute\AsEventListener;
use Symfony\Component\Security\Http\Event\LogoutEvent;
/**
* This handler logs to event log, if a user logs out.
*/
#[AsEventListener]
final class LogLogoutEventEventSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
{
public function __construct(protected EventLogger $logger, protected bool $gpdr_compliance)
{
}
public function __invoke(LogoutEvent $event): void
{
$request = $event->getRequest();
$token = $event->getToken();
if (!$token instanceof \Symfony\Component\Security\Core\Authentication\Token\TokenInterface) {
return;
}
$log = new UserLogoutLogEntry($request->getClientIp(), $this->gpdr_compliance);
$user = $token->getUser();
if ($user instanceof User) {
$log->setTargetElement($user);
}
$this->logger->logAndFlush($log);
}
/**
* @return array<string, mixed>
*/
public static function getSubscribedEvents(): array
{
return ['' => ''];
}
}

View file

@ -53,7 +53,7 @@ use Symfony\Component\HttpFoundation\RequestStack;
*/
final class SecurityEventLoggerSubscriber implements EventSubscriberInterface
{
public function __construct(private readonly RequestStack $requestStack, private readonly EventLogger $eventLogger, private readonly bool $gpdr_compliant)
public function __construct(private readonly RequestStack $requestStack, private readonly EventLogger $eventLogger, private readonly bool $gdpr_compliance)
{
}
@ -119,7 +119,7 @@ final class SecurityEventLoggerSubscriber implements EventSubscriberInterface
private function addLog(string $type, SecurityEvent $event): void
{
$anonymize = $this->gpdr_compliant;
$anonymize = $this->gdpr_compliance;
$request = $this->requestStack->getCurrentRequest();
if ($request instanceof \Symfony\Component\HttpFoundation\Request) {

View file

@ -30,7 +30,7 @@ use Symfony\Component\HttpKernel\Event\ResponseEvent;
*/
final class SymfonyDebugToolbarSubscriber implements EventSubscriberInterface
{
public function __construct(private readonly bool $kernel_debug)
public function __construct(private readonly bool $kernel_debug_enabled)
{
}
@ -59,7 +59,7 @@ final class SymfonyDebugToolbarSubscriber implements EventSubscriberInterface
public function onKernelResponse(ResponseEvent $event): void
{
if (!$this->kernel_debug) {
if (!$this->kernel_debug_enabled) {
return;
}

View file

@ -37,14 +37,14 @@ use Symfony\Contracts\Translation\TranslatorInterface;
*/
final class LoginSuccessSubscriber implements EventSubscriberInterface
{
public function __construct(private readonly TranslatorInterface $translator, private readonly RequestStack $requestStack, private readonly EventLogger $eventLogger, private readonly bool $gpdr_compliance)
public function __construct(private readonly TranslatorInterface $translator, private readonly RequestStack $requestStack, private readonly EventLogger $eventLogger, private readonly bool $gdpr_compliance)
{
}
public function onLogin(InteractiveLoginEvent $event): void
{
$ip = $event->getRequest()->getClientIp();
$log = new UserLoginLogEntry($ip, $this->gpdr_compliance);
$log = new UserLoginLogEntry($ip, $this->gdpr_compliance);
$user = $event->getAuthenticationToken()->getUser();
if ($user instanceof User && $user->getID()) {
$log->setTargetElement($user);

View file

@ -23,17 +23,17 @@ declare(strict_types=1);
namespace App\EventSubscriber\UserSystem;
use App\Entity\UserSystem\User;
use Symfony\Bundle\SecurityBundle\Security;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\ControllerEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\Security\Core\Security;
/**
* The purpose of this event listener is to set the timezone to the one preferred by the user.
*/
final class SetUserTimezoneSubscriber implements EventSubscriberInterface
{
public function __construct(private readonly string $default_timezone, private readonly \Symfony\Bundle\SecurityBundle\Security $security)
public function __construct(private readonly string $default_timezone, private readonly Security $security)
{
}