1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* Copyright (C) 2020-2025 Iain Cambridge |
7
|
|
|
* |
8
|
|
|
* This program is free software: you can redistribute it and/or modify |
9
|
|
|
* it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE as published by |
10
|
|
|
* the Free Software Foundation, either version 2.1 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 Lesser General Public License for more details. |
17
|
|
|
* |
18
|
|
|
* You should have received a copy of the GNU General Public License |
19
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. |
20
|
|
|
*/ |
21
|
|
|
|
22
|
|
|
namespace Parthenon\User\Security; |
23
|
|
|
|
24
|
|
|
use Parthenon\Common\Exception\NoEntityFoundException; |
25
|
|
|
use Parthenon\User\Repository\UserRepositoryInterface; |
26
|
|
|
use Symfony\Component\Security\Core\Exception\UserNotFoundException; |
27
|
|
|
use Symfony\Component\Security\Core\User\UserInterface; |
28
|
|
|
use Symfony\Component\Security\Core\User\UserProviderInterface; |
29
|
|
|
|
30
|
|
|
final class UserProvider implements UserProviderInterface |
31
|
|
|
{ |
32
|
|
|
private UserRepositoryInterface $userRepository; |
33
|
|
|
|
34
|
|
|
public function __construct(UserRepositoryInterface $userRepository) |
35
|
|
|
{ |
36
|
|
|
$this->userRepository = $userRepository; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function loadUserByUsername(string $username) |
40
|
|
|
{ |
41
|
|
|
try { |
42
|
|
|
$user = $this->userRepository->findByEmail($username); |
43
|
|
|
} catch (NoEntityFoundException $e) { |
44
|
|
|
throw new UserNotFoundException(''); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
return $user; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function refreshUser(UserInterface $user): UserInterface |
51
|
|
|
{ |
52
|
|
|
return $this->loadUserByUsername($user->getUsername()); |
|
|
|
|
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function supportsClass(string $class): bool |
56
|
|
|
{ |
57
|
|
|
return true; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function loadUserByIdentifier(string $identifier): UserInterface |
61
|
|
|
{ |
62
|
|
|
return $this->loadUserByUsername($identifier); |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|