vendor/symfony/security-http/Authenticator/Passport/Credentials/CustomCredentials.php line 24

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Symfony package.
  4.  *
  5.  * (c) Fabien Potencier <fabien@symfony.com>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace Symfony\Component\Security\Http\Authenticator\Passport\Credentials;
  11. use Symfony\Component\Security\Core\Exception\BadCredentialsException;
  12. use Symfony\Component\Security\Core\User\UserInterface;
  13. /**
  14.  * Implements credentials checking using a custom checker function.
  15.  *
  16.  * @author Wouter de Jong <wouter@wouterj.nl>
  17.  *
  18.  * @final
  19.  */
  20. class CustomCredentials implements CredentialsInterface
  21. {
  22.     private $customCredentialsChecker;
  23.     private $credentials;
  24.     private $resolved false;
  25.     /**
  26.      * @param callable $customCredentialsChecker the check function. If this function does not return `true`, a
  27.      *                                           BadCredentialsException is thrown. You may also throw a more
  28.      *                                           specific exception in the function.
  29.      * @param mixed    $credentials
  30.      */
  31.     public function __construct(callable $customCredentialsChecker$credentials)
  32.     {
  33.         $this->customCredentialsChecker $customCredentialsChecker;
  34.         $this->credentials $credentials;
  35.     }
  36.     public function executeCustomChecker(UserInterface $user): void
  37.     {
  38.         $checker $this->customCredentialsChecker;
  39.         if (true !== $checker($this->credentials$user)) {
  40.             throw new BadCredentialsException('Credentials check failed as the callable passed to CustomCredentials did not return "true".');
  41.         }
  42.         $this->resolved true;
  43.     }
  44.     public function isResolved(): bool
  45.     {
  46.         return $this->resolved;
  47.     }
  48. }