CustomAuthenticationSuccessHandler.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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\Authentication;
  11. use Symfony\Component\HttpFoundation\Request;
  12. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  13. /**
  14. * @author Fabien Potencier <fabien@symfony.com>
  15. */
  16. class CustomAuthenticationSuccessHandler implements AuthenticationSuccessHandlerInterface
  17. {
  18. private $handler;
  19. /**
  20. * @param array $options Options for processing a successful authentication attempt
  21. */
  22. public function __construct(AuthenticationSuccessHandlerInterface $handler, array $options, string $firewallName)
  23. {
  24. $this->handler = $handler;
  25. if (method_exists($handler, 'setOptions')) {
  26. $this->handler->setOptions($options);
  27. }
  28. if (method_exists($handler, 'setFirewallName')) {
  29. $this->handler->setFirewallName($firewallName);
  30. } elseif (method_exists($handler, 'setProviderKey')) {
  31. trigger_deprecation('symfony/security-http', '5.2', 'Method "%s::setProviderKey()" is deprecated, rename the method to "setFirewallName()" instead.', \get_class($handler));
  32. $this->handler->setProviderKey($firewallName);
  33. }
  34. }
  35. /**
  36. * {@inheritdoc}
  37. */
  38. public function onAuthenticationSuccess(Request $request, TokenInterface $token)
  39. {
  40. return $this->handler->onAuthenticationSuccess($request, $token);
  41. }
  42. }