jbtronics /
StuRa-Finanzsoftware
| 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 | use DH\Auditor\Security\SecurityProviderInterface; |
||
| 22 | use Symfony\Bundle\SecurityBundle\Security\FirewallMap; |
||
| 23 | use Symfony\Component\HttpFoundation\IpUtils; |
||
| 24 | use Symfony\Component\HttpFoundation\RequestStack; |
||
| 25 | |||
| 26 | class AnonymizedIPSecurityProvider implements SecurityProviderInterface |
||
| 27 | { |
||
| 28 | private $requestStack; |
||
| 29 | private $firewallMap; |
||
| 30 | |||
| 31 | public function __construct(RequestStack $requestStack, FirewallMap $firewallMap) |
||
| 32 | { |
||
| 33 | $this->requestStack = $requestStack; |
||
| 34 | $this->firewallMap = $firewallMap; |
||
| 35 | } |
||
| 36 | |||
| 37 | public function __invoke(): array |
||
| 38 | { |
||
| 39 | $clientIp = null; |
||
| 40 | $firewallName = null; |
||
| 41 | |||
| 42 | $request = $this->requestStack->getCurrentRequest(); |
||
| 43 | if (null !== $request) { |
||
| 44 | $firewallConfig = $this->firewallMap->getFirewallConfig($request); |
||
| 45 | |||
| 46 | $clientIp = $request->getClientIp(); |
||
| 47 | //Censor clientIP to be GPDR conform |
||
| 48 | $clientIp = IpUtils::anonymize($clientIp); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 49 | |||
| 50 | $firewallName = null === $firewallConfig ? null : $firewallConfig->getName(); |
||
| 51 | } |
||
| 52 | |||
| 53 | return [$clientIp, $firewallName]; |
||
| 54 | } |
||
| 55 | } |
||
| 56 |