Restructured EventSubscriber Folder structure.

This commit is contained in:
Jan Böhmer 2020-04-09 17:24:16 +02:00
parent e8f83f188a
commit 26737f4b46
14 changed files with 76 additions and 25 deletions

View file

@ -40,7 +40,7 @@ security:
logout: logout:
path: logout path: logout
target: homepage target: homepage
handlers: [App\EventSubscriber\LogoutListener] handlers: [App\EventSubscriber\LogSystem\LogoutLoggerHandler]
remember_me: remember_me:
secret: '%kernel.secret%' secret: '%kernel.secret%'

View file

@ -48,7 +48,7 @@ services:
resource: '../src/Controller' resource: '../src/Controller'
tags: ['controller.service_arguments'] tags: ['controller.service_arguments']
App\EventSubscriber\MailFromListener: App\EventSubscriber\SetMailFromSubscriber:
tags: ['kernel.event_subscriber'] tags: ['kernel.event_subscriber']
arguments: arguments:
$email: '%sender_email%' $email: '%sender_email%'
@ -75,7 +75,7 @@ services:
tags: tags:
- { name: "doctrine.orm.entity_listener" } - { name: "doctrine.orm.entity_listener" }
App\EventSubscriber\EventLoggerSubscriber: App\EventSubscriber\LogSystem\EventLoggerSubscriber:
arguments: arguments:
$save_changed_fields: '%env(bool:HISTORY_SAVE_CHANGED_FIELDS)%' $save_changed_fields: '%env(bool:HISTORY_SAVE_CHANGED_FIELDS)%'
$save_changed_data: '%env(bool:HISTORY_SAVE_CHANGED_DATA)%' $save_changed_data: '%env(bool:HISTORY_SAVE_CHANGED_DATA)%'
@ -83,7 +83,7 @@ services:
tags: tags:
- { name: 'doctrine.event_subscriber' } - { name: 'doctrine.event_subscriber' }
App\EventSubscriber\MigrationListener: App\EventSubscriber\LogSystem\LogDBMigrationSubscriber:
tags: tags:
- { name: 'doctrine.event_subscriber' } - { name: 'doctrine.event_subscriber' }
@ -138,7 +138,7 @@ services:
arguments: arguments:
$demo_mode: '%demo_mode%' $demo_mode: '%demo_mode%'
App\EventSubscriber\TimezoneListener: App\EventSubscriber\UserSystem\SetUserTimezoneSubscriber:
arguments: arguments:
$timezone: '%timezone%' $timezone: '%timezone%'

View file

