mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-07-01 14:04:30 +02:00
Use imports instead of FQNs
This commit is contained in:
parent
f63b6d7207
commit
5629215ce4
179 changed files with 792 additions and 597 deletions
67
src/EventSubscriber/LogSystem/LogLogoutEventSubscriber.php
Normal file
67
src/EventSubscriber/LogSystem/LogLogoutEventSubscriber.php
Normal file
|
@ -0,0 +1,67 @@
|
|||
<?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 Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
|
||||
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.
|
||||
*/
|
||||
final class LogLogoutEventSubscriber implements EventSubscriberInterface
|
||||
{
|
||||
public function __construct(private readonly EventLogger $logger, private readonly bool $gdpr_compliance)
|
||||
{
|
||||
}
|
||||
|
||||
public function logLogout(LogoutEvent $event): void
|
||||
{
|
||||
$request = $event->getRequest();
|
||||
$token = $event->getToken();
|
||||
|
||||
if (!$token instanceof TokenInterface) {
|
||||
return;
|
||||
}
|
||||
|
||||
$log = new UserLogoutLogEntry($request->getClientIp(), $this->gdpr_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 [LogoutEvent::class => 'logLogout'];
|
||||
}
|
||||
|
||||
}
|
|
@ -41,6 +41,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\EventSubscriber\LogSystem;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use App\Entity\LogSystem\SecurityEventLogEntry;
|
||||
use App\Events\SecurityEvent;
|
||||
use App\Events\SecurityEvents;
|
||||
|
@ -122,7 +123,7 @@ final class SecurityEventLoggerSubscriber implements EventSubscriberInterface
|
|||
$anonymize = $this->gdpr_compliance;
|
||||
|
||||
$request = $this->requestStack->getCurrentRequest();
|
||||
if ($request instanceof \Symfony\Component\HttpFoundation\Request) {
|
||||
if ($request instanceof Request) {
|
||||
$ip = $request->getClientIp() ?? 'unknown';
|
||||
} else {
|
||||
$ip = 'Console';
|
||||
|
|
|
@ -22,13 +22,13 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\EventSubscriber\UserSystem;
|
||||
|
||||
use Symfony\Bundle\SecurityBundle\Security;
|
||||
use App\Entity\UserSystem\User;
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
use Symfony\Component\HttpKernel\Event\RequestEvent;
|
||||
use Symfony\Component\HttpKernel\KernelEvents;
|
||||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
||||
use Symfony\Component\Security\Core\Security;
|
||||
|
||||
/**
|
||||
* This subscriber is used to log out a disabled user, as soon as he to do a request.
|
||||
|
@ -36,7 +36,7 @@ use Symfony\Component\Security\Core\Security;
|
|||
*/
|
||||
final class LogoutDisabledUserSubscriber implements EventSubscriberInterface
|
||||
{
|
||||
public function __construct(private readonly \Symfony\Bundle\SecurityBundle\Security $security, private readonly UrlGeneratorInterface $urlGenerator)
|
||||
public function __construct(private readonly Security $security, private readonly UrlGeneratorInterface $urlGenerator)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -22,6 +22,8 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\EventSubscriber\UserSystem;
|
||||
|
||||
use Symfony\Bundle\SecurityBundle\Security;
|
||||
use App\Entity\UserSystem\Group;
|
||||
use App\Entity\UserSystem\User;
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface;
|
||||
|
@ -29,7 +31,6 @@ use Symfony\Component\HttpFoundation\Session\Session;
|
|||
use Symfony\Component\HttpFoundation\Session\SessionInterface;
|
||||
use Symfony\Component\HttpKernel\Event\RequestEvent;
|
||||
use Symfony\Component\HttpKernel\KernelEvents;
|
||||
use Symfony\Component\Security\Core\Security;
|
||||
use Symfony\Component\Security\Http\HttpUtils;
|
||||
|
||||
/**
|
||||
|
@ -56,7 +57,7 @@ final class PasswordChangeNeededSubscriber implements EventSubscriberInterface
|
|||
*/
|
||||
public const REDIRECT_TARGET = 'user_settings';
|
||||
|
||||
public function __construct(private readonly \Symfony\Bundle\SecurityBundle\Security $security, private readonly HttpUtils $httpUtils)
|
||||
public function __construct(private readonly Security $security, private readonly HttpUtils $httpUtils)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -125,7 +126,7 @@ final class PasswordChangeNeededSubscriber implements EventSubscriberInterface
|
|||
{
|
||||
$tfa_enabled = $user->isWebAuthnAuthenticatorEnabled() || $user->isGoogleAuthenticatorEnabled();
|
||||
|
||||
return $user->getGroup() instanceof \App\Entity\UserSystem\Group && $user->getGroup()->isEnforce2FA() && !$tfa_enabled;
|
||||
return $user->getGroup() instanceof Group && $user->getGroup()->isEnforce2FA() && !$tfa_enabled;
|
||||
}
|
||||
|
||||
public static function getSubscribedEvents(): array
|
||||
|
|
|
@ -20,6 +20,8 @@
|
|||
|
||||
namespace App\EventSubscriber\UserSystem;
|
||||
|
||||
use Symfony\Bundle\SecurityBundle\Security;
|
||||
use Symfony\Component\Security\Core\User\UserInterface;
|
||||
use App\Entity\UserSystem\User;
|
||||
use App\Services\LogSystem\EventCommentHelper;
|
||||
use App\Services\UserSystem\PermissionSchemaUpdater;
|
||||
|
@ -28,14 +30,13 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
|||
use Symfony\Component\HttpFoundation\Session\Session;
|
||||
use Symfony\Component\HttpKernel\Event\RequestEvent;
|
||||
use Symfony\Component\HttpKernel\KernelEvents;
|
||||
use Symfony\Component\Security\Core\Security;
|
||||
|
||||
/**
|
||||
* The purpose of this event subscriber is to check if the permission schema of the current user is up-to-date and upgrade it automatically if needed.
|
||||
*/
|
||||
class UpgradePermissionsSchemaSubscriber implements EventSubscriberInterface
|
||||
{
|
||||
public function __construct(private readonly \Symfony\Bundle\SecurityBundle\Security $security, private readonly PermissionSchemaUpdater $permissionSchemaUpdater, private readonly EntityManagerInterface $entityManager, private readonly EventCommentHelper $eventCommentHelper)
|
||||
public function __construct(private readonly Security $security, private readonly PermissionSchemaUpdater $permissionSchemaUpdater, private readonly EntityManagerInterface $entityManager, private readonly EventCommentHelper $eventCommentHelper)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -46,7 +47,7 @@ class UpgradePermissionsSchemaSubscriber implements EventSubscriberInterface
|
|||
}
|
||||
|
||||
$user = $this->security->getUser();
|
||||
if (!$user instanceof \Symfony\Component\Security\Core\User\UserInterface) {
|
||||
if (!$user instanceof UserInterface) {
|
||||
//Retrieve anonymous user
|
||||
$user = $this->entityManager->getRepository(User::class)->getAnonymousUser();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue