public function testPersistentToken()
 {
     $token = new RememberMeToken($this->getUser(), 'fookey', 'foo');
     $persistentToken = $this->getMock('Symfony\\Component\\Security\\Core\\Authentication\\RememberMe\\PersistentTokenInterface');
     $this->assertNull($token->getPersistentToken());
     $token->setPersistentToken($persistentToken);
     $this->assertSame($persistentToken, $token->getPersistentToken());
 }
 public function authenticate(TokenInterface $token)
 {
     if (!$this->supports($token)) {
         return;
     }
     if ($this->key !== $token->getKey()) {
         throw new BadCredentialsException('The presented key does not match.');
     }
     $user = $token->getUser();
     $this->userChecker->checkPostAuth($user);
     $authenticatedToken = new RememberMeToken($user, $this->providerKey, $this->key);
     $authenticatedToken->setAttributes($token->getAttributes());
     return $authenticatedToken;
 }
 /**
  * {@inheritDoc}
  */
 protected function processAutoLoginCookie(array $cookieParts, Request $request)
 {
     if (count($cookieParts) !== 2) {
         throw new AuthenticationException('The cookie is invalid.');
     }
     list($series, $tokenValue) = $cookieParts;
     $persistentToken = $this->tokenProvider->loadTokenBySeries($series);
     if ($persistentToken->getTokenValue() !== $tokenValue) {
         $this->tokenProvider->deleteTokenBySeries($series);
         throw new CookieTheftException('This token was already used. The account is possibly compromised.');
     }
     if ($persistentToken->getLastUsed()->getTimestamp() + $this->options['lifetime'] < time()) {
         throw new AuthenticationException('The cookie has expired.');
     }
     $user = $this->getUserProvider($persistentToken->getClass())->loadUserByUsername($persistentToken->getUsername());
     $authenticationToken = new RememberMeToken($user, $this->providerKey, $this->key);
     $authenticationToken->setPersistentToken($persistentToken);
     return $authenticationToken;
 }
 public function testConstructor()
 {
     $user = $this->getUser();
     $token = new RememberMeToken($user, 'fookey', 'foo');
     $this->assertEquals('fookey', $token->getProviderKey());
     $this->assertEquals('foo', $token->getKey());
     $this->assertEquals(array(new Role('ROLE_FOO')), $token->getRoles());
     $this->assertSame($user, $token->getUser());
     $this->assertTrue($token->isAuthenticated());
 }
 /**
  * {@inheritdoc}
  */
 public function unserialize($serialized)
 {
     list($organizationData, $parentStr) = explode('||', $serialized);
     $this->organizationContext = unserialize($organizationData);
     parent::unserialize($parentStr);
 }