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


PHP SecurityContextInterface::getToken方法代码示例

本文整理汇总了PHP中Symfony\Component\Security\Core\SecurityContextInterface::getToken方法的典型用法代码示例。如果您正苦于以下问题:PHP SecurityContextInterface::getToken方法的具体用法?PHP SecurityContextInterface::getToken怎么用?PHP SecurityContextInterface::getToken使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Symfony\Component\Security\Core\SecurityContextInterface的用法示例。


在下文中一共展示了SecurityContextInterface::getToken方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: execute

 /**
  * {@inheritdoc}
  */
 public function execute(BlockContextInterface $blockContext, Response $response = null)
 {
     $criteria = array();
     if ('admin' !== $blockContext->getSetting('mode')) {
         $criteria['customer'] = $this->customerManager->findOneBy(array('user' => $this->securityContext->getToken()->getUser()));
     }
     return $this->renderPrivateResponse($blockContext->getTemplate(), array('context' => $blockContext, 'settings' => $blockContext->getSettings(), 'block' => $blockContext->getBlock(), 'orders' => $this->orderManager->findBy($criteria, array('createdAt' => 'DESC'), $blockContext->getSetting('number'))), $response);
 }
开发者ID:johnulist,项目名称:ecommerce-1,代码行数:11,代码来源:RecentOrdersBlockService.php

示例2: handle

 /**
  * @param GetResponseEvent $event
  */
 public function handle(GetResponseEvent $event)
 {
     $request = $event->getRequest();
     if (!$request->headers->has('cookie')) {
         return;
     }
     if (strstr($request->headers->get('cookie'), 'SimpleSAMLAuthToken') === false) {
         return;
     }
     if (!$request->query->has('csrf-token')) {
         $this->logger->notice('Ssp Firewall: Auth Token cookie but no CSRF Token');
         return;
     }
     $csrfToken = $request->query->getAlnum('csrf-token');
     if (!$this->csrfProvider->isCsrfTokenValid('api', $csrfToken)) {
         $this->logger->notice('Ssp Firewall: Invalid CSRF token for api use: ' . $csrfToken);
         return;
     }
     try {
         $authToken = $this->authenticationManager->authenticate(new SspToken());
         $this->securityContext->setToken($authToken);
     } catch (AuthenticationException $failed) {
         $this->logger->warning('Ssp Firewall: failed:' . $failed->getMessage());
         $token = $this->securityContext->getToken();
         if ($token instanceof SspToken) {
             $this->securityContext->setToken(null);
         }
         return;
     }
 }
开发者ID:baszoetekouw,项目名称:janus,代码行数:33,代码来源:SspListener.php

示例3: getUser

 /**
  * @return \Symfony\Component\Security\Core\User\UserInterface
  */
 private function getUser()
 {
     if (is_null($this->user)) {
         $this->user = $this->securityContext->getToken()->getUser();
     }
     return $this->user;
 }
开发者ID:hyrmedia,项目名称:KunstmaanBundlesCMS,代码行数:10,代码来源:LogPageEventsSubscriber.php

示例4: onKernelRequest

    /**
     * If user is logged-in in legacy_mode (e.g. legacy admin interface),
     * will inject currently logged-in user in the repository.
     *
     * @param GetResponseEvent $event
     */
    public function onKernelRequest( GetResponseEvent $event )
    {
        /** @var \eZ\Publish\Core\MVC\ConfigResolverInterface $configResolver */
        $request = $event->getRequest();
        $session = $request->getSession();
        if (
            $event->getRequestType() !== HttpKernelInterface::MASTER_REQUEST
            || !$this->configResolver->getParameter( 'legacy_mode' )
            || !( $session->isStarted() && $session->has( 'eZUserLoggedInID' ) )
        )
        {
            return;
        }

        try
        {
            $apiUser = $this->repository->getUserService()->loadUser( $session->get( 'eZUserLoggedInID' ) );
            $this->repository->setCurrentUser( $apiUser );

            $token = $this->securityContext->getToken();
            if ( $token instanceof TokenInterface )
            {
                $token->setUser( new User( $apiUser ) );
                $token->setAuthenticated( true );
            }
        }
        catch ( NotFoundException $e )
        {
            // Invalid user ID, the user may have been removed => invalidate the token and the session.
            $this->securityContext->setToken( null );
            $session->invalidate();
        }
    }
