summaryrefslogtreecommitdiffstats
path: root/Core/Authentication/Provider/AnonymousAuthenticationProvider.php
diff options
context:
space:
mode:
Diffstat (limited to 'Core/Authentication/Provider/AnonymousAuthenticationProvider.php')
-rw-r--r--Core/Authentication/Provider/AnonymousAuthenticationProvider.php60
1 files changed, 60 insertions, 0 deletions
diff --git a/Core/Authentication/Provider/AnonymousAuthenticationProvider.php b/Core/Authentication/Provider/AnonymousAuthenticationProvider.php
new file mode 100644
index 0000000..821e17e
--- /dev/null
+++ b/Core/Authentication/Provider/AnonymousAuthenticationProvider.php
@@ -0,0 +1,60 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
+ *
+ * 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\Authentication\Token\TokenInterface;
+use Symfony\Component\Security\Core\Exception\BadCredentialsException;
+use Symfony\Component\Security\Core\Authentication\Token\AnonymousToken;
+
+/**
+ * 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;
+ }
+}