当前位置: 首页>>代码示例>>PHP>>正文


PHP TokenStorageInterface::getToken方法代码示例

本文整理汇总了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();
 }
开发者ID:phppro,项目名称:supervision,代码行数:12,代码来源:SupervisionService.php

示例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;
                 }
             }
         }
     }
 }
开发者ID:spomky-labs,项目名称:oauth2-server-bundle,代码行数:27,代码来源:AnnotationDriver.php

示例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;
 }
开发者ID:ojs,项目名称:ojs,代码行数:14,代码来源:AbstractJournalItemMailer.php

示例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;
 }
开发者ID:stopfstedt,项目名称:ilios,代码行数:12,代码来源:Logger.php

示例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;
 }
开发者ID:BranchBit,项目名称:KunstmaanBundlesCMS,代码行数:10,代码来源:LogPageEventsSubscriber.php

示例6: getUserFromTokenStorage

 private function getUserFromTokenStorage()
 {
     if (($token = $this->tokenStorage->getToken()) !== null) {
         return $token->getUser();
     }
     throw new \RuntimeException('I don\'t have a token');
 }
开发者ID:WeCamp,项目名称:ihaveanidea,代码行数:7,代码来源:Idea.php

示例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;
 }
开发者ID:abdeldayem,项目名称:pim-community-dev,代码行数:7,代码来源:ResponseHistoryListener.php

示例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;
 }
开发者ID:hostnet,项目名称:entity-tracker-bundle,代码行数:10,代码来源:DefaultBlamableProvider.php

示例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;
 }
开发者ID:harpcio,项目名称:FileUploaderBundle,代码行数:31,代码来源:FileOwnerValidator.php

示例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();
     }
 }
开发者ID:yjqg6666,项目名称:packagist,代码行数:11,代码来源:MenuBuilder.php

示例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)));
 }
开发者ID:albegali,项目名称:SonataUserBundle,代码行数:35,代码来源:RequestListener.php

示例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);
 }
开发者ID:feriatos,项目名称:api-key-bundle,代码行数:33,代码来源:ApiKeyListener.php

示例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();
     }
 }
开发者ID:igui-br,项目名称:packagist,代码行数:11,代码来源:MenuBuilder.php

示例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');
     }
 }
开发者ID:adam-paterson,项目名称:orocommerce,代码行数:10,代码来源:FrontendProductSelectExtension.php

示例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;
 }
开发者ID:woei66,项目名称:platform,代码行数:40,代码来源:ActivityContextApiEntityManager.php


注:本文中的Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface::getToken方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。