summaryrefslogtreecommitdiffstats
path: root/Authentication/Provider/AnonymousAuthenticationProvider.php
diff options
context:
space:
mode:
authorFabien Potencier <fabien.potencier@gmail.com>2010-10-19 13:06:43 +0200
committerFabien Potencier <fabien.potencier@gmail.com>2010-10-19 13:33:17 +0200
commit3fec93d3ff1f6a31f078e5558a15a75539bf5185 (patch)
tree1a6229643289d9d0ca55871bab9497035a6e49f1 /Authentication/Provider/AnonymousAuthenticationProvider.php
downloadsymfony-security-3fec93d3ff1f6a31f078e5558a15a75539bf5185.zip
symfony-security-3fec93d3ff1f6a31f078e5558a15a75539bf5185.tar.gz
symfony-security-3fec93d3ff1f6a31f078e5558a15a75539bf5185.tar.bz2
added the Security Component and its integration into the MVC framework
Happy birthday symfony!
Diffstat (limited to 'Authentication/Provider/AnonymousAuthenticationProvider.php')
-rw-r--r--Authentication/Provider/AnonymousAuthenticationProvider.php60
1 files changed, 60 insertions, 0 deletions
diff --git a/Authentication/Provider/AnonymousAuthenticationProvider.php b/Authentication/Provider/AnonymousAuthenticationProvider.php
new file mode 100644
index 0000000..67671b5
--- /dev/null
+++ b/Authentication/Provider/AnonymousAuthenticationProvider.php
@@ -0,0 +1,60 @@
+<?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;
+ }
+
+ /**
+ * {@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($token)
+ {
+ return $token instanceof AnonymousToken;
+ }
+}