开发者ID:ezsystemstraining,项目名称:ez54training,代码行数:39,代码来源:RequestListener.php

示例5: handle

 /**
  * This interface must be implemented by firewall listeners.
  *
  * @param GetResponseEvent $event
  */
 public function handle(GetResponseEvent $event)
 {
     $request = $event->getRequest();
     $apiKey = $request->headers->get('Authorization', $request->query->get('api_key'));
     if (!$apiKey) {
         if (true === $this->forceApiKey) {
             $response = new Response();
             $response->setStatusCode(401);
             $event->setResponse($response);
         }
         return;
     }
     $token = new ApiKeyUserToken();
     $token->setApiKey($apiKey);
     try {
         $authToken = $this->authenticationManager->authenticate($token);
         $this->securityContext->setToken($authToken);
         return;
     } catch (AuthenticationException $failed) {
         $token = $this->securityContext->getToken();
         if ($token instanceof ApiKeyUserToken && $token->getCredentials() == $apiKey) {
             $this->securityContext->setToken(null);
         }
         $message = $failed->getMessage();
     }
     if ($this->isJsonRequest($request)) {
         $response = new JsonResponse(array('error' => $message));
     } else {
         $response = new Response();
         $response->setContent($message);
     }
     $response->setStatusCode(401);
     $event->setResponse($response);
 }
开发者ID:atipso,项目名称:api-key-bundle,代码行数:39,代码来源:ApiKeyListener.php

示例6: onKernelController

 public function onKernelController(FilterControllerEvent $event)
 {
     if (!is_array($controller = $event->getController())) {
         return;
     }
     $className = class_exists('Doctrine\\Common\\Util\\ClassUtils') ? ClassUtils::getClass($controller[0]) : get_class($controller[0]);
     $object = new \ReflectionClass($className);
     $method = $object->getMethod($controller[1]);
     /**
      * @var UserType\UserTypeInterface[] $requiredUserTypes
      */
     $requiredUserTypes = array_merge($this->getConfigurations($this->reader->getClassAnnotations($object)), $this->getConfigurations($this->reader->getMethodAnnotations($method)));
     if (count($requiredUserTypes) === 0) {
         return;
     }
     $token = $this->securityContext->getToken();
     if (null === $token) {
         throw new AccessDeniedException(sprintf("You are not authenticated, a known user type is required for access."));
     }
     $user = $token->getUser();
     foreach ($requiredUserTypes as $userType) {
         $userClass = $userType->getUserClass();
         if (!interface_exists($userClass) && !class_exists($userClass)) {
             throw new RuntimeException(sprintf("The user type class '%s' does not exist", $userClass));
         }
         if (!$user instanceof $userClass) {
             throw new AccessDeniedException(sprintf("You do not have the required user type. A user type of '%s' is required.", $userClass));
         }
         unset($userType, $userClass);
     }
 }
开发者ID:viettut,项目名称:todo,代码行数:31,代码来源:UserTypeSecurityListener.php