@ -1,4 +1,22 @@
<?php <?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 - 2020 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); declare(strict_types=1);
@ -21,7 +39,7 @@ declare(strict_types=1);
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
namespace App\EventSubscriber; namespace App\EventSubscriber\LogSystem;
use App\Entity\Attachments\Attachment; use App\Entity\Attachments\Attachment;
use App\Entity\Base\AbstractDBElement; use App\Entity\Base\AbstractDBElement;
@ -47,6 +65,10 @@ use Doctrine\Persistence\Event\LifecycleEventArgs;
use Symfony\Component\PropertyAccess\PropertyAccessorInterface; use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
use Symfony\Component\Serializer\SerializerInterface; 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 class EventLoggerSubscriber implements EventSubscriber
{ {
/** @var array The given fields will not be saved, because they contain sensitive informations */ /** @var array The given fields will not be saved, because they contain sensitive informations */

View file

@ -40,7 +40,7 @@ declare(strict_types=1);
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/ */
namespace App\EventSubscriber; namespace App\EventSubscriber\LogSystem;
use App\Entity\LogSystem\DatabaseUpdatedLogEntry; use App\Entity\LogSystem\DatabaseUpdatedLogEntry;
use App\Services\LogSystem\EventLogger; use App\Services\LogSystem\EventLogger;
@ -48,7 +48,11 @@ use Doctrine\Common\EventSubscriber;
use Doctrine\Migrations\Event\MigrationsEventArgs; use Doctrine\Migrations\Event\MigrationsEventArgs;
use Doctrine\Migrations\Events; use Doctrine\Migrations\Events;
class MigrationListener implements EventSubscriber /**
* This subscriber logs databaseMigrations to Event log.
* @package App\EventSubscriber
*/
class LogDBMigrationSubscriber implements EventSubscriber
{ {
protected $old_version = null; protected $old_version = null;
protected $new_version = null; protected $new_version = null;

View file

@ -40,7 +40,7 @@ declare(strict_types=1);
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/ */
namespace App\EventSubscriber; namespace App\EventSubscriber\LogSystem;
use App\Entity\LogSystem\UserLogoutLogEntry; use App\Entity\LogSystem\UserLogoutLogEntry;
use App\Entity\UserSystem\User; use App\Entity\UserSystem\User;
@ -50,7 +50,11 @@ use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Http\Logout\LogoutHandlerInterface; use Symfony\Component\Security\Http\Logout\LogoutHandlerInterface;
class LogoutListener implements LogoutHandlerInterface /**
* This handler logs to event log, if a user logs out.
* @package App\EventSubscriber\LogSystem
*/
class LogoutLoggerHandler implements LogoutHandlerInterface
{ {
protected $logger; protected $logger;
protected $gpdr_compliance; protected $gpdr_compliance;

View file

@ -18,7 +18,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
namespace App\EventSubscriber; namespace App\EventSubscriber\LogSystem;
use App\Entity\LogSystem\SecurityEventLogEntry; use App\Entity\LogSystem\SecurityEventLogEntry;
@ -29,6 +29,10 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack; 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 final class SecurityEventLoggerSubscriber implements EventSubscriberInterface
{ {

View file

@ -47,7 +47,11 @@ use Symfony\Component\Mailer\Event\MessageEvent;
use Symfony\Component\Mime\Address; use Symfony\Component\Mime\Address;
use Symfony\Component\Mime\Email; use Symfony\Component\Mime\Email;
final class MailFromListener implements EventSubscriberInterface /**
* 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
{ {
private $email; private $email;
private $name; private $name;

View file

@ -47,6 +47,10 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent; use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\Event\ResponseEvent; 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 final class SymfonyDebugToolbarSubscriber implements EventSubscriberInterface
{ {
private $kernel_debug; private $kernel_debug;

View file

@ -40,7 +40,7 @@ declare(strict_types=1);
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/ */
namespace App\EventSubscriber; namespace App\EventSubscriber\UserSystem;
use App\Entity\LogSystem\UserLoginLogEntry; use App\Entity\LogSystem\UserLoginLogEntry;
use App\Entity\UserSystem\User; use App\Entity\UserSystem\User;
@ -52,9 +52,9 @@ use Symfony\Component\Security\Http\SecurityEvents;
use Symfony\Contracts\Translation\TranslatorInterface; use Symfony\Contracts\Translation\TranslatorInterface;
/** /**
* This event listener shows an login successful flash to the user after login. * This event listener shows an login successful flash to the user after login and write the login to event log.
*/ */
final class LoginSuccessListener implements EventSubscriberInterface final class LoginSuccessSubscriber implements EventSubscriberInterface
{ {
private $translator; private $translator;
private $flashBag; private $flashBag;

View file

@ -40,7 +40,7 @@ declare(strict_types=1);
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/ */
namespace App\EventSubscriber; namespace App\EventSubscriber\UserSystem;
use App\Entity\UserSystem\User; use App\Entity\UserSystem\User;
use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface;
@ -50,7 +50,12 @@ use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface; use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Security\Core\Security; use Symfony\Component\Security\Core\Security;
final class LogoutOnDisabledUserListener implements EventSubscriberInterface /**
* 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
{ {
private $security; private $security;
private $urlGenerator; private $urlGenerator;

View file

@ -40,7 +40,7 @@ declare(strict_types=1);
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/ */
namespace App\EventSubscriber; namespace App\EventSubscriber\UserSystem;
use App\Entity\UserSystem\User; use App\Entity\UserSystem\User;
use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface;

View file

@ -40,7 +40,7 @@ declare(strict_types=1);
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/ */
namespace App\EventSubscriber; namespace App\EventSubscriber\UserSystem;
use App\Entity\UserSystem\U2FKey; use App\Entity\UserSystem\U2FKey;
use App\Entity\UserSystem\User; use App\Entity\UserSystem\User;
@ -55,7 +55,11 @@ use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface; use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
final class U2FRegistrationSubscriber implements EventSubscriberInterface /**
* 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
{ {
private $em; private $em;

View file

@ -40,7 +40,7 @@ declare(strict_types=1);
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/ */
namespace App\EventSubscriber; namespace App\EventSubscriber\UserSystem;
use App\Entity\UserSystem\User; use App\Entity\UserSystem\User;
use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface;
@ -51,7 +51,7 @@ use Symfony\Component\Security\Core\Security;
/** /**
* The purpose of this event listener is to set the timezone to the one preferred by the user. * The purpose of this event listener is to set the timezone to the one preferred by the user.
*/ */
final class TimezoneListener implements EventSubscriberInterface final class SetUserTimezoneSubscriber implements EventSubscriberInterface
{ {
private $default_timezone; private $default_timezone;
private $security; private $security;

View file

@ -45,7 +45,7 @@ namespace App\Tests\EventSubscriber;
use App\Entity\UserSystem\Group; use App\Entity\UserSystem\Group;
use App\Entity\UserSystem\U2FKey; use App\Entity\UserSystem\U2FKey;
use App\Entity\UserSystem\User; use App\Entity\UserSystem\User;
use App\EventSubscriber\PasswordChangeNeededSubscriber; use App\EventSubscriber\UserSystem\PasswordChangeNeededSubscriber;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
class PasswordChangeNeededSubscriberTest extends TestCase class PasswordChangeNeededSubscriberTest extends TestCase
@ -57,11 +57,11 @@ class PasswordChangeNeededSubscriberTest extends TestCase
//A user without a group must not redirect //A user without a group must not redirect
$user->setGroup(null); $user->setGroup(null);
$this->assertFalse(PasswordChangeNeededSubscriber::TFARedirectNeeded($user)); $this->assertFalse(\App\EventSubscriber\UserSystem\PasswordChangeNeededSubscriber::TFARedirectNeeded($user));
//When the group does not enforce the redirect the user must not be redirected //When the group does not enforce the redirect the user must not be redirected
$user->setGroup($group); $user->setGroup($group);
$this->assertFalse(PasswordChangeNeededSubscriber::TFARedirectNeeded($user)); $this->assertFalse(\App\EventSubscriber\UserSystem\PasswordChangeNeededSubscriber::TFARedirectNeeded($user));
//The user must be redirected if the group enforces 2FA and it does not have a method //The user must be redirected if the group enforces 2FA and it does not have a method
$group->setEnforce2FA(true); $group->setEnforce2FA(true);