Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit db572e3

Browse filesBrowse files
committed
[Security] Deprecate PassportInterface
1 parent cbe1f81 commit db572e3
Copy full SHA for db572e3

18 files changed

+193
-27
lines changed

‎UPGRADE-5.4.md

Copy file name to clipboardExpand all lines: UPGRADE-5.4.md
+23Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,26 @@ Security
4545
* Deprecate `TokenInterface:isAuthenticated()` and `setAuthenticated()` methods without replacement.
4646
Security tokens won't have an "authenticated" flag anymore, so they will always be considered authenticated
4747
* Deprecate `DeauthenticatedEvent`, use `TokenDeauthenticatedEvent` instead
48+
* Deprecate `AuthenticatorInterface::createAuthenticatedToken()`, use `AuthenticatorInterface::createToken()` instead
49+
* Deprecate `PassportInterface` and `UserPassportInterface`, use `Passport` instead.
50+
As such, the return type declaration of `AuthenticatorInterface::authenticate()` will change to `Passport` in 6.0
51+
52+
Before:
53+
```php
54+
class MyAuthenticator implements AuthenticatorInterface
55+
{
56+
public function authenticate(Request $request): PassportInterface
57+
{
58+
}
59+
}
60+
```
61+
62+
After:
63+
```php
64+
class MyAuthenticator implements AuthenticatorInterface
65+
{
66+
public function authenticate(Request $request): Passport
67+
{
68+
}
69+
}
70+
```

‎UPGRADE-6.0.md

Copy file name to clipboardExpand all lines: UPGRADE-6.0.md
+23Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,29 @@ Security
326326
* Remove `TokenInterface:isAuthenticated()` and `setAuthenticated()` methods without replacement.
327327
Security tokens won't have an "authenticated" flag anymore, so they will always be considered authenticated
328328
* Remove `DeauthenticatedEvent`, use `TokenDeauthenticatedEvent` instead
329+
* Remove `AuthenticatorInterface::createAuthenticatedToken()`, use `AuthenticatorInterface::createToken()` instead
330+
* Remove `PassportInterface` and `UserPassportInterface`, use `Passport` instead.
331+
Also, the return type declaration of `AuthenticatorInterface::authenticate()` was changed to `Passport`
332+
333+
Before:
334+
```php
335+
class MyAuthenticator implements AuthenticatorInterface
336+
{
337+
public function authenticate(Request $request): PassportInterface
338+
{
339+
}
340+
}
341+
```
342+
343+
After:
344+
```php
345+
class MyAuthenticator implements AuthenticatorInterface
346+
{
347+
public function authenticate(Request $request): Passport
348+
{
349+
}
350+
}
351+
```
329352

330353
SecurityBundle
331354
--------------

‎src/Symfony/Component/Ldap/Security/LdapAuthenticator.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Ldap/Security/LdapAuthenticator.php
+17-2Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
1717
use Symfony\Component\Security\Core\Exception\AuthenticationException;
1818
use Symfony\Component\Security\Http\Authenticator\AuthenticatorInterface;
19+
use Symfony\Component\Security\Http\Authenticator\Passport\Passport;
1920
use Symfony\Component\Security\Http\Authenticator\Passport\PassportInterface;
2021

2122
/**
@@ -53,17 +54,31 @@ public function supports(Request $request): ?bool
5354
return $this->authenticator->supports($request);
5455
}
5556

56-
public function authenticate(Request $request): PassportInterface
57+
public function authenticate(Request $request): Passport
5758
{
5859
$passport = $this->authenticator->authenticate($request);
5960
$passport->addBadge(new LdapBadge($this->ldapServiceId, $this->dnString, $this->searchDn, $this->searchPassword, $this->queryString));
6061

6162
return $passport;
6263
}
6364

65+
/**
66+
* @deprecated since Symfony 5.4, use {@link createToken()} instead
67+
*/
6468
public function createAuthenticatedToken(PassportInterface $passport, string $firewallName): TokenInterface
6569
{
66-
return $this->authenticator->createAuthenticatedToken($passport, $firewallName);
70+
trigger_deprecation('symfony/ldap', '5.4', 'Method "%s()" is deprecated, use "%s::createToken()" instead.', __METHOD__, __CLASS__);
71+
72+
return $this->createToken($passport, $firewallName);
73+
}
74+
75+
public function createToken(PassportInterface $passport, string $firewallName): TokenInterface
76+
{
77+
// @deprecated since Symfony 5.4, in 6.0 change to:
78+
// return $this->authenticator->createToken($passport, $firewallName);
79+
return method_exists($this->authenticator, 'createToken')
80+
? $this->authenticator->createToken($passport, $firewallName)
81+
: $this->authenticator->createAuthenticatedToken($passport, $firewallName);
6782
}
6883

