8000 Delete cookies from the TokenProvider that is no longer in use by TerjeBr · Pull Request #6055 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Delete cookies from the TokenProvider that is no longer in use #6055

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 24, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@ final public function loginFail(Request $request)
*/
final public function loginSuccess(Request $request, Response $response, TokenInterface $token)
{
// Make sure any old remember-me cookies are cancelled
$this->cancelCookie($request);

if (!$token->getUser() instanceof UserInterface) {
if (null !== $this->logger) {
$this->logger->debug('Remember-me ignores token since it does not contain a UserInterface implementation.');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,12 @@ public function setTokenProvider(TokenProviderInterface $tokenProvider)
/**
* {@inheritDoc}
*/
public function logout(Request $request, Response $response, TokenInterface $token)
protected function cancelCookie(Request $request)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removing the logout method is not BC.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logout method is still inherited from the parent. It is not removed.

{
parent::logout($request, $response, $token);
// Delete cookie on the client
parent::cancelCookie($request);

// Delete cookie from the tokenProvider
if (null !== ($cookie = $request->cookies->get($this->options['name']))
&& count($parts = $this->decodeCookie($cookie)) === 2
) {
Expand All @@ -88,8 +90,6 @@ protected function processAutoLoginCookie(array $cookieParts, Request $request)
$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.');
}

Expand Down Expand Up @@ -133,6 +133,7 @@ protected function onLoginSuccess(Request $request, Response $response, TokenInt
)
);

$request->attributes->remove(self::COOKIE_ATTR_NAME);
$response->headers->setCookie(
new Cookie(
$this->options['name'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function testGetKey()

public function testAutoLoginReturnsNullWhenNoCookie()
{
$service = $this->getService(null, array('name' => 'foo'));
$service = $this->getService(null, array('name' => 'foo', 'path' => null, 'domain' => null));

$this->assertNull($service->autoLogin(new Request()));
}
Expand All @@ -49,7 +49,7 @@ public function testAutoLoginReturnsNullWhenNoCookie()
*/
public function testAutoLoginThrowsExceptionWhenImplementationDoesNotReturnUserInterface()
{
$service = $this->getService(null, array('name' => 'foo'));
$service = $this->getService(null, array('name' => 'foo', 'path' => null, 'domain' => null));
$request = new Request;
$request->cookies->set('foo', 'foo');

Expand All @@ -64,7 +64,7 @@ public function testAutoLoginThrowsExceptionWhenImplementationDoesNotReturnUserI

public function testAutoLogin()
{
$service = $this->getService(null, array('name' => 'foo'));
$service = $this->getService(null, array('name' => 'foo', 'path' => null, 'domain' => null));
$request = new Request();
$request->cookies->set('foo', 'foo');

Expand Down Expand Up @@ -112,7 +112,7 @@ public function testLoginFail()

public function testLoginSuccessIsNotProcessedWhenTokenDoesNotContainUserInterfaceImplementation()
{
$service = $this->getService(null, array('name' => 'foo', 'always_remember_me' => true));
$service = $this->getService(null, array('name' => 'foo', 'always_remember_me' => true, 'path' => null, 'domain' => null));
$request = new Request;
$response = new Response;
$account = $this->getMock('Symfony\Component\Security\Core\User\UserInterface');
Expand All @@ -135,7 +135,7 @@ public function testLoginSuccessIsNotProcessedWhenTokenDoesNotContainUserInterfa

public function testLoginSuccessIsNotProcessedWhenRememberMeIsNotRequested()
{
$service = $this->getService(null, array('name' => 'foo', 'always_remember_me' => false, 'remember_me_parameter' => 'foo'));
$service = $this->getService(null, array('name' => 'foo', 'always_remember_me' => false, 'remember_me_parameter' => 'foo', 'path' => null, 'domain' => null));
$request = new Request;
$response = new Response;
$account = $this->getMock('Symfony\Component\Security\Core\User\UserInterface');
Expand All @@ -159,7 +159,7 @@ public function testLoginSuccessIsNotProcessedWhenRememberMeIsNotRequested()

public function testLoginSuccessWhenRememberMeAlwaysIsTrue()
{
$service = $this->getService(null, array('name' => 'foo', 'always_remember_me' => true));
$service = $this->getService(null, array('name' => 'foo', 'always_remember_me' => true, 'path' => null, 'domain' => null));
$request = new Request;
$response = new Response;
$account = $this->getMock('Symfony\Component\Security\Core\User\UserInterface');
Expand All @@ -184,7 +184,7 @@ public function testLoginSuccessWhenRememberMeAlwaysIsTrue()
*/
public function testLoginSuccessWhenRememberMeParameterWithPathIsPositive($value)
{
$service = $this->getService(null, array('name' => 'foo', 'always_remember_me' => false, 'remember_me_parameter' => 'foo[bar]'));
$service = $this->getService(null, array('name' => 'foo', 'always_remember_me' => false, 'remember_me_parameter' => 'foo[bar]', 'path' => null, 'domain' => null));

$request = new Request;
$request->request->set('foo', array('bar' => $value));
Expand All @@ -211,7 +211,7 @@ public function testLoginSuccessWhenRememberMeParameterWithPathIsPositive($value
*/
public function testLoginSuccessWhenRememberMeParameterIsPositive($value)
{
$service = $this->getService(null, array('name' => 'foo', 'always_remember_me' => false, 'remember_me_parameter' => 'foo'));
$service = $this->getService(null, array('name' => 'foo', 'always_remember_me' => false, 'remember_me_parameter' => 'foo', 'path' => null, 'domain' => null));

$request = new Request;
$request->request->set('foo', $value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public function testLoginFail()

public function testLoginSuccessIgnoresTokensWhichDoNotContainAnUserInterfaceImplementation()
{
$service = $this->getService(null, array('name' => 'foo', 'always_remember_me' => true));
$service = $this->getService(null, array('name' => 'foo', 'always_remember_me' => true, 'path' => null, 'domain' => null));
$request = new Request;
$response = new Response;
$token = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface');
Expand Down
0