123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- <?php
- namespace Symfony\Component\Security\Authentication\Provider;
- use Symfony\Component\Security\Authentication\Token\TokenInterface;
- use Symfony\Component\Security\Exception\BadCredentialsException;
- use Symfony\Component\Security\Authentication\Token\AnonymousToken;
- /*
- * This file is part of the Symfony framework.
- *
- * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
- *
- * This source file is subject to the MIT license that is bundled
- * with this source code in the file LICENSE.
- */
- /**
- * AnonymousAuthenticationProvider validates AnonymousToken instances.
- *
- * @author Fabien Potencier <fabien.potencier@symfony-project.com>
- */
- class AnonymousAuthenticationProvider implements AuthenticationProviderInterface
- {
- protected $key;
- /**
- * Constructor.
- *
- * @param string $key The key shared with the authentication token
- */
- public function __construct($key)
- {
- $this->key = $key;
- }
- /**
- * {@inheritdoc}
- */
- public function authenticate(TokenInterface $token)
- {
- if (!$this->supports($token)) {
- return null;
- }
- if ($this->key != $token->getKey()) {
- throw new BadCredentialsException('The Token does not contain the expected key.');
- }
- return $token;
- }
- /**
- * {@inheritdoc}
- */
- public function supports(TokenInterface $token)
- {
- return $token instanceof AnonymousToken;
- }
- }
|