summaryrefslogtreecommitdiffstats
path: root/Authentication/RememberMe
diff options
context:
space:
mode:
authorJohannes Schmitt <schmittjoh@gmail.com>2011-01-25 20:28:26 +0100
committerFabien Potencier <fabien.potencier@gmail.com>2011-01-26 16:38:54 +0100
commit521c9f65e9d70618f63ac6ed803a495651b9fd35 (patch)
tree4e64bf3f877a4050eb3eb95c0b55630a4105053c /Authentication/RememberMe
parentbff922f5c7ab61fb144e124b584da067842cb955 (diff)
downloadsymfony-security-521c9f65e9d70618f63ac6ed803a495651b9fd35.zip
symfony-security-521c9f65e9d70618f63ac6ed803a495651b9fd35.tar.gz
symfony-security-521c9f65e9d70618f63ac6ed803a495651b9fd35.tar.bz2
[Security] many improvements, and fixes
Diffstat (limited to 'Authentication/RememberMe')
-rw-r--r--Authentication/RememberMe/InMemoryTokenProvider.php50
-rw-r--r--Authentication/RememberMe/PersistentToken.php107
-rw-r--r--Authentication/RememberMe/PersistentTokenInterface.php45
-rw-r--r--Authentication/RememberMe/TokenProviderInterface.php51
4 files changed, 253 insertions, 0 deletions
diff --git a/Authentication/RememberMe/InMemoryTokenProvider.php b/Authentication/RememberMe/InMemoryTokenProvider.php
new file mode 100644
index 0000000..71c1bf2
--- /dev/null
+++ b/Authentication/RememberMe/InMemoryTokenProvider.php
@@ -0,0 +1,50 @@
+<?php
+
+namespace Symfony\Component\Security\Authentication\RememberMe;
+
+use Symfony\Component\Security\Exception\TokenNotFoundException;
+
+/**
+ * This class is used for testing purposes, and is not really suited for production.
+ *
+ * @author Johannes M. Schmitt <schmittjoh@gmail.com>
+ */
+class InMemoryTokenProvider implements TokenProviderInterface
+{
+ protected $tokens = array();
+
+ public function loadTokenBySeries($series)
+ {
+ if (!isset($this->tokens[$series])) {
+ throw new TokenNotFoundException('No token found.');
+ }
+
+ return $this->tokens[$series];
+ }
+
+ public function updateToken($series, $tokenValue, \DateTime $lastUsed)
+ {
+ if (!isset($this->tokens[$series])) {
+ throw new TokenNotFoundException('No token found.');
+ }
+
+ $token = new PersistentToken(
+ $this->tokens[$series]->getClass(),
+ $this->tokens[$series]->getUsername(),
+ $series,
+ $tokenValue,
+ $lastUsed
+ );
+ $this->tokens[$series] = $token;
+ }
+
+ public function deleteTokenBySeries($series)
+ {
+ unset($this->tokens[$series]);
+ }
+
+ public function createNewToken(PersistentTokenInterface $token)
+ {
+ $this->tokens[$token->getSeries()] = $token;
+ }
+} \ No newline at end of file
diff --git a/Authentication/RememberMe/PersistentToken.php b/Authentication/RememberMe/PersistentToken.php
new file mode 100644
index 0000000..cdbc296
--- /dev/null
+++ b/Authentication/RememberMe/PersistentToken.php
@@ -0,0 +1,107 @@
+<?php
+
+namespace Symfony\Component\Security\Authentication\RememberMe;
+
+/*
+ * 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.
+ */
+
+/**
+ * This class is only used by PersistentTokenRememberMeServices internally.
+ *
+ * @author Johannes M. Schmitt <schmittjoh@gmail.com>
+ */
+final class PersistentToken implements PersistentTokenInterface
+{
+ private $class;
+ private $username;
+ private $series;
+ private $tokenValue;
+ private $lastUsed;
+
+ /**
+ * Constructor
+ *
+ * @param string $class
+ * @param string $username
+ * @param string $series
+ * @param string $tokenValue
+ * @param DateTime $lastUsed
+ */
+ public function __construct($class, $username, $series, $tokenValue, \DateTime $lastUsed)
+ {
+ if (empty($class)) {
+ throw new \InvalidArgumentException('$class must not be empty.');
+ }
+ if (empty($username)) {
+ throw new \InvalidArgumentException('$username must not be empty.');
+ }
+ if (empty($series)) {
+ throw new \InvalidArgumentException('$series must not be empty.');
+ }
+ if (empty($tokenValue)) {
+ throw new \InvalidArgumentException('$tokenValue must not be empty.');
+ }
+
+ $this->class = $class;
+ $this->username = $username;
+ $this->series = $series;
+ $this->tokenValue = $tokenValue;
+ $this->lastUsed = $lastUsed;
+ }
+
+ /**
+ * Returns the class of the user
+ *
+ * @return string
+ */
+ public function getClass()
+ {
+ return $this->class;
+ }
+
+ /**
+ * Returns the username
+ *
+ * @return string
+ */
+ public function getUsername()
+ {
+ return $this->username;
+ }
+
+ /**
+ * Returns the series
+ *
+ * @return string
+ */
+ public function getSeries()
+ {
+ return $this->series;
+ }
+
+ /**
+ * Returns the token value
+ *
+ * @return string
+ */
+ public function getTokenValue()
+ {
+ return $this->tokenValue;
+ }
+
+ /**
+ * Returns the time the token was last used
+ *
+ * @return DateTime
+ */
+ public function getLastUsed()
+ {
+ return $this->lastUsed;
+ }
+} \ No newline at end of file
diff --git a/Authentication/RememberMe/PersistentTokenInterface.php b/Authentication/RememberMe/PersistentTokenInterface.php
new file mode 100644
index 0000000..5525a34
--- /dev/null
+++ b/Authentication/RememberMe/PersistentTokenInterface.php
@@ -0,0 +1,45 @@
+<?php
+
+namespace Symfony\Component\Security\Authentication\RememberMe;
+
+/*
+ * 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.
+ */
+
+/**
+ * Interface to be implemented by persistent token classes (such as
+ * Doctrine entities representing a remember-me token)
+ *
+ * @author Johannes M. Schmitt <schmittjoh@gmail.com>
+ */
+interface PersistentTokenInterface
+{
+ /**
+ * Returns the username
+ * @return string
+ */
+ function getUsername();
+
+ /**
+ * Returns the series
+ * @return string
+ */
+ function getSeries();
+
+ /**
+ * Returns the token value
+ * @return string
+ */
+ function getTokenValue();
+
+ /**
+ * Returns the last time the cookie was used
+ * @return \DateTime
+ */
+ function getLastUsed();
+} \ No newline at end of file
diff --git a/Authentication/RememberMe/TokenProviderInterface.php b/Authentication/RememberMe/TokenProviderInterface.php
new file mode 100644
index 0000000..0ed3f50
--- /dev/null
+++ b/Authentication/RememberMe/TokenProviderInterface.php
@@ -0,0 +1,51 @@
+<?php
+
+namespace Symfony\Component\Security\Authentication\RememberMe;
+
+/*
+ * 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.
+ */
+
+/**
+ * Interface for TokenProviders
+ *
+ * @author Johannes M. Schmitt <schmittjoh@gmail.com>
+ */
+interface TokenProviderInterface
+{
+ /**
+ * Loads the active token for the given series
+ *
+ * @throws TokenNotFoundException if the token is not found
+ *
+ * @param string $series
+ * @return PersistentTokenInterface
+ */
+ function loadTokenBySeries($series);
+
+ /**
+ * Deletes all tokens belonging to series
+ * @param string $series
+ */
+ function deleteTokenBySeries($series);
+
+ /**
+ * Updates the token according to this data
+ *
+ * @param string $series
+ * @param string $tokenValue
+ * @param DateTime $lastUsed
+ */
+ function updateToken($series, $tokenValue, \DateTime $lastUsed);
+
+ /**
+ * Creates a new token
+ * @param PersistentTokenInterface $token
+ */
+ function createNewToken(PersistentTokenInterface $token);
+} \ No newline at end of file