|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Security; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Component\Security\Core\Exception\UnsupportedUserException; |
|
6
|
|
|
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException; |
|
7
|
|
|
use Symfony\Component\Security\Core\User\UserInterface; |
|
8
|
|
|
use Symfony\Component\Security\Core\User\UserProviderInterface; |
|
9
|
|
|
use Ramsey\Uuid\Uuid; |
|
10
|
|
|
|
|
11
|
|
|
class UserProvider implements UserProviderInterface |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* Symfony calls this method if you use features like switch_user |
|
15
|
|
|
* or remember_me. |
|
16
|
|
|
* |
|
17
|
|
|
* If you're not using these features, you do not need to implement |
|
18
|
|
|
* this method. |
|
19
|
|
|
* |
|
20
|
|
|
* @return UserInterface |
|
21
|
|
|
*/ |
|
22
|
|
|
public function loadUserByUsername($username) |
|
23
|
|
|
{ |
|
24
|
|
|
// Load a User object from your data source or throw UsernameNotFoundException. |
|
25
|
|
|
// The $username argument may not actually be a username: |
|
26
|
|
|
// it is whatever value is being returned by the getUsername() |
|
27
|
|
|
// method in your User class. |
|
28
|
|
|
throw new \Exception('TODO: fill in loadUserByUsername() inside '.__FILE__); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Refreshes the user after being reloaded from the session. |
|
33
|
|
|
* |
|
34
|
|
|
* When a user is logged in, at the beginning of each request, the |
|
35
|
|
|
* User object is loaded from the session and then this method is |
|
36
|
|
|
* called. Your job is to make sure the user's data is still fresh by, |
|
37
|
|
|
* for example, re-querying for fresh User data. |
|
38
|
|
|
* |
|
39
|
|
|
* If your firewall is "stateless: true" (for a pure API), this |
|
40
|
|
|
* method is not called. |
|
41
|
|
|
* |
|
42
|
|
|
* @return UserInterface |
|
43
|
|
|
*/ |
|
44
|
|
|
public function refreshUser(UserInterface $user) |
|
45
|
|
|
{ |
|
46
|
|
|
if (!$user instanceof User) { |
|
47
|
|
|
throw new UnsupportedUserException(sprintf('Invalid user class "%s".', get_class($user))); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/* @var User $user */ |
|
51
|
|
|
|
|
52
|
|
|
// Return a User object after making sure its data is "fresh". |
|
53
|
|
|
// Or throw a UsernameNotFoundException if the user no longer exists. |
|
54
|
|
|
throw new \Exception('TODO: fill in refreshUser() inside '.__FILE__); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Tells Symfony to use this provider for this User class. |
|
59
|
|
|
*/ |
|
60
|
|
|
public function supportsClass($class) |
|
61
|
|
|
{ |
|
62
|
|
|
return User::class === $class; |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|