當前位置: 首頁>>代碼示例>>PHP>>正文


PHP SecurityContext::setToken方法代碼示例

本文整理匯總了PHP中Symfony\Component\Security\Core\SecurityContext::setToken方法的典型用法代碼示例。如果您正苦於以下問題:PHP SecurityContext::setToken方法的具體用法?PHP SecurityContext::setToken怎麽用?PHP SecurityContext::setToken使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Symfony\Component\Security\Core\SecurityContext的用法示例。


在下文中一共展示了SecurityContext::setToken方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: register

 public function register(User $user)
 {
     $user->setSalt(md5(time()));
     $password = $this->securityEncoderFactory->getEncoder($user)->encodePassword($user->getPassword(), $user->getSalt());
     $user->setPassword($password);
     $this->em->persist($user);
     $this->em->flush();
     $token = new UsernamePasswordToken($user, $user->getPassword(), 'app', $user->getRoles());
     $this->securityContext->setToken($token);
 }
開發者ID:AeonRush,項目名稱:demoblog,代碼行數:10,代碼來源:UserManager.php

示例2: closeAccount

 public function closeAccount(Response $response)
 {
     $user = $this->securityContext->getToken()->getUser();
     $user->setEnabled(false);
     $this->userManager->updateUser($user);
     $cookieHandler = new CookieClearingLogoutHandler($this->request->cookies->all());
     $cookieHandler->logout($this->request, $response, $this->securityContext->getToken());
     $sessionHandler = new SessionLogoutHandler();
     $sessionHandler->logout($this->request, $response, $this->securityContext->getToken());
     $this->securityContext->setToken(null);
 }
開發者ID:hotfics,項目名稱:lichess-old,代碼行數:11,代碼來源:AccountCloser.php

示例3: testGetSetToken

 public function testGetSetToken()
 {
     $context = new SecurityContext($this->getMock('Symfony\\Component\\Security\\Core\\Authentication\\AuthenticationManagerInterface'), $this->getMock('Symfony\\Component\\Security\\Core\\Authorization\\AccessDecisionManagerInterface'));
     $this->assertNull($context->getToken());
     $context->setToken($token = $this->getMock('Symfony\\Component\\Security\\Core\\Authentication\\Token\\TokenInterface'));
     $this->assertSame($token, $context->getToken());
 }
開發者ID:nickaggarwal,項目名稱:sample-symfony2,代碼行數:7,代碼來源:SecurityContextTest.php

示例4: refuseRegistration

 /**
  * @param $entityManager
  * @param $user
  */
 private function refuseRegistration($entityManager, $user)
 {
     $entityManager->remove($user);
     $entityManager->flush();
     $this->securityContext->setToken(null);
     return $this->redirect($this->generateUrl('base_publichome'));
 }
開發者ID:PhilippeGeek,項目名稱:PHPM,代碼行數:11,代碼來源:OAuthController.php

示例5: loginUser

 /**
  * Log in user
  *
  * @param Newscoop\Entity\User $user
  * @param string               $providerKey
  *
  * @return UsernamePasswordToken
  */
 public function loginUser(User $user, $providerKey)
 {
     $roles = $user->getRoles();
     $token = new UsernamePasswordToken($user, null, $providerKey, $roles);
     $this->security->setToken($token);
     return $token;
 }
開發者ID:sourcefabric,項目名稱:newscoop,代碼行數:15,代碼來源:UserService.php

示例6: createSecurityContext

 protected function createSecurityContext($granted = false)
 {
     $authManager = $this->getMock('Symfony\\Component\\Security\\Core\\Authentication\\AuthenticationManagerInterface');
     $decisionManager = $this->getMock('Symfony\\Component\\Security\\Core\\Authorization\\AccessDecisionManagerInterface');
     $decisionManager->expects($this->any())->method('decide')->will($this->returnValue($granted));
     $context = new SecurityContext($authManager, $decisionManager, false);
     $context->setToken($token = $this->getMock('Symfony\\Component\\Security\\Core\\Authentication\\Token\\TokenInterface'));
     $token->expects($this->any())->method('isAuthenticated')->will($this->returnValue(true));
     return $context;
 }
開發者ID:jaivac,項目名稱:SmartyBundle,代碼行數:10,代碼來源:SecurityExtensionTest.php