6984
public function onAuthenticationSuccess(Request $request, TokenInterface $token, string $firewallName): ?Response

‎src/Symfony/Component/Security/Core/Exception/AuthenticationExpiredException.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Security/Core/Exception/AuthenticationExpiredException.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
namespace Symfony\Component\Security\Core\Exception;
1313

1414
/**
15-
* AuthenticationExpiredException is thrown when an authenticated token becomes un-authenticated between requests.
15+
* AuthenticationExpiredException is thrown when an authentication token becomes un-authenticated between requests.
1616
*
1717
* In practice, this is due to the User changing between requests (e.g. password changes),
1818
* causes the token to become un-authenticated.

‎src/Symfony/Component/Security/Http/Authentication/AuthenticatorManager.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Security/Http/Authentication/AuthenticatorManager.php
+7-6Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,12 @@ public function __construct(iterable $authenticators, TokenStorageInterface $tok
7474
*/
7575
public function authenticateUser(UserInterface $user, AuthenticatorInterface $authenticator, Request $request, array $badges = []): ?Response
7676
{
77-
// create an authenticated token for the User
77+
// create an authentication token for the User
7878
// @deprecated since 5.3, change to $user->getUserIdentifier() in 6.0
79-
$token = $authenticator->createAuthenticatedToken($passport = new SelfValidatingPassport(new UserBadge(method_exists($user, 'getUserIdentifier') ? $user->getUserIdentifier() : $user->getUsername(), function () use ($user) { return $user; }), $badges), $this->firewallName);
79+
$passport = new SelfValidatingPassport(new UserBadge(method_exists($user, 'getUserIdentifier') ? $user->getUserIdentifier() : $user->getUsername(), function () use ($user) { return $user; }), $badges);
80+
$token = method_exists($authenticator, 'createToken') ? $authenticator->createToken($passport, $this->firewallName) : $authenticator->createAuthenticatedToken($passport, $this->firewallName);
8081

81-
// announce the authenticated token
82+
// announce the authentication token
8283
$token = $this->eventDispatcher->dispatch(new AuthenticationTokenCreatedEvent($token, $passport))->getAuthenticatedToken();
8384

8485
// authenticate this in the system
@@ -189,10 +190,10 @@ private function executeAuthenticator(AuthenticatorInterface $authenticator, Req
189190
throw new BadCredentialsException(sprintf('Authentication failed; Some badges marked as required by the firewall config are not available on the passport: "%s".', implode('", "', $missingRequiredBadges)));
190191
}
191192

192-
// create the authenticated token
193-
$authenticatedToken = $authenticator->createAuthenticatedToken($passport, $this->firewallName);
193+
// create the authentication token
194+
$authenticatedToken = method_exists($authenticator, 'createToken') ? $authenticator->createToken($passport, $this->firewallName) : $authenticator->createAuthenticatedToken($passport, $this->firewallName);
194195

195-
// announce the authenticated token
196+
// announce the authentication token
196197
$authenticatedToken = $this->eventDispatcher->dispatch(new AuthenticationTokenCreatedEvent($authenticatedToken, $passport))->getAuthenticatedToken();
197198

198199
if (true === $this->eraseCredentials) {

‎src/Symfony/Component/Security/Http/Authenticator/AbstractAuthenticator.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Security/Http/Authenticator/AbstractAuthenticator.php
+14-2Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
1515
use Symfony\Component\Security\Core\Exception\LogicException;
16+
use Symfony\Component\Security\Http\Authenticator\Passport\Passport;
1617
use Symfony\Component\Security\Http\Authenticator\Passport\PassportInterface;
1718
use Symfony\Component\Security\Http\Authenticator\Passport\UserPassportInterface;
1819
use Symfony\Component\Security\Http\Authenticator\Token\PostAuthenticationToken;
@@ -30,12 +31,23 @@ abstract class AbstractAuthenticator implements AuthenticatorInterface
3031
*
3132
* @return PostAuthenticationToken
3233
*/
33-
public function createAuthenticatedToken(PassportInterface $passport, string $firewallName): TokenInterface
34+
public function createToken(Passport $passport, string $firewallName): TokenInterface
3435
{
36+
// @deprecated since Symfony 5.4
3537
if (!$passport instanceof UserPassportInterface) {
36-
throw new LogicException(sprintf('Passport does not contain a user, overwrite "createAuthenticatedToken()" in "%s" to create a custom authenticated token.', static::class));
38+
throw new LogicException(sprintf('Passport does not contain a user, overwrite "createToken()" in "%s" to create a custom authentication token.', static::class));
3739
}
3840

3941
return new PostAuthenticationToken($passport->getUser(), $firewallName, $passport->getUser()->getRoles());
4042
}
43+
44+
/**
45+
* @deprecated since Symfony 5.4, use {@link createToken()} instead
46+
*/
47+
public function createAuthenticatedToken(PassportInterface $passport, string $firewallName): TokenInterface
48+
{
49+
trigger_deprecation('symfony/security-http', '5.4', 'Method "%s()" is deprecated, use "%s::createToken()" instead.', __METHOD__, __CLASS__);
50+
51+
return $this->createToken($passport, $firewallName);
52+
}
4153
}

‎src/Symfony/Component/Security/Http/Authenticator/AbstractPreAuthenticatedAuthenticator.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Security/Http/Authenticator/AbstractPreAuthenticatedAuthenticator.php
+12-1Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use Symfony\Component\Security\Core\User\UserProviderInterface;
2323
use Symfony\Component\Security\Http\Authenticator\Passport\Badge\PreAuthenticatedUserBadge;
2424
use Symfony\Component\Security\Http\Authenticator\Passport\Badge\UserBadge;
25+
use Symfony\Component\Security\Http\Authenticator\Passport\Passport;
2526
use Symfony\Component\Security\Http\Authenticator\Passport\PassportInterface;
2627
use Symfony\Component\Security\Http\Authenticator\Passport\SelfValidatingPassport;
2728

@@ -84,7 +85,7 @@ public function supports(Request $request): ?bool
8485
return true;
8586
}
8687

