summaryrefslogtreecommitdiffstats
path: root/Authentication
diff options
context:
space:
mode:
Diffstat (limited to 'Authentication')
-rw-r--r--Authentication/AuthenticationTrustResolver.php66
-rw-r--r--Authentication/AuthenticationTrustResolverInterface.php53
-rw-r--r--Authentication/Token/RememberMeToken.php56
3 files changed, 175 insertions, 0 deletions
diff --git a/Authentication/AuthenticationTrustResolver.php b/Authentication/AuthenticationTrustResolver.php
new file mode 100644
index 0000000..010fa91
--- /dev/null
+++ b/Authentication/AuthenticationTrustResolver.php
@@ -0,0 +1,66 @@
+<?php
+
+namespace Symfony\Component\Security\Authentication;
+
+use Symfony\Component\Security\Authentication\Token\TokenInterface;
+
+/**
+ * The default implementation of the authentication trust resolver.
+ *
+ * @author Johannes M. Schmitt <schmittjoh@gmail.com>
+ */
+class AuthenticationTrustResolver implements AuthenticationTrustResolverInterface
+{
+ protected $anonymousClass;
+ protected $rememberMeClass;
+
+ /**
+ * Constructor
+ *
+ * @param string $anonymousClass
+ * @param string $rememberMeClass
+ *
+ * @return void
+ */
+ public function __construct($anonymousClass, $rememberMeClass)
+ {
+ $this->anonymousClass = $anonymousClass;
+ $this->rememberMeClass = $rememberMeClass;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function isAnonymous(TokenInterface $token = null)
+ {
+ if (null === $token) {
+ return false;
+ }
+
+ return $token instanceof $this->anonymousClass;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function isRememberMe(TokenInterface $token = null)
+ {
+ if (null === $token) {
+ return false;
+ }
+
+ return $token instanceof $this->rememberMeClass;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function isFullFledged(TokenInterface $token = null)
+ {
+ if (null === $token) {
+ return false;
+ }
+
+ return !$this->isAnonymous($token) && !$this->isRememberMe($token);
+ }
+}
diff --git a/Authentication/AuthenticationTrustResolverInterface.php b/Authentication/AuthenticationTrustResolverInterface.php
new file mode 100644
index 0000000..e57bb65
--- /dev/null
+++ b/Authentication/AuthenticationTrustResolverInterface.php
@@ -0,0 +1,53 @@
+<?php
+
+namespace Symfony\Component\Security\Authentication;
+
+use Symfony\Component\Security\Authentication\Token\TokenInterface;
+
+/*
+ * 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 resolving the authentication status of a given token.
+ *
+ * @author Johannes M. Schmitt <schmittjoh@gmail.com>
+ */
+interface AuthenticationTrustResolverInterface
+{
+ /**
+ * Resolves whether the passed token implementation is authenticated
+ * anonymously.
+ *
+ * If null is passed, the method must return false.
+ *
+ * @param TokenInterface $token
+ *
+ * @return Boolean
+ */
+ function isAnonymous(TokenInterface $token = null);
+
+ /**
+ * Resolves whether the passed token implementation is authenticated
+ * using remember-me capabilities.
+ *
+ * @param TokenInterface $token
+ *
+ * @return Boolean
+ */
+ function isRememberMe(TokenInterface $token = null);
+
+ /**
+ * Resolves whether the passed token implementation is fully authenticated.
+ *
+ * @param TokenInterface $token
+ *
+ * @return Boolean
+ */
+ function isFullFledged(TokenInterface $token = null);
+}
diff --git a/Authentication/Token/RememberMeToken.php b/Authentication/Token/RememberMeToken.php
new file mode 100644
index 0000000..587222d
--- /dev/null
+++ b/Authentication/Token/RememberMeToken.php
@@ -0,0 +1,56 @@
+<?php
+
+namespace Symfony\Component\Security\Authentication\Token;
+
+use Symfony\Component\Security\Authentication\RememberMe\PersistentTokenInterface;
+use Symfony\Component\Security\User\AccountInterface;
+
+/**
+ * Base class for "Remember Me" tokens
+ *
+ * @author Johannes M. Schmitt <schmittjoh@gmail.com>
+ */
+class RememberMeToken extends Token
+{
+ protected $key;
+
+ /**
+ * The persistent token which resulted in this authentication token.
+ *
+ * @var PersistentTokenInterface
+ */
+ protected $persistentToken;
+
+ /**
+ * Constructor.
+ *
+ * @param string $username
+ * @param string $key
+ */
+ public function __construct(AccountInterface $user, $key) {
+ parent::__construct($user->getRoles());
+
+ if (0 === strlen($key)) {
+ throw new \InvalidArgumentException('$key cannot be empty.');
+ }
+
+ $this->user = $user;
+ $this->key = $key;
+ $this->setAuthenticated(true);
+ }
+
+ public function getKey()
+ {
+ return $this->key;
+ }
+
+ public function setPersistentToken(PersistentTokenInterface $persistentToken)
+ {
+ $this->persistentToken = $persistentToken;
+ }
+
+ public function getPersistentToken()
+ {
+ return $this->persistentToken;
+ }
+}