|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). |
|
4
|
|
|
* |
|
5
|
|
|
* Copyright (C) 2019 - 2020 Jan Böhmer (https://github.com/jbtronics) |
|
6
|
|
|
* |
|
7
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
8
|
|
|
* it under the terms of the GNU Affero General Public License as published |
|
9
|
|
|
* by the Free Software Foundation, either version 3 of the License, or |
|
10
|
|
|
* (at your option) any later version. |
|
11
|
|
|
* |
|
12
|
|
|
* This program is distributed in the hope that it will be useful, |
|
13
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
15
|
|
|
* GNU Affero General Public License for more details. |
|
16
|
|
|
* |
|
17
|
|
|
* You should have received a copy of the GNU Affero General Public License |
|
18
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. |
|
19
|
|
|
*/ |
|
20
|
|
|
|
|
21
|
|
|
declare(strict_types=1); |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). |
|
25
|
|
|
* |
|
26
|
|
|
* Copyright (C) 2019 - 2020 Jan Böhmer (https://github.com/jbtronics) |
|
27
|
|
|
* |
|
28
|
|
|
* This program is free software; you can redistribute it and/or |
|
29
|
|
|
* modify it under the terms of the GNU General Public License |
|
30
|
|
|
* as published by the Free Software Foundation; either version 2 |
|
31
|
|
|
* of the License, or (at your option) any later version. |
|
32
|
|
|
* |
|
33
|
|
|
* This program is distributed in the hope that it will be useful, |
|
34
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
35
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
36
|
|
|
* GNU General Public License for more details. |
|
37
|
|
|
* |
|
38
|
|
|
* You should have received a copy of the GNU General Public License |
|
39
|
|
|
* along with this program; if not, write to the Free Software |
|
40
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
|
41
|
|
|
*/ |
|
42
|
|
|
|
|
43
|
|
|
namespace App\EventSubscriber\LogSystem; |
|
44
|
|
|
|
|
45
|
|
|
use App\Entity\LogSystem\UserLogoutLogEntry; |
|
46
|
|
|
use App\Entity\UserSystem\User; |
|
47
|
|
|
use App\Services\LogSystem\EventLogger; |
|
48
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
49
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
50
|
|
|
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; |
|
51
|
|
|
use Symfony\Component\Security\Http\Event\LogoutEvent; |
|
52
|
|
|
use Symfony\Component\Security\Http\Logout\LogoutHandlerInterface; |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* This handler logs to event log, if a user logs out. |
|
56
|
|
|
*/ |
|
57
|
|
|
class LogoutLoggerListener |
|
58
|
|
|
{ |
|
59
|
|
|
protected $logger; |
|
60
|
|
|
protected $gpdr_compliance; |
|
61
|
|
|
|
|
62
|
|
|
public function __construct(EventLogger $logger, bool $gpdr_compliance) |
|
63
|
|
|
{ |
|
64
|
|
|
$this->logger = $logger; |
|
65
|
|
|
$this->gpdr_compliance = $gpdr_compliance; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
|
|
69
|
|
|
public function __invoke(LogoutEvent $event) |
|
70
|
|
|
{ |
|
71
|
|
|
$request = $event->getRequest(); |
|
72
|
|
|
$token = $event->getToken(); |
|
73
|
|
|
|
|
74
|
|
|
if ($token === null) { |
|
75
|
|
|
return; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
$log = new UserLogoutLogEntry($request->getClientIp(), $this->gpdr_compliance); |
|
|
|
|
|
|
79
|
|
|
$user = $token->getUser(); |
|
80
|
|
|
if ($user instanceof User) { |
|
81
|
|
|
$log->setTargetElement($user); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
$this->logger->logAndFlush($log); |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|