Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
763bba9
commit abe8047
Showing
10 changed files
with
321 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
src/Symfony/Component/Security/Authentication/AuthenticationTrustResolver.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
src/Symfony/Component/Security/Authentication/AuthenticationTrustResolverInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |
56 changes: 56 additions & 0 deletions
56
src/Symfony/Component/Security/Authentication/Token/RememberMeToken.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.