示例7: handle

 /**
  * {@inheritdoc}
  */
 public function handle(GetResponseEvent $event)
 {
     $request = $event->getRequest();
     if ($this->securityContext->getToken() !== null) {
         return;
     }
     if ($request->getRequestUri() == '/app_dev.php/api/login' || $request->getRequestUri() == '/api/login') {
         return;
     }
     //Try to reach token from HTTP headers
     if ($request->headers->has('X-Auth-Token')) {
         $tokenId = $request->headers->get('X-Auth-Token');
     } else {
         $tokenId = $request->get('token');
     }
     //by token
     if (isset($tokenId)) {
         $user = $this->userProvider->findUserByToken($tokenId);
         if (!$user) {
             throw new BadCredentialsException();
         }
         try {
             $token = new ApiToken([], $this->providerId, $this->key);
             $token->setUser($user);
             $authenticatedToken = $this->authenticationManager->authenticate($token);
             $this->securityContext->setToken($authenticatedToken);
         } catch (AuthenticationException $e) {
             //log something
         }
     }
 }
开发者ID:Exanrus,项目名称:crm-bundle,代码行数:34,代码来源:ApiListener.php

示例8: isVisible

 public function isVisible()
 {
     if ($this->securityContext === null) {
         return true;
     }
     return !$this->securityContext->getToken();
 }
开发者ID:mikegibson,项目名称:sentient,代码行数:7,代码来源:LoginAction.php

示例9: onResponse

 /**
  * Checking request and response and decide whether we need a redirect
  *
  * @param FilterResponseEvent $event
  */
 public function onResponse(FilterResponseEvent $event)
 {
     $request = $event->getRequest();
     $response = $event->getResponse();
     if ($request->get(self::HASH_NAVIGATION_HEADER) || $request->headers->get(self::HASH_NAVIGATION_HEADER)) {
         $location = '';
         $isFullRedirect = false;
         if ($response->isRedirect()) {
             $location = $response->headers->get('location');
             if ($request->attributes->get('_fullRedirect') || !is_object($this->security->getToken())) {
                 $isFullRedirect = true;
             }
         }
         if ($response->isNotFound() || $response->getStatusCode() == 503 && !$this->isDebug) {
             $location = $request->getUri();
             $isFullRedirect = true;
         }
         if ($location) {
             $response = $this->templating->renderResponse('OroNavigationBundle:HashNav:redirect.html.twig', array('full_redirect' => $isFullRedirect, 'location' => $location));
         }
         // disable cache for ajax navigation pages and change content type to json
         $response->headers->set('Content-Type', 'application/json');
         $response->headers->addCacheControlDirective('no-cache', true);
         $response->headers->addCacheControlDirective('max-age', 0);
         $response->headers->addCacheControlDirective('must-revalidate', true);
         $response->headers->addCacheControlDirective('no-store', true);
         $event->setResponse($response);
     }
 }
开发者ID:ramunasd,项目名称:platform,代码行数:34,代码来源:ResponseHashnavListener.php

示例10: blame

 /**
  * Assigns the Security token's user to the vote.
  *
  * @param  VoteEvent $vote
  * @return void
  */
 public function blame(VoteEvent $event)
 {
     $vote = $event->getVote();
     if (null === $this->securityContext) {
         if ($this->logger) {
             $this->logger->debug("Vote Blamer did not receive the security.context service.");
         }
         return;
     }
     if (!$vote instanceof SignedVoteInterface) {
         if ($this->logger) {
             $this->logger->debug("Vote does not implement SignedVoteInterface, skipping");
         }
         return;
     }
     if (null === $this->securityContext->getToken()) {
         if ($this->logger) {
             $this->logger->debug("There is no firewall configured. We cant get a user.");
         }
         return;
     }
     if ($this->securityContext->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
         $vote->setVoter($this->securityContext->getToken()->getUser());
     }
 }
开发者ID:saberyounis,项目名称:Sonata-Project,代码行数:31,代码来源:VoteBlamerListener.php

