本文整理汇总了PHP中Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface::getToken方法的典型用法代码示例。如果您正苦于以下问题:PHP TokenStorageInterface::getToken方法的具体用法?PHP TokenStorageInterface::getToken怎么用?PHP TokenStorageInterface::getToken使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface
的用法示例。
在下文中一共展示了TokenStorageInterface::getToken方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getIdentity
/**
* Returns the current logged in user identity.
*
* @return TokenInterface|null
*/
public function getIdentity()
{
if (null == $this->tokenStorage) {
return null;
}
return $this->tokenStorage->getToken();
}
示例2: onKernelController
public function onKernelController(FilterControllerEvent $event)
{
if (!is_array($controller = $event->getController())) {
return;
}
$object = new \ReflectionObject($controller[0]);
$method = $object->getMethod($controller[1]);
$classConfigurations = $this->reader->getClassAnnotations($object);
$methodConfigurations = $this->reader->getMethodAnnotations($method);
foreach (array_merge($classConfigurations, $methodConfigurations) as $configuration) {
if ($configuration instanceof OAuth2) {
$token = $this->token_storage->getToken();
// If no access token is found by the firewall, then returns an authentication error
if (!$token instanceof OAuth2Token) {
$this->createAuthenticationException($event, 'OAuth2 authentication required');
return;
}
foreach ($this->getCheckers() as $checker) {
$result = $checker->check($token, $configuration);
if (null !== $result) {
$this->createAccessDeniedException($event, $result);
return;
}
}
}
}
}
示例3: __construct
/**
* AbstractJournalItemMailer constructor.
* @param OjsMailer $ojsMailer
* @param RegistryInterface $registry
* @param TokenStorageInterface $tokenStorage
* @param RouterInterface $router
*/
public function __construct(OjsMailer $ojsMailer, RegistryInterface $registry, TokenStorageInterface $tokenStorage, RouterInterface $router)
{
$this->ojsMailer = $ojsMailer;
$this->em = $registry->getManager();
$this->user = $tokenStorage->getToken() ? $tokenStorage->getToken()->getUser() : null;
$this->router = $router;
}
示例4: __construct
/**
* Set the username from injected security context
* @param TokenStorageInterface $securityTokenStorage
* @param AuditLogManager $auditLogManager
*/
public function __construct(TokenStorageInterface $securityTokenStorage, AuditLogManager $auditLogManager)
{
if (null !== $securityTokenStorage && null !== $securityTokenStorage->getToken()) {
$this->user = $securityTokenStorage->getToken()->getUser();
}
$this->manager = $auditLogManager;
}
示例5: getUser
/**
* @return \Symfony\Component\Security\Core\User\UserInterface
*/
private function getUser()
{
if (is_null($this->user)) {
$this->user = $this->tokenStorage->getToken()->getUser();
}
return $this->user;
}
示例6: getUserFromTokenStorage
private function getUserFromTokenStorage()
{
if (($token = $this->tokenStorage->getToken()) !== null) {
return $token->getUser();
}
throw new \RuntimeException('I don\'t have a token');
}
示例7: __construct
public function __construct(ItemFactory $navigationItemFactory, TokenStorageInterface $tokenStorage, EntityManager $entityManager, TitleServiceInterface $titleService)
{
$this->navItemFactory = $navigationItemFactory;
$this->user = !$tokenStorage->getToken() || is_string($tokenStorage->getToken()->getUser()) ? null : $tokenStorage->getToken()->getUser();
$this->em = $entityManager;
$this->titleService = $titleService;
}
示例8: getUpdatedBy
/**
* @see \Hostnet\Component\EntityBlamable\Provider\BlamableProviderInterface::getUpdatedBy()
*/
public function getUpdatedBy()
{
if (($token = $this->token_storage->getToken()) instanceof TokenInterface) {
return $token->getUsername();
}
return $this->username;
}
示例9: validate
/**
* Validate that the submitted file is owned by the authenticated user
*
* @param string $value
* @param Constraint $constraint
*/
public function validate($value, Constraint $constraint)
{
$fileHistory = $this->em->getRepository('JbFileUploaderBundle:FileHistory')->find($value);
if (!$fileHistory) {
return;
}
// No userid associated with file. Every one can use it.
if (!$fileHistory->getUserId()) {
return;
}
// No token. Violation as there is a user id associate with file.
$token = $this->tokenStorage->getToken();
if (!$token) {
return $this->createViolation($value, $constraint);
}
// No user. Violation as there is a user id associate with file.
$user = $token->getUser();
if (!$user) {
return $this->createViolation($value, $constraint);
}
if ($user->getId() !== $fileHistory->getUserId()) {
return $this->createViolation($value, $constraint);
}
return;
}
示例10: __construct
/**
* @param FactoryInterface $factory
* @param TokenStorageInterface $securityContext
*/
public function __construct(FactoryInterface $factory, TokenStorageInterface $securityContext)
{
$this->factory = $factory;
if ($securityContext->getToken() && $securityContext->getToken()->getUser()) {
$this->username = $securityContext->getToken()->getUser()->getUsername();
}
}
示例11: onCoreRequest
/**
* @param GetResponseEvent $event
*/
public function onCoreRequest(GetResponseEvent $event)
{
if (HttpKernel::MASTER_REQUEST != $event->getRequestType()) {
return;
}
$token = $this->tokenStorage->getToken();
if (!$token) {
return;
}
if (!$token instanceof UsernamePasswordToken) {
return;
}
$key = $this->helper->getSessionKey($this->tokenStorage->getToken());
$request = $event->getRequest();
$session = $event->getRequest()->getSession();
$user = $this->tokenStorage->getToken()->getUser();
if (!$session->has($key)) {
return;
}
if ($session->get($key) === true) {
return;
}
$state = 'init';
if ($request->getMethod() == 'POST') {
if ($this->helper->checkCode($user, $request->get('_code')) == true) {
$session->set($key, true);
return;
}
$state = 'error';
}
$event->setResponse($this->templating->renderResponse('SonataUserBundle:Admin:Security/two_step_form.html.twig', array('state' => $state)));
}
示例12: handle
/**
* This interface must be implemented by firewall listeners.
*
* @param GetResponseEvent $event
*/
public function handle(GetResponseEvent $event)
{
$request = $event->getRequest();
if (!$this->keyExtractor->hasKey($request)) {
$response = new Response();
$response->setStatusCode(401);
$event->setResponse($response);
return;
}
$apiKey = $this->keyExtractor->extractKey($request);
$token = new ApiKeyUserToken();
$token->setApiKey($apiKey);
try {
$authToken = $this->authenticationManager->authenticate($token);
$this->tokenStorage->setToken($authToken);
return;
} catch (AuthenticationException $failed) {
$token = $this->tokenStorage->getToken();
if ($token instanceof ApiKeyUserToken && $token->getCredentials() == $apiKey) {
$this->tokenStorage->setToken(null);
}
$message = $failed->getMessage();
}
$response = new Response();
$response->setContent($message);
$response->setStatusCode(403);
$event->setResponse($response);
}
示例13: __construct
/**
* @param FactoryInterface $factory
* @param TokenStorageInterface $tokenStorage
*/
public function __construct(FactoryInterface $factory, TokenStorageInterface $tokenStorage)
{
$this->factory = $factory;
if ($tokenStorage->getToken() && $tokenStorage->getToken()->getUser()) {
$this->username = $tokenStorage->getToken()->getUser()->getUsername();
}
}
示例14: configureOptions
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$token = $this->tokenStorage->getToken();
if ($token && $token->getUser() instanceof AccountUser) {
$resolver->setDefault('grid_name', 'products-select-grid-frontend');
}
}
示例15: getActivityContext
/**
* Returns the context for the given activity class and id
*
* @param string $class The FQCN of the activity entity
* @param $id
*
* @return array
*/
public function getActivityContext($class, $id)
{
$currentUser = $this->securityTokenStorage->getToken()->getUser();
$userClass = ClassUtils::getClass($currentUser);
$entity = $this->doctrineHelper->getEntity($class, $id);
$result = [];
if (!$entity || !$entity instanceof ActivityInterface) {
return $result;
}
$targets = $entity->getActivityTargetEntities();
$entityProvider = $this->configManager->getProvider('entity');
foreach ($targets as $target) {
$targetClass = ClassUtils::getClass($target);
$targetId = $target->getId();
if ($userClass === $targetClass && $currentUser->getId() === $targetId) {
continue;
}
$item = [];
$config = $entityProvider->getConfig($targetClass);
$safeClassName = $this->entityClassNameHelper->getUrlSafeClassName($targetClass);
$item = $this->prepareItemTitle($item, $targetClass, $target, $targetId);
$item['activityClassAlias'] = $this->entityAliasResolver->getPluralAlias($class);
$item['entityId'] = $id;
$item['targetId'] = $targetId;
$item['targetClassName'] = $safeClassName;
$item['icon'] = $config->get('icon');
$item['link'] = $this->getContextLink($targetClass, $targetId);
$item = $this->dispatchContextTitle($item, $targetClass);
$result[] = $item;
}
return $result;
}