Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
87.50% covered (warning)
87.50%
7 / 8
66.67% covered (warning)
66.67%
2 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
UserChecker
87.50% covered (warning)
87.50%
7 / 8
66.67% covered (warning)
66.67%
2 / 3
5.05
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 checkPreAuth
83.33% covered (warning)
83.33%
5 / 6
0.00% covered (danger)
0.00%
0 / 1
3.04
 checkPostAuth
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3/**
4 * This file is part of the MADIS - RGPD Management application.
5 *
6 * @copyright Copyright (c) 2018-2019 Soluris - Solutions Numériques Territoriales Innovantes
7 *
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU Affero General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Affero General Public License for more details.
17 *
18 * You should have received a copy of the GNU Affero General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
22declare(strict_types=1);
23
24namespace App\Domain\User\Symfony\Security\Checker;
25
26use App\Domain\User\Model\User;
27use App\Domain\User\Symfony\Security\Authorization\UserAuthorization;
28use Symfony\Component\Security\Core\Exception\DisabledException;
29use Symfony\Component\Security\Core\User\UserCheckerInterface;
30use Symfony\Component\Security\Core\User\UserInterface;
31
32class UserChecker implements UserCheckerInterface
33{
34    /**
35     * @var UserAuthorization
36     */
37    private $userAuthorization;
38
39    /**
40     * UserChecker constructor.
41     */
42    public function __construct(UserAuthorization $userAuthorization)
43    {
44        $this->userAuthorization = $userAuthorization;
45    }
46
47    /**
48     * Checks the user account before authentication.
49     *
50     * @throws DisabledException
51     */
52    public function checkPreAuth(UserInterface $user): void
53    {
54        if (!$user instanceof User) {
55            return;
56        }
57
58        if (!$this->userAuthorization->canConnect($user)) {
59            $ex = new DisabledException('User account is disabled.');
60            $ex->setUser($user);
61
62            throw $ex;
63        }
64    }
65
66    /**
67     * Checks the user account after authentication.
68     */
69    public function checkPostAuth(UserInterface $user): void
70    {
71    }
72}