1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* Copyright (C) 2020 Jan Böhmer |
4
|
|
|
* |
5
|
|
|
* This program is free software: you can redistribute it and/or modify |
6
|
|
|
* it under the terms of the GNU Affero General Public License as published |
7
|
|
|
* by the Free Software Foundation, either version 3 of the License, or |
8
|
|
|
* (at your option) any later version. |
9
|
|
|
* |
10
|
|
|
* This program is distributed in the hope that it will be useful, |
11
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
12
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13
|
|
|
* GNU Affero General Public License for more details. |
14
|
|
|
* |
15
|
|
|
* You should have received a copy of the GNU Affero General Public License |
16
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
namespace App\Audit; |
20
|
|
|
|
21
|
|
|
|
22
|
|
|
use DH\Auditor\Security\SecurityProviderInterface; |
23
|
|
|
use Symfony\Bundle\SecurityBundle\Security\FirewallMap; |
24
|
|
|
use Symfony\Component\HttpFoundation\IpUtils; |
25
|
|
|
use Symfony\Component\HttpFoundation\RequestStack; |
26
|
|
|
|
27
|
|
|
class AnonymizedIPSecurityProvider implements SecurityProviderInterface |
28
|
|
|
{ |
29
|
|
|
private $requestStack; |
30
|
|
|
private $firewallMap; |
31
|
|
|
|
32
|
|
|
public function __construct(RequestStack $requestStack, FirewallMap $firewallMap) |
33
|
|
|
{ |
34
|
|
|
$this->requestStack = $requestStack; |
35
|
|
|
$this->firewallMap = $firewallMap; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function __invoke(): array |
39
|
|
|
{ |
40
|
|
|
$clientIp = null; |
41
|
|
|
$firewallName = null; |
42
|
|
|
|
43
|
|
|
$request = $this->requestStack->getCurrentRequest(); |
44
|
|
|
if (null !== $request) { |
45
|
|
|
$firewallConfig = $this->firewallMap->getFirewallConfig($request); |
46
|
|
|
|
47
|
|
|
$clientIp = $request->getClientIp(); |
48
|
|
|
//Censor clientIP to be GPDR conform |
49
|
|
|
$clientIp = IpUtils::anonymize($clientIp); |
|
|
|
|
50
|
|
|
|
51
|
|
|
$firewallName = null === $firewallConfig ? null : $firewallConfig->getName(); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
return [$clientIp, $firewallName]; |
55
|
|
|
} |
56
|
|
|
} |