87-
public function authenticate(Request $request): PassportInterface
88+
public function authenticate(Request $request): Passport
8889
{
8990
// @deprecated since 5.3, change to $this->userProvider->loadUserByIdentifier() in 6.0
9091
$method = 'loadUserByIdentifier';
@@ -100,7 +101,17 @@ public function authenticate(Request $request): PassportInterface
100101
);
101102
}
102103

104+
/**
105+
* @deprecated since Symfony 5.4, use {@link createToken()} instead
106+
*/
103107
public function createAuthenticatedToken(PassportInterface $passport, string $firewallName): TokenInterface
108+
{
109+
trigger_deprecation('symfony/security-http', '5.4', 'Method "%s()" is deprecated, use "%s::createToken()" instead.', __METHOD__, __CLASS__);
110+
111+
return $this->createToken($passport, $firewallName);
112+
}
113+
114+
public function createToken(Passport $passport, string $firewallName): TokenInterface
104115
{
105116
return new PreAuthenticatedToken($passport->getUser(), null, $firewallName, $passport->getUser()->getRoles());
106117
}

‎src/Symfony/Component/Security/Http/Authenticator/AuthenticatorInterface.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Security/Http/Authenticator/AuthenticatorInterface.php
+11-1Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Component\HttpFoundation\Response;
1616
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
1717
use Symfony\Component\Security\Core\Exception\AuthenticationException;
18+
use Symfony\Component\Security\Http\Authenticator\Passport\Passport;
1819
use Symfony\Component\Security\Http\Authenticator\Passport\PassportInterface;
1920