示例7: onKernelRequest

 /**
  * Called on kernel.request event. Find current user.
  */
 public function onKernelRequest(GetResponseEvent $event)
 {
     // User already found ? (Used by tests)
     if ($this->securityContext->getToken() !== null) {
         return;
     }
     // Cookie not found
     if ($event->getRequest()->cookies->has(md5('etuutt-session-cookie-name'))) {
         $cookie = $event->getRequest()->cookies->get(md5('etuutt-session-cookie-name'));
         /** @var EntityManager $em */
         $em = $this->doctrine->getManager();
         // Find session
         /** @var \Etu\Core\UserBundle\Entity\Session $session */
         $session = $em->getRepository('EtuUserBundle:Session')->findOneBy(['token' => $cookie]);
         if ($session && $session->getExpireAt() > new \DateTime()) {
             if ($session->getEntityType() == \Etu\Core\UserBundle\Entity\Session::TYPE_ORGA) {
                 $this->session->set('user', null);
                 $this->session->set('user_data', null);
                 $orga = $em->getRepository('EtuUserBundle:Organization')->find($session->getEntityId());
                 $this->session->set('orga', $orga);
                 $this->securityContext->setToken(new OrgaToken($orga));
                 return;
             } elseif ($session->getEntityType() == \Etu\Core\UserBundle\Entity\Session::TYPE_USER) {
                 $this->session->set('orga', null);
                 $user = $em->getRepository('EtuUserBundle:User')->find($session->getEntityId());
                 $this->session->set('user', $user->getId());
                 $this->session->set('user_data', $user);
                 $this->securityContext->setToken(new UserToken($user));
                 return;
             }
         }
     }
     $this->session->set('user', null);
     $this->session->set('orga', null);
     $this->securityContext->setToken(new AnonymousToken());
 }
開發者ID:ChrisdAutume,項目名稱:EtuUTT,代碼行數:39,代碼來源:KernelListener.php

示例8: testGetUser

    public function testGetUser()
    {
        $token = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface');
        $token->expects($this->once())
            ->method('getUser')
            ->will($this->returnValue('foo'));

        $context = new SecurityContext(
            $this->getMock('Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface'),
            $this->getMock('Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface')
        );

        $this->assertNull($context->getUser(), '->getUser() returns null when there is no token');

        $context->setToken($token);
        $this->assertEquals('foo', $context->getUser(), '->getUser() return the token user');
    }
開發者ID:usefulthink,項目名稱:symfony,代碼行數:17,代碼來源:SecurityContextTest.php

示例9: getMockSecurityContext

 protected function getMockSecurityContext()
 {
     $authManager = $this->getMock('Symfony\\Component\\Security\\Core\\Authentication\\AuthenticationManagerInterface');
     $decisionManager = $this->getMock('Symfony\\Component\\Security\\Core\\Authorization\\AccessDecisionManagerInterface');
     $context = new SecurityContext($authManager, $decisionManager);
     $context->setToken($token = $this->getMock('Symfony\\Component\\Security\\Core\\Authentication\\Token\\TokenInterface'));
     return $context;
 }
開發者ID:absalonvaldes,項目名稱:FreeAgentWorkflowBundle,代碼行數:8,代碼來源:TestCase.php

示例10: undoImpersonation

 /**
  * Switches the security context to the previous security token
  *
  * @param TokenInterface|null $originalToken
  */
 protected function undoImpersonation(TokenInterface $originalToken = null)
 {
     if ($originalToken) {
         $this->securityContext->setToken($originalToken);
     }
 }
開發者ID:Maksold,項目名稱:platform,代碼行數:11,代碼來源:UserPermissionApiEntityManager.php

示例11: doLogout

 /**
  * Remove current security token
  */
 public function doLogout()
 {
     $this->token_storage->setToken(null);
 }
開發者ID:bravo3,項目名稱:orm-bundle,代碼行數:7,代碼來源:OrmSecurityManager.php

示例12: setSecurityContext

 /**
  * @param User $user
  */
 protected function setSecurityContext(User $user)
 {
     $token = new UsernamePasswordOrganizationToken($user, $user->getUsername(), 'main', $this->organization);
     $this->securityContext->setToken($token);
 }
開發者ID:antrampa,項目名稱:crm,代碼行數:8,代碼來源:LoadUsersCalendarData.php


注:本文中的Symfony\Component\Security\Core\SecurityContext::setToken方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。