Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c268915

Browse files
bug #36832 [Security] Improved upgrade path for custom remember me services (wouterj)
This PR was merged into the 5.1-dev branch. Discussion ---------- [Security] Improved upgrade path for custom remember me services | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | - | Deprecations? | - | Tickets | #36806 (comment) | License | MIT | Doc PR | This improves the upgrade path for custom remember me services now `LogoutHandlerInterface` has been deprecated. As suggested in #36806 (comment), the `logout()` method should be added to the `RememberMeServicesInterface` in Symfony 6. This patch allows developers to write a custom class implementing only `RememberMeServicesInterface` with a `logout()` method. Requiring them to implement `LogoutHandlerInterface` will mean they have to maintain 2 version of the class to support both Symfony 5.1+ and 6.0. Commits ------- c49d00f Added deprecation for RememberMe services without logout() method
2 parents 773bebc + c49d00f commit c268915

File tree

5 files changed

+15
-2
lines changed

5 files changed

+15
-2
lines changed

UPGRADE-5.1.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ Security
167167

168168
* Deprecated `LogoutSuccessHandlerInterface` and `LogoutHandlerInterface`, register a listener on the `LogoutEvent` event instead.
169169
* Deprecated `DefaultLogoutSuccessHandler` in favor of `DefaultLogoutListener`.
170+
* Deprecated `RememberMeServicesInterface` implementations without a `logout(Request $request, Response $response, TokenInterface $token)` method.
170171

171172
Yaml
172173
----

UPGRADE-6.0.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ Security
113113
* Removed `ROLE_PREVIOUS_ADMIN` role in favor of `IS_IMPERSONATOR` attribute
114114
* Removed `LogoutSuccessHandlerInterface` and `LogoutHandlerInterface`, register a listener on the `LogoutEvent` event instead.
115115
* Removed `DefaultLogoutSuccessHandler` in favor of `DefaultLogoutListener`.
116+
* Added a `logout(Request $request, Response $response, TokenInterface $token)` method to the `RememberMeServicesInterface`.
116117

117118
Yaml
118119
----

src/Symfony/Component/Security/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ CHANGELOG
1111
* Deprecated `LogoutSuccessHandlerInterface` and `LogoutHandlerInterface` in favor of listening on the `LogoutEvent`.
1212
* Added experimental new security using `Http\Authenticator\AuthenticatorInterface`, `Http\Authentication\AuthenticatorManager` and `Http\Firewall\AuthenticatorManagerListener`.
1313
* Added `CustomUserMessageAccountStatusException` to be used when extending `UserCheckerInterface`
14+
* Deprecated `RememberMeServicesInterface` implementations without `logout(Request $request, Response $response, TokenInterface $token)` method, this method will be required in Symfony 6.0.
1415

1516
5.0.0
1617
-----

src/Symfony/Component/Security/Http/EventListener/RememberMeLogoutListener.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
1515
use Symfony\Component\Security\Core\Exception\LogicException;
1616
use Symfony\Component\Security\Http\Event\LogoutEvent;
17-
use Symfony\Component\Security\Http\Logout\LogoutHandlerInterface;
17+
use Symfony\Component\Security\Http\RememberMe\RememberMeServicesInterface;
1818

1919
/**
2020
* @author Wouter de Jong <[email protected]>
@@ -25,13 +25,21 @@ class RememberMeLogoutListener implements EventSubscriberInterface
2525
{
2626
private $rememberMeServices;
2727

28-
public function __construct(LogoutHandlerInterface $rememberMeServices)
28+
public function __construct(RememberMeServicesInterface $rememberMeServices)
2929
{
30+
if (!method_exists($rememberMeServices, 'logout')) {
31+
trigger_deprecation('symfony/security-core', '5.1', '"%s" should implement the "logout(Request $request, Response $response, TokenInterface $token)" method, this method will be added to the "%s" in version 6.0.', \get_class($rememberMeServices), RememberMeServicesInterface::class);
32+
}
33+
3034
$this->rememberMeServices = $rememberMeServices;
3135
}
3236

3337
public function onLogout(LogoutEvent $event): void
3438
{
39+
if (!method_exists($this->rememberMeServices, 'logout')) {
40+
return;
41+
}
42+
3543
if (null === $event->getResponse()) {
3644
throw new LogicException(sprintf('No response was set for this logout action. Make sure the DefaultLogoutListener or another listener has set the response before "%s" is called.', __CLASS__));
3745
}

src/Symfony/Component/Security/Http/RememberMe/RememberMeServicesInterface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
* - PersistentTokenBasedRememberMeServices (requires a TokenProvider)
2525
*
2626
* @author Johannes M. Schmitt <[email protected]>
27+
*
28+
* @method logout(Request $request, Response $response, TokenInterface $token)
2729
*/
2830
interface RememberMeServicesInterface
2931
{

0 commit comments

Comments
 (0)