当前位置: 首页>>代码示例>>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;未经允许,请勿转载。