2021
/**
@@ -23,6 +24,11 @@
2324
* @author Ryan Weaver <ryan@symfonycasts.com>
2425
* @author Amaury Leroux de Lens <amaury@lerouxdelens.com>
2526
* @author Wouter de Jong <wouter@wouterj.nl>
27+
*
28+
* @method TokenInterface createToken(Passport $passport, string $firewallName) Create a token for the given user.
29+
* If you don't care about which token class is used or don't really
30+
* understand what a "token" is, you can skip this method by extending
31+
* the AbstractAuthenticator class from your authenticator.
2632
*/
2733
interface AuthenticatorInterface
2834
{
@@ -47,8 +53,10 @@ public function supports(Request $request): ?bool;
4753
* a UserNotFoundException when the user cannot be found).
4854
*
4955
* @throws AuthenticationException
56+
*
57+
* @return Passport
5058
*/
51-
public function authenticate(Request $request): PassportInterface;
59+
public function authenticate(Request $request); /*: Passport;*/
5260

5361
/**
5462
* Create an authenticated token for the given user.
@@ -60,6 +68,8 @@ public function authenticate(Request $request): PassportInterface;
6068
* @see AbstractAuthenticator
6169
*
6270
* @param PassportInterface $passport The passport returned from authenticate()
71+
*
72+
* @deprecated since Symfony 5.4, use {@link createToken()} instead
6373
*/
6474
public function createAuthenticatedToken(PassportInterface $passport, string $firewallName): TokenInterface;
6575

‎src/Symfony/Component/Security/Http/Authenticator/FormLoginAuthenticator.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Security/Http/Authenticator/FormLoginAuthenticator.php
+12-2Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public function supports(Request $request): bool
7777
&& $this->httpUtils->checkRequestPath($request, $this->options['check_path']);
7878
}
7979

80-
public function authenticate(Request $request): PassportInterface
80+
public function authenticate(Request $request): Passport
8181
{
8282
$credentials = $this->getCredentials($request);
8383

@@ -106,9 +106,19 @@ public function authenticate(Request $request): PassportInterface
106106
}
107107

108108
/**
109-
* @param Passport $passport
109+
* @deprecated since Symfony 5.4, use {@link createToken()} instead
110110
*/
111111
public function createAuthenticatedToken(PassportInterface $passport, string $firewallName): TokenInterface
112+
{
113+
trigger_deprecation('symfony/security-http', '5.4', 'Method "%s()" is deprecated, use "%s::createToken()" instead.', __METHOD__, __CLASS__);
114+
115+
return $this->createToken($passport, $firewallName);
116+
}
117+
118+
/**
119+
* @return UsernamePasswordToken
120+
*/
121+
public function createToken(Passport $passport, string $firewallName): TokenInterface
112122
{
113123
return new UsernamePasswordToken($passport->getUser(), null, $firewallName, $passport->getUser()->getRoles());
114124
}

‎src/Symfony/Component/Security/Http/Authenticator/HttpBasicAuthenticator.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Security/Http/Authenticator/HttpBasicAuthenticator.php
+8-1Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,16 @@ public function authenticate(Request $request): PassportInterface
8484
}
8585

8686
/**
87-
* @param Passport $passport
87+
* @deprecated since Symfony 5.4, use {@link createToken()} instead
8888
*/
8989
public function createAuthenticatedToken(PassportInterface $passport, string $firewallName): TokenInterface
90+
{
91+
trigger_deprecation('symfony/security-http', '5.4', 'Method "%s()" is deprecated, use "%s::createToken()" instead.', __METHOD__, __CLASS__);
92+
93+
return $this->createToken($passport, $firewallName);
94+
}
95+
96+
public function createToken(Passport $passport, string $firewallName): TokenInterface
9097
{
9198
return new UsernamePasswordToken($passport->getUser(), null, $firewallName, $passport->getUser()->getRoles());
9299
}

‎src/Symfony/Component/Security/Http/Authenticator/JsonLoginAuthenticator.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Security/Http/Authenticator/JsonLoginAuthenticator.php
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,17 @@ public function authenticate(Request $request): PassportInterface
110110
return $passport;
111111
}
112112