示例11: process

 /**
  * Process form
  *
  * @param AccountUser $accountUser
  * @return bool True on successful processing, false otherwise
  */
 public function process(AccountUser $accountUser)
 {
     if (in_array($this->request->getMethod(), ['POST', 'PUT'], true)) {
         $this->form->submit($this->request);
         if ($this->form->isValid()) {
             if (!$accountUser->getId()) {
                 if ($this->form->get('passwordGenerate')->getData()) {
                     $generatedPassword = $this->userManager->generatePassword(10);
                     $accountUser->setPlainPassword($generatedPassword);
                 }
                 if ($this->form->get('sendEmail')->getData()) {
                     $this->userManager->sendWelcomeEmail($accountUser);
                 }
             }
             $token = $this->securityContext->getToken();
             if ($token instanceof OrganizationContextTokenInterface) {
                 $organization = $token->getOrganizationContext();
                 $accountUser->setOrganization($organization)->addOrganization($organization);
             }
             $this->userManager->updateUser($accountUser);
             return true;
         }
     }
     return false;
 }
开发者ID:hafeez3000,项目名称:orocommerce,代码行数:31,代码来源:AccountUserHandler.php

示例12: getCustomer

 /**
  * Gets customer based on currently logged user.
  *
  * @return CustomerInterface|null
  */
 public function getCustomer()
 {
     if ($this->securityContext->getToken() && $this->securityContext->isGranted('IS_AUTHENTICATED_REMEMBERED') && $this->securityContext->getToken()->getUser() instanceof UserInterface) {
         return $this->securityContext->getToken()->getUser()->getCustomer();
     }
     return null;
 }
开发者ID:aleherse,项目名称:Sylius,代码行数:12,代码来源:CustomerContext.php

示例13: onCoreRequest

 /**
  * @param GetResponseEvent $event
  */
 public function onCoreRequest(GetResponseEvent $event)
 {
     if (HttpKernel::MASTER_REQUEST != $event->getRequestType()) {
         return;
     }
     $token = $this->securityContext->getToken();
     if (!$token) {
         return;
     }
     if (!$token instanceof UsernamePasswordToken) {
         return;
     }
     $key = $this->helper->getSessionKey($this->securityContext->getToken());
     $request = $event->getRequest();
     $session = $event->getRequest()->getSession();
     $user = $this->securityContext->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:lordrhodos,项目名称:SonataUserBundle,代码行数:35,代码来源:RequestListener.php

示例14: get

 /**
  * Get the customer.
  *
  * @throws \RuntimeException
  *
  * @return \Sonata\Component\Customer\CustomerInterface
  */
 public function get()
 {
     $customer = null;
     $user = null;
     if (true === $this->securityContext->isGranted('IS_AUTHENTICATED_FULLY')) {
         // user is authenticated
         $user = $this->securityContext->getToken()->getUser();
         if (!$user instanceof UserInterface) {
             throw new \RuntimeException('User must be an instance of FOS\\UserBundle\\Model\\UserInterface');
         }
         $customer = $this->customerManager->findOneBy(array('user' => $user->getId()));
     }
     if (!$customer) {
         $basket = $this->getBasket();
         if ($basket && $basket->getCustomer()) {
             $customer = $basket->getCustomer();
         }
     }
     if (!$customer) {
         $customer = $this->customerManager->create();
     }
     if (!$customer->getLocale()) {
         $customer->setLocale($this->locale);
     }
     if ($user && $customer) {
         $customer->setUser($user);
     }
     return $customer;
 }
开发者ID:kinkinweb,项目名称:lhvb,代码行数:36,代码来源:CustomerSelector.php

示例15: 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->securityContext->setToken($authToken);
         return;
     } catch (AuthenticationException $failed) {
         $token = $this->securityContext->getToken();
         if ($token instanceof ApiKeyUserToken && $token->getCredentials() == $apiKey) {
             $this->securityContext->setToken(null);
         }
         $message = $failed->getMessage();
     }
     $response = new Response();
     $response->setContent($message);
     $response->setStatusCode(403);
     $event->setResponse($response);
 }
开发者ID:tuandv2611,项目名称:api-key-bundle,代码行数:33,代码来源:ApiKeyListener.php


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