示例#1
0
 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());
 }
 /**
  * {@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;
 }