[Security] Fixed missing badges argument for method authenticateUser

This commit is contained in:
Alexandre Daubois 2021-04-07 11:17:44 +02:00 committed by Wouter de Jong
parent 251ce63347
commit 7888f8930d
3 changed files with 11 additions and 3 deletions

View File

@ -193,6 +193,7 @@ Security
* Deprecate calling methods `hashPassword()`, `isPasswordValid()` and `needsRehash()` on `UserPasswordHasherInterface` with a `UserInterface` instance that does not implement `PasswordAuthenticatedUserInterface` * Deprecate calling methods `hashPassword()`, `isPasswordValid()` and `needsRehash()` on `UserPasswordHasherInterface` with a `UserInterface` instance that does not implement `PasswordAuthenticatedUserInterface`
* Deprecate all classes in the `Core\Encoder\` sub-namespace, use the `PasswordHasher` component instead * Deprecate all classes in the `Core\Encoder\` sub-namespace, use the `PasswordHasher` component instead
* Deprecated voters that do not return a valid decision when calling the `vote` method * Deprecated voters that do not return a valid decision when calling the `vote` method
* [BC break] Add optional array argument `$badges` to `UserAuthenticatorInterface::authenticateUser()`
SecurityBundle SecurityBundle
-------------- --------------

View File

@ -19,6 +19,7 @@ use Symfony\Component\Security\Core\Exception\LogicException;
use Symfony\Component\Security\Core\User\UserInterface; use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Security\Http\Authentication\UserAuthenticatorInterface; use Symfony\Component\Security\Http\Authentication\UserAuthenticatorInterface;
use Symfony\Component\Security\Http\Authenticator\AuthenticatorInterface; use Symfony\Component\Security\Http\Authenticator\AuthenticatorInterface;
use Symfony\Component\Security\Http\Authenticator\Passport\Badge\BadgeInterface;
/** /**
* A decorator that delegates all method calls to the authenticator * A decorator that delegates all method calls to the authenticator
@ -42,9 +43,12 @@ class UserAuthenticator implements UserAuthenticatorInterface
$this->requestStack = $requestStack; $this->requestStack = $requestStack;
} }
public function authenticateUser(UserInterface $user, AuthenticatorInterface $authenticator, Request $request): ?Response /**
* {@inheritdoc}
*/
public function authenticateUser(UserInterface $user, AuthenticatorInterface $authenticator, Request $request, array $badges = []): ?Response
{ {
return $this->getUserAuthenticator()->authenticateUser($user, $authenticator, $request); return $this->getUserAuthenticator()->authenticateUser($user, $authenticator, $request, $badges);
} }
private function getUserAuthenticator(): UserAuthenticatorInterface private function getUserAuthenticator(): UserAuthenticatorInterface

View File

@ -15,6 +15,7 @@ use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Core\User\UserInterface; use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Security\Http\Authenticator\AuthenticatorInterface; use Symfony\Component\Security\Http\Authenticator\AuthenticatorInterface;
use Symfony\Component\Security\Http\Authenticator\Passport\Badge\BadgeInterface;
/** /**
* @author Wouter de Jong <wouter@wouterj.nl> * @author Wouter de Jong <wouter@wouterj.nl>
@ -26,6 +27,8 @@ interface UserAuthenticatorInterface
/** /**
* Convenience method to programmatically login a user and return a * Convenience method to programmatically login a user and return a
* Response *if any* for success. * Response *if any* for success.
*
* @param BadgeInterface[] $badges Optionally, pass some Passport badges to use for the manual login
*/ */
public function authenticateUser(UserInterface $user, AuthenticatorInterface $authenticator, Request $request): ?Response; public function authenticateUser(UserInterface $user, AuthenticatorInterface $authenticator, Request $request, array $badges = []): ?Response;
} }