Skip to content

Instantly share code, notes, and snippets.

@marijn
Last active December 15, 2015 04:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marijn/60a45044a50dd9d96b70 to your computer and use it in GitHub Desktop.
Save marijn/60a45044a50dd9d96b70 to your computer and use it in GitHub Desktop.
Alternative to the default SecurityContextInterface implementation from Symfony
<?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