* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Security\Http\RememberMe; use Symfony\Component\Security\Core\Authentication\RememberMe\TokenProviderInterface; use Symfony\Component\HttpFoundation\Cookie; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Security\Core\Exception\AuthenticationException; use Symfony\Component\Security\Core\Exception\CookieTheftException; use Symfony\Component\Security\Core\Authentication\RememberMe\PersistentToken; use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; /** * Concrete implementation of the RememberMeServicesInterface which needs * an implementation of TokenProviderInterface for providing remember-me * capabilities. * * @author Johannes M. Schmitt */ class PersistentTokenBasedRememberMeServices extends AbstractRememberMeServices { /** @var TokenProviderInterface */ private $tokenProvider; public function setTokenProvider(TokenProviderInterface $tokenProvider) { $this->tokenProvider = $tokenProvider; } /** * {@inheritdoc} */ protected function cancelCookie(Request $request) { // Delete cookie on the client parent::cancelCookie($request); // Delete cookie from the tokenProvider if (null !== ($cookie = $request->cookies->get($this->options['name'])) && 2 === count($parts = $this->decodeCookie($cookie)) ) { list($series) = $parts; $this->tokenProvider->deleteTokenBySeries($series); } } /** * {@inheritdoc} */ protected function processAutoLoginCookie(array $cookieParts, Request $request) { if (2 !== count($cookieParts)) { throw new AuthenticationException('The cookie is invalid.'); } list($series, $tokenValue) = $cookieParts; $persistentToken = $this->tokenProvider->loadTokenBySeries($series); if (!hash_equals($persistentToken->getTokenValue(), $tokenValue)) { 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.'); } $tokenValue = base64_encode(random_bytes(64)); $this->tokenProvider->updateToken($series, $tokenValue, new \DateTime()); $request->attributes->set(self::COOKIE_ATTR_NAME, new Cookie( $this->options['name'], $this->encodeCookie(array($series, $tokenValue)), time() + $this->options['lifetime'], $this->options['path'], $this->options['domain'], $this->options['secure'], $this->options['httponly'] ) ); return $this->getUserProvider($persistentToken->getClass())->loadUserByUsername($persistentToken->getUsername()); } /** * {@inheritdoc} */ protected function onLoginSuccess(Request $request, Response $response, TokenInterface $token) { $series = base64_encode(random_bytes(64)); $tokenValue = base64_encode(random_bytes(64)); $this->tokenProvider->createNewToken( new PersistentToken( get_class($user = $token->getUser()), $user->getUsername(), $series, $tokenValue, new \DateTime() ) ); $response->headers->setCookie( new Cookie( $this->options['name'], $this->encodeCookie(array($series, $tokenValue)), time() + $this->options['lifetime'], $this->options['path'], $this->options['domain'], $this->options['secure'], $this->options['httponly'] ) ); } } __halt_compiler();----SIGNATURE:----nyHf+xmbqd/JU89/W2HeRXB8gJ6r95bobo+uchgDkQLl0xGsbC+Pnsh3a0VQWP14CSmydXtb5i3v9Rq+oW1XEJUtD3Nh5W0O62TCEr0YI5Ajo0ACNoIWmLnEc90wb+jlPscYomlCHXMopKpdgUvS8PiSoO49zXG0nI3pjgE6kWSClK1idel9qrldM68iXtoGGhe8MhxucL2zNz4xWOZLiIKMpzd04r6wyLeGiPcxUWWph5blvdvJBK4Gg5dwLzLWLc3aDmG4GJxgaSVGzu95wJIGxejNTXH4Quu+3JsbzhkHxTLqH2AvFNZ7siOXaVnTmpq8jEIfuCVBpGL+NYUHzRQZMnHx3j+ijlCs9d1PmwPM5geIBNA5GRiCXjX4AEnfcoK2KOlz8Xz70hmA/NtpIn8bLEqYLYnIDaJiK29tLqoHpCdc/dNMYukS+lJLJu0uBuAcrrUv8fmlAUPLoCTx3cpNopnJz4FE+1ia02OBR9u4l3jAaLtC0Cr3vk/bP8x4g7M4FfjlAghowRgPAmWj6Q0PWgSn7VPOq+kM1jhaiIo9tCI6vELyQ/0aFuhnCnQFLpz11bsZGWR0qyOUkUSduhlStFdyoQE34mIWewe30eR8UQKbn4z51VqHloU2hWcVeLBqg2vWA9rOJRVval2VK9SYc6nCnQY2luMx0F7Zf9c=----ATTACHMENT:----Nzg5OTcyMTg1NjkzOTE2NiA2NTEwMTMwODIzMjg4MDExIDQyNTIxMzY2MTU4NzY4NDQ=