* * 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 */ 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; } }