Last active
December 15, 2015 04:59
-
-
Save marijn/60a45044a50dd9d96b70 to your computer and use it in GitHub Desktop.
Alternative to the default SecurityContextInterface implementation from Symfony
This file contains hidden or 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
<?php | |
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; | |
use Symfony\Component\Security\Core\SecurityContextInterface; | |
final class SecurityGuard implements SecurityContextInterface | |
{ | |
private $nativeSecurityContext; | |
public function __construct(SecurityContextInterface $nativeSecurityContext) | |
{ | |
$this->nativeSecurityContext = $nativeSecurityContext; | |
} | |
public function authenticate(TokenInterface $token) | |
{ | |
return $this->nativeSecurityContext->setToken($token); | |
} | |
public function logout() | |
{ | |
return $this->nativeSecurityContext->setToken(null); | |
} | |
public function isGranted($attributes, $object = null) | |
{ | |
return $this->nativeSecurityContext->isGranted($attributes, $object); | |
} | |
/** | |
* @deprecated | |
* @see authenticate() | |
* @see logout() | |
*/ | |
public function setToken(TokenInterface $token = null) | |
{ | |
return $this->nativeSecurityContext->setToken($token); | |
} | |
/** | |
* @return TokenInterface|null | |
*/ | |
public function getToken() | |
{ | |
return $this->nativeSecurityContext->getToken(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment