* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Security\Core\Authentication\Provider; use Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface; use Symfony\Component\Security\Core\User\UserProviderInterface; use Symfony\Component\Security\Core\User\UserCheckerInterface; use Symfony\Component\Security\Core\User\UserInterface; use Symfony\Component\Security\Core\Exception\UsernameNotFoundException; use Symfony\Component\Security\Core\Exception\AuthenticationServiceException; use Symfony\Component\Security\Core\Exception\BadCredentialsException; use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken; /** * DaoAuthenticationProvider uses a UserProviderInterface to retrieve the user * for a UsernamePasswordToken. * * @author Fabien Potencier */ class DaoAuthenticationProvider extends UserAuthenticationProvider { private $encoderFactory; private $userProvider; /** * @param UserProviderInterface $userProvider An UserProviderInterface instance * @param UserCheckerInterface $userChecker An UserCheckerInterface instance * @param string $providerKey The provider key * @param EncoderFactoryInterface $encoderFactory An EncoderFactoryInterface instance * @param bool $hideUserNotFoundExceptions Whether to hide user not found exception or not */ public function __construct(UserProviderInterface $userProvider, UserCheckerInterface $userChecker, $providerKey, EncoderFactoryInterface $encoderFactory, $hideUserNotFoundExceptions = true) { parent::__construct($userChecker, $providerKey, $hideUserNotFoundExceptions); $this->encoderFactory = $encoderFactory; $this->userProvider = $userProvider; } /** * {@inheritdoc} */ protected function checkAuthentication(UserInterface $user, UsernamePasswordToken $token) { $currentUser = $token->getUser(); if ($currentUser instanceof UserInterface) { if ($currentUser->getPassword() !== $user->getPassword()) { throw new BadCredentialsException('The credentials were changed from another session.'); } } else { if ('' === ($presentedPassword = $token->getCredentials())) { throw new BadCredentialsException('The presented password cannot be empty.'); } if (!$this->encoderFactory->getEncoder($user)->isPasswordValid($user->getPassword(), $presentedPassword, $user->getSalt())) { throw new BadCredentialsException('The presented password is invalid.'); } } } /** * {@inheritdoc} */ protected function retrieveUser($username, UsernamePasswordToken $token) { $user = $token->getUser(); if ($user instanceof UserInterface) { return $user; } try { $user = $this->userProvider->loadUserByUsername($username); if (!$user instanceof UserInterface) { throw new AuthenticationServiceException('The user provider must return a UserInterface object.'); } return $user; } catch (UsernameNotFoundException $e) { $e->setUsername($username); throw $e; } catch (\Exception $e) { $e = new AuthenticationServiceException($e->getMessage(), 0, $e); $e->setToken($token); throw $e; } } } __halt_compiler();----SIGNATURE:----lQqdr/tBCjkUb4JPwRlQlWb09RSwHpiRJcw23zS9FaNoQZEe96gI3Crk1JDSBevU5ZWdShDXMYlXmhh8Q7RtE1xhqy1iQPZdVMk/k0l0BrTGFXZt7+maqaZ3N9HARAYPK7ZS4Lp4AYy2FEN0cajabAyckFiSarEnpUA2ldUeiuyS44YbDhn4rI0MR9ZeeIx1R3THfpyzjQd60UQfGK1wtwLlwYNOEZg7QAbfrV6NJ8GY6UfIfTD4OzqQbU8GHIs3Q1Kcd3HJj8t8YsKrVeU46kbORxKiCEJu/iVnXQ3JqLQePkWRbRM2K0HEERJ6bOXAQi7BWR+HIYl6MGEI1LAWwgote2ori5SEOGiNRu7pOXhRBNXJOqR6+hrlF5hfRllcGvlUHkouTS/JtfR0qvs0i2fT4RGGpbIxzpZ3nEFJqro5pheBVZdEPRCMxipqfQxqeE4y76B8CMFq+oAPsHhnloKAB2mQCqGfWnjSHt6+2aNBmDUB8pHlMRzV2qRW/OeRfgjcBNCJ5tyf4mJz8MV9XcKIrPlXEIFhbNhI9qyO52CCDpcBdjrVeJhg6heddlCe45Ro8KcREgPbXn+CptMQqF4mUc4gyizaMJoJNVWi6yk4jJVHc2x5Y1hbyzGOkrBfFv51QUJAyzprJJllB84g1cAlY473NimpkVrR+uRvp+Q=----ATTACHMENT:----ODkzODY5NzAyNDExMTg5NCA1OTg1OTQ2MDQyNTM4Mjc2IDQ1OTA4NDI1NDUzNzIwNjg=