113+
/**
114+
* @deprecated since Symfony 5.4, use {@link createToken()} instead
115+
*/
113116
public function createAuthenticatedToken(PassportInterface $passport, string $firewallName): TokenInterface
117+
{
118+
trigger_deprecation('symfony/security-http', '5.4', 'Method "%s()" is deprecated, use "%s::createToken()" instead.', __METHOD__, __CLASS__);
119+
120+
return $this->createToken($passport, $firewallName);
121+
}
122+
123+
public function createToken(Passport $passport, string $firewallName): TokenInterface
114124
{
115125
return new UsernamePasswordToken($passport->getUser(), null, $firewallName, $passport->getUser()->getRoles());
116126
}

‎src/Symfony/Component/Security/Http/Authenticator/Passport/PassportInterface.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Security/Http/Authenticator/Passport/PassportInterface.php
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
* passport.
2222
*
2323
* @author Wouter de Jong <wouter@wouterj.nl>
24+
*
25+
* @deprecated since Symfony 5.4, use {@link Passport} instead
2426
*/
2527
interface PassportInterface
2628
{

‎src/Symfony/Component/Security/Http/Authenticator/Passport/UserPassportInterface.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Security/Http/Authenticator/Passport/UserPassportInterface.php
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
* Represents a passport for a Security User.
1919
*
2020
* @author Wouter de Jong <wouter@wouterj.nl>
21+
*
22+
* @deprecated since Symfony 5.4, use {@link Passport} instead
2123
*/
2224
interface UserPassportInterface extends PassportInterface
2325
{

‎src/Symfony/Component/Security/Http/Authenticator/RememberMeAuthenticator.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Security/Http/Authenticator/RememberMeAuthenticator.php
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
2323
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
2424
use Symfony\Component\Security\Http\Authenticator\Passport\Badge\UserBadge;
25+
use Symfony\Component\Security\Http\Authenticator\Passport\Passport;
2526
use Symfony\Component\Security\Http\Authenticator\Passport\PassportInterface;
2627
use Symfony\Component\Security\Http\Authenticator\Passport\SelfValidatingPassport;
2728
use Symfony\Component\Security\Http\RememberMe\RememberMeDetails;
@@ -95,7 +96,17 @@ public function authenticate(Request $request): PassportInterface
9596
}));
9697
}
9798

99+
/**
100+
* @deprecated since Symfony 5.4, use {@link createToken()} instead
101+
*/
98102
public function createAuthenticatedToken(PassportInterface $passport, string $firewallName): TokenInterface
103+
{
104+
trigger_deprecation('symfony/security-http', '5.4', 'Method "%s()" is deprecated, use "%s::createToken()" instead.', __METHOD__, __CLASS__);
105+
106+
return $this->createToken($passport, $firewallName);
107+
}
108+
109+
public function createToken(Passport $passport, string $firewallName): TokenInterface
99110
{
100111
return new RememberMeToken($passport->getUser(), $firewallName, $this->secret);
101112
}

‎src/Symfony/Component/Security/Http/Authenticator/Token/PostAuthenticationToken.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Security/Http/Authenticator/Token/PostAuthenticationToken.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function __construct(UserInterface $user, string $firewallName, array $ro
4040
}
4141

4242
/**
43-
* This is meant to be only an authenticated token, where credentials
43+
* This is meant to be only a token, where credentials
4444
* have already been used and are thus cleared.
4545
*
4646
* {@inheritdoc}

‎src/Symfony/Component/Security/Http/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Component/Security/Http/CHANGELOG.md
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ CHANGELOG
66

77
* Deprecate not setting the 5th argument (`$exceptionOnNoToken`) of `AccessListener` to `false`
88
* Deprecate `DeauthenticatedEvent`, use `TokenDeauthenticatedEvent` instead
9+
* Deprecate `PassportInterface` and `UserPassportInterface`, use `Passport` instead
910

1011
5.3
1112
---

‎src/Symfony/Component/Security/Http/Event/LoginSuccessEvent.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Security/Http/Event/LoginSuccessEvent.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
/**
2525
* This event is dispatched after authentication has successfully completed.
2626
*
27-
* At this stage, the authenticator created an authenticated token
28-
* and generated an authentication success response. Listeners to
27+
* At this stage, the authenticator created a token and
28+
* generated an authentication success response. Listeners to
2929
* this event can do actions related to successful authentication
3030
* (such as migrating the password).
3131
*

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.