| @@ 15-34 (lines=20) @@ | ||
| 12 | use eZ\Publish\Core\MVC\Symfony\Security\UserInterface; |
|
| 13 | use Symfony\Component\Security\Core\Exception\UsernameNotFoundException; |
|
| 14 | ||
| 15 | final class EmailProvider extends BaseProvider |
|
| 16 | { |
|
| 17 | public function loadUserByUsername($user) |
|
| 18 | { |
|
| 19 | try { |
|
| 20 | // SecurityContext always tries to authenticate anonymous users when checking granted access. |
|
| 21 | // In that case $user is an instance of \eZ\Publish\Core\MVC\Symfony\Security\User. |
|
| 22 | // We don't need to reload the user here. |
|
| 23 | if ($user instanceof UserInterface) { |
|
| 24 | return $user; |
|
| 25 | } |
|
| 26 | ||
| 27 | return $this->createSecurityUser( |
|
| 28 | $this->userService->loadUserByEmail($user) |
|
| 29 | ); |
|
| 30 | } catch (NotFoundException $e) { |
|
| 31 | throw new UsernameNotFoundException($e->getMessage(), 0, $e); |
|
| 32 | } |
|
| 33 | } |
|
| 34 | } |
|
| 35 | ||
| @@ 15-34 (lines=20) @@ | ||
| 12 | use eZ\Publish\Core\MVC\Symfony\Security\UserInterface; |
|
| 13 | use Symfony\Component\Security\Core\Exception\UsernameNotFoundException; |
|
| 14 | ||
| 15 | final class UsernameProvider extends BaseProvider |
|
| 16 | { |
|
| 17 | public function loadUserByUsername($user) |
|
| 18 | { |
|
| 19 | try { |
|
| 20 | // SecurityContext always tries to authenticate anonymous users when checking granted access. |
|
| 21 | // In that case $user is an instance of \eZ\Publish\Core\MVC\Symfony\Security\User. |
|
| 22 | // We don't need to reload the user here. |
|
| 23 | if ($user instanceof UserInterface) { |
|
| 24 | return $user; |
|
| 25 | } |
|
| 26 | ||
| 27 | return $this->createSecurityUser( |
|
| 28 | $this->userService->loadUserByLogin($user) |
|
| 29 | ); |
|
| 30 | } catch (NotFoundException $e) { |
|
| 31 | throw new UsernameNotFoundException($e->getMessage(), 0, $e); |
|
| 32 | } |
|
| 33 | } |
|
| 34 | } |
|
| 35 | ||