[Form] Drop remaing CsrfProviderAdapter/Interface mentions
This commit is contained in:
parent
380ce606aa
commit
5bc34d2d51
@ -94,15 +94,11 @@ class FormExtension extends \Twig_Extension implements \Twig_Extension_InitRunti
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Renders a CSRF token.
|
* {@inheritdoc}
|
||||||
*
|
|
||||||
* @param string $intention The intention of the protected action.
|
|
||||||
*
|
|
||||||
* @return string A CSRF token.
|
|
||||||
*/
|
*/
|
||||||
public function renderCsrfToken($intention)
|
public function renderCsrfToken($tokenId)
|
||||||
{
|
{
|
||||||
return $this->renderer->renderCsrfToken($intention);
|
return $this->renderer->renderCsrfToken($tokenId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -223,7 +223,7 @@ class FormHelper extends Helper
|
|||||||
* echo $view['form']->csrfToken('rm_user_'.$user->getId());
|
* echo $view['form']->csrfToken('rm_user_'.$user->getId());
|
||||||
* </code>
|
* </code>
|
||||||
*
|
*
|
||||||
* Check the token in your action using the same intention.
|
* Check the token in your action using the same CSRF token id.
|
||||||
*
|
*
|
||||||
* <code>
|
* <code>
|
||||||
* $csrfProvider = $this->get('security.csrf.token_generator');
|
* $csrfProvider = $this->get('security.csrf.token_generator');
|
||||||
@ -232,15 +232,15 @@ class FormHelper extends Helper
|
|||||||
* }
|
* }
|
||||||
* </code>
|
* </code>
|
||||||
*
|
*
|
||||||
* @param string $intention The intention of the protected action
|
* @param string $tokenId The CSRF token id of the protected action
|
||||||
*
|
*
|
||||||
* @return string A CSRF token
|
* @return string A CSRF token
|
||||||
*
|
*
|
||||||
* @throws \BadMethodCallException When no CSRF provider was injected in the constructor.
|
* @throws \BadMethodCallException When no CSRF provider was injected in the constructor.
|
||||||
*/
|
*/
|
||||||
public function csrfToken($intention)
|
public function csrfToken($tokenId)
|
||||||
{
|
{
|
||||||
return $this->renderer->renderCsrfToken($intention);
|
return $this->renderer->renderCsrfToken($tokenId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function humanize($text)
|
public function humanize($text)
|
||||||
|
@ -29,7 +29,7 @@ class FormLoginFactory extends AbstractFactory
|
|||||||
$this->addOption('username_parameter', '_username');
|
$this->addOption('username_parameter', '_username');
|
||||||
$this->addOption('password_parameter', '_password');
|
$this->addOption('password_parameter', '_password');
|
||||||
$this->addOption('csrf_parameter', '_csrf_token');
|
$this->addOption('csrf_parameter', '_csrf_token');
|
||||||
$this->addOption('intention', 'authenticate');
|
$this->addOption('csrf_token_id', 'authenticate');
|
||||||
$this->addOption('post_only', true);
|
$this->addOption('post_only', true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -303,7 +303,7 @@ class SecurityExtension extends Extension
|
|||||||
$listener = $container->setDefinition($listenerId, new DefinitionDecorator('security.logout_listener'));
|
$listener = $container->setDefinition($listenerId, new DefinitionDecorator('security.logout_listener'));
|
||||||
$listener->replaceArgument(3, array(
|
$listener->replaceArgument(3, array(
|
||||||
'csrf_parameter' => $firewall['logout']['csrf_parameter'],
|
'csrf_parameter' => $firewall['logout']['csrf_parameter'],
|
||||||
'intention' => $firewall['logout']['csrf_token_id'],
|
'csrf_token_id' => $firewall['logout']['csrf_token_id'],
|
||||||
'logout_path' => $firewall['logout']['path'],
|
'logout_path' => $firewall['logout']['path'],
|
||||||
));
|
));
|
||||||
$listeners[] = new Reference($listenerId);
|
$listeners[] = new Reference($listenerId);
|
||||||
|
@ -91,54 +91,6 @@ class MainConfigurationTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals('a_token_id', $processedConfig['firewalls']['stub']['logout']['csrf_token_id']);
|
$this->assertEquals('a_token_id', $processedConfig['firewalls']['stub']['logout']['csrf_token_id']);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @group legacy
|
|
||||||
*/
|
|
||||||
public function testLegacyCsrfAliases()
|
|
||||||
{
|
|
||||||
$config = array(
|
|
||||||
'firewalls' => array(
|
|
||||||
'stub' => array(
|
|
||||||
'logout' => array(
|
|
||||||
'csrf_provider' => 'a_token_generator',
|
|
||||||
'intention' => 'a_token_id',
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
$config = array_merge(static::$minimalConfig, $config);
|
|
||||||
|
|
||||||
$processor = new Processor();
|
|
||||||
$configuration = new MainConfiguration(array(), array());
|
|
||||||
$processedConfig = $processor->processConfiguration($configuration, array($config));
|
|
||||||
$this->assertTrue(isset($processedConfig['firewalls']['stub']['logout']['csrf_token_generator']));
|
|
||||||
$this->assertEquals('a_token_generator', $processedConfig['firewalls']['stub']['logout']['csrf_token_generator']);
|
|
||||||
$this->assertTrue(isset($processedConfig['firewalls']['stub']['logout']['csrf_token_id']));
|
|
||||||
$this->assertEquals('a_token_id', $processedConfig['firewalls']['stub']['logout']['csrf_token_id']);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException \InvalidArgumentException
|
|
||||||
*/
|
|
||||||
public function testCsrfOriginalAndAliasValueCausesException()
|
|
||||||
{
|
|
||||||
$config = array(
|
|
||||||
'firewalls' => array(
|
|
||||||
'stub' => array(
|
|
||||||
'logout' => array(
|
|
||||||
'csrf_token_id' => 'a_token_id',
|
|
||||||
'intention' => 'old_name',
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
$config = array_merge(static::$minimalConfig, $config);
|
|
||||||
|
|
||||||
$processor = new Processor();
|
|
||||||
$configuration = new MainConfiguration(array(), array());
|
|
||||||
$processor->processConfiguration($configuration, array($config));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testDefaultUserCheckers()
|
public function testDefaultUserCheckers()
|
||||||
{
|
{
|
||||||
$processor = new Processor();
|
$processor = new Processor();
|
||||||
|
@ -76,12 +76,12 @@ class UserLoginType extends AbstractType
|
|||||||
*/
|
*/
|
||||||
public function configureOptions(OptionsResolver $resolver)
|
public function configureOptions(OptionsResolver $resolver)
|
||||||
{
|
{
|
||||||
/* Note: the form's intention must correspond to that for the form login
|
/* Note: the form's csrf_token_id must correspond to that for the form login
|
||||||
* listener in order for the CSRF token to validate successfully.
|
* listener in order for the CSRF token to validate successfully.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$resolver->setDefaults(array(
|
$resolver->setDefaults(array(
|
||||||
'intention' => 'authenticate',
|
'csrf_token_id' => 'authenticate',
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,9 +11,6 @@
|
|||||||
|
|
||||||
namespace Symfony\Component\Form\Extension\Csrf;
|
namespace Symfony\Component\Form\Extension\Csrf;
|
||||||
|
|
||||||
use Symfony\Component\Form\Exception\UnexpectedTypeException;
|
|
||||||
use Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderAdapter;
|
|
||||||
use Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderInterface;
|
|
||||||
use Symfony\Component\Form\AbstractExtension;
|
use Symfony\Component\Form\AbstractExtension;
|
||||||
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
|
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
|
||||||
use Symfony\Component\Translation\TranslatorInterface;
|
use Symfony\Component\Translation\TranslatorInterface;
|
||||||
@ -47,14 +44,8 @@ class CsrfExtension extends AbstractExtension
|
|||||||
* @param TranslatorInterface $translator The translator for translating error messages
|
* @param TranslatorInterface $translator The translator for translating error messages
|
||||||
* @param null|string $translationDomain The translation domain for translating
|
* @param null|string $translationDomain The translation domain for translating
|
||||||
*/
|
*/
|
||||||
public function __construct($tokenManager, TranslatorInterface $translator = null, $translationDomain = null)
|
public function __construct(CsrfTokenManagerInterface $tokenManager, TranslatorInterface $translator = null, $translationDomain = null)
|
||||||
{
|
{
|
||||||
if ($tokenManager instanceof CsrfProviderInterface) {
|
|
||||||
$tokenManager = new CsrfProviderAdapter($tokenManager);
|
|
||||||
} elseif (!$tokenManager instanceof CsrfTokenManagerInterface) {
|
|
||||||
throw new UnexpectedTypeException($tokenManager, 'CsrfProviderInterface or CsrfTokenManagerInterface');
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->tokenManager = $tokenManager;
|
$this->tokenManager = $tokenManager;
|
||||||
$this->translator = $translator;
|
$this->translator = $translator;
|
||||||
$this->translationDomain = $translationDomain;
|
$this->translationDomain = $translationDomain;
|
||||||
|
@ -12,9 +12,6 @@
|
|||||||
namespace Symfony\Component\Form\Extension\Csrf\EventListener;
|
namespace Symfony\Component\Form\Extension\Csrf\EventListener;
|
||||||
|
|
||||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||||
use Symfony\Component\Form\Exception\UnexpectedTypeException;
|
|
||||||
use Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderAdapter;
|
|
||||||
use Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderInterface;
|
|
||||||
use Symfony\Component\Form\FormEvents;
|
use Symfony\Component\Form\FormEvents;
|
||||||
use Symfony\Component\Form\FormError;
|
use Symfony\Component\Form\FormError;
|
||||||
use Symfony\Component\Form\FormEvent;
|
use Symfony\Component\Form\FormEvent;
|
||||||
@ -75,14 +72,8 @@ class CsrfValidationListener implements EventSubscriberInterface
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __construct($fieldName, $tokenManager, $tokenId, $errorMessage, TranslatorInterface $translator = null, $translationDomain = null)
|
public function __construct($fieldName, CsrfTokenManagerInterface $tokenManager, $tokenId, $errorMessage, TranslatorInterface $translator = null, $translationDomain = null)
|
||||||
{
|
{
|
||||||
if ($tokenManager instanceof CsrfProviderInterface) {
|
|
||||||
$tokenManager = new CsrfProviderAdapter($tokenManager);
|
|
||||||
} elseif (!$tokenManager instanceof CsrfTokenManagerInterface) {
|
|
||||||
throw new UnexpectedTypeException($tokenManager, 'CsrfProviderInterface or CsrfTokenManagerInterface');
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->fieldName = $fieldName;
|
$this->fieldName = $fieldName;
|
||||||
$this->tokenManager = $tokenManager;
|
$this->tokenManager = $tokenManager;
|
||||||
$this->tokenId = $tokenId;
|
$this->tokenId = $tokenId;
|
||||||
|
@ -12,10 +12,6 @@
|
|||||||
namespace Symfony\Component\Form\Extension\Csrf\Type;
|
namespace Symfony\Component\Form\Extension\Csrf\Type;
|
||||||
|
|
||||||
use Symfony\Component\Form\AbstractTypeExtension;
|
use Symfony\Component\Form\AbstractTypeExtension;
|
||||||
use Symfony\Component\Form\Exception\UnexpectedTypeException;
|
|
||||||
use Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderAdapter;
|
|
||||||
use Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderInterface;
|
|
||||||
use Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfTokenManagerAdapter;
|
|
||||||
use Symfony\Component\Form\Extension\Csrf\EventListener\CsrfValidationListener;
|
use Symfony\Component\Form\Extension\Csrf\EventListener\CsrfValidationListener;
|
||||||
use Symfony\Component\Form\FormBuilderInterface;
|
use Symfony\Component\Form\FormBuilderInterface;
|
||||||
use Symfony\Component\Form\FormView;
|
use Symfony\Component\Form\FormView;
|
||||||
@ -55,14 +51,8 @@ class FormTypeCsrfExtension extends AbstractTypeExtension
|
|||||||
*/
|
*/
|
||||||
private $translationDomain;
|
private $translationDomain;
|
||||||
|
|
||||||
public function __construct($defaultTokenManager, $defaultEnabled = true, $defaultFieldName = '_token', TranslatorInterface $translator = null, $translationDomain = null)
|
public function __construct(CsrfTokenManagerInterface $defaultTokenManager, $defaultEnabled = true, $defaultFieldName = '_token', TranslatorInterface $translator = null, $translationDomain = null)
|
||||||
{
|
{
|
||||||
if ($defaultTokenManager instanceof CsrfProviderInterface) {
|
|
||||||
$defaultTokenManager = new CsrfProviderAdapter($defaultTokenManager);
|
|
||||||
} elseif (!$defaultTokenManager instanceof CsrfTokenManagerInterface) {
|
|
||||||
throw new UnexpectedTypeException($defaultTokenManager, 'CsrfProviderInterface or CsrfTokenManagerInterface');
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->defaultTokenManager = $defaultTokenManager;
|
$this->defaultTokenManager = $defaultTokenManager;
|
||||||
$this->defaultEnabled = $defaultEnabled;
|
$this->defaultEnabled = $defaultEnabled;
|
||||||
$this->defaultFieldName = $defaultFieldName;
|
$this->defaultFieldName = $defaultFieldName;
|
||||||
@ -130,39 +120,14 @@ class FormTypeCsrfExtension extends AbstractTypeExtension
|
|||||||
return $options['intention'];
|
return $options['intention'];
|
||||||
};
|
};
|
||||||
|
|
||||||
// BC clause for the "csrf_provider" option
|
|
||||||
$csrfTokenManager = function (Options $options) {
|
|
||||||
if ($options['csrf_provider'] instanceof CsrfTokenManagerInterface) {
|
|
||||||
return $options['csrf_provider'];
|
|
||||||
}
|
|
||||||
|
|
||||||
return $options['csrf_provider'] instanceof CsrfTokenManagerAdapter
|
|
||||||
? $options['csrf_provider']->getTokenManager(false)
|
|
||||||
: new CsrfProviderAdapter($options['csrf_provider']);
|
|
||||||
};
|
|
||||||
|
|
||||||
$defaultTokenManager = $this->defaultTokenManager;
|
|
||||||
$csrfProviderNormalizer = function (Options $options, $csrfProvider) use ($defaultTokenManager) {
|
|
||||||
if (null !== $csrfProvider) {
|
|
||||||
@trigger_error('The form option "csrf_provider" is deprecated since version 2.8 and will be removed in 3.0. Use "csrf_token_manager" instead.', E_USER_DEPRECATED);
|
|
||||||
|
|
||||||
return $csrfProvider;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $defaultTokenManager;
|
|
||||||
};
|
|
||||||
|
|
||||||
$resolver->setDefaults(array(
|
$resolver->setDefaults(array(
|
||||||
'csrf_protection' => $this->defaultEnabled,
|
'csrf_protection' => $this->defaultEnabled,
|
||||||
'csrf_field_name' => $this->defaultFieldName,
|
'csrf_field_name' => $this->defaultFieldName,
|
||||||
'csrf_message' => 'The CSRF token is invalid. Please try to resubmit the form.',
|
'csrf_message' => 'The CSRF token is invalid. Please try to resubmit the form.',
|
||||||
'csrf_token_manager' => $csrfTokenManager,
|
'csrf_token_manager' => $this->defaultTokenManager,
|
||||||
'csrf_token_id' => $csrfTokenId,
|
'csrf_token_id' => $csrfTokenId,
|
||||||
'csrf_provider' => null, // deprecated
|
|
||||||
'intention' => null, // deprecated
|
'intention' => null, // deprecated
|
||||||
));
|
));
|
||||||
|
|
||||||
$resolver->setNormalizer('csrf_provider', $csrfProviderNormalizer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -12,9 +12,6 @@
|
|||||||
namespace Symfony\Component\Form\Extension\Templating;
|
namespace Symfony\Component\Form\Extension\Templating;
|
||||||
|
|
||||||
use Symfony\Component\Form\AbstractExtension;
|
use Symfony\Component\Form\AbstractExtension;
|
||||||
use Symfony\Component\Form\Exception\UnexpectedTypeException;
|
|
||||||
use Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderAdapter;
|
|
||||||
use Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderInterface;
|
|
||||||
use Symfony\Component\Form\FormRenderer;
|
use Symfony\Component\Form\FormRenderer;
|
||||||
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
|
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
|
||||||
use Symfony\Component\Templating\PhpEngine;
|
use Symfony\Component\Templating\PhpEngine;
|
||||||
@ -27,14 +24,8 @@ use Symfony\Bundle\FrameworkBundle\Templating\Helper\FormHelper;
|
|||||||
*/
|
*/
|
||||||
class TemplatingExtension extends AbstractExtension
|
class TemplatingExtension extends AbstractExtension
|
||||||
{
|
{
|
||||||
public function __construct(PhpEngine $engine, $csrfTokenManager = null, array $defaultThemes = array())
|
public function __construct(PhpEngine $engine, CsrfTokenManagerInterface $csrfTokenManager = null, array $defaultThemes = array())
|
||||||
{
|
{
|
||||||
if ($csrfTokenManager instanceof CsrfProviderInterface) {
|
|
||||||
$csrfTokenManager = new CsrfProviderAdapter($csrfTokenManager);
|
|
||||||
} elseif (null !== $csrfTokenManager && !$csrfTokenManager instanceof CsrfTokenManagerInterface) {
|
|
||||||
throw new UnexpectedTypeException($csrfTokenManager, 'CsrfProviderInterface or CsrfTokenManagerInterface');
|
|
||||||
}
|
|
||||||
|
|
||||||
$engine->addHelpers(array(
|
$engine->addHelpers(array(
|
||||||
new FormHelper(new FormRenderer(new TemplatingRendererEngine($engine, $defaultThemes), $csrfTokenManager)),
|
new FormHelper(new FormRenderer(new TemplatingRendererEngine($engine, $defaultThemes), $csrfTokenManager)),
|
||||||
));
|
));
|
||||||
|
@ -13,9 +13,6 @@ namespace Symfony\Component\Form;
|
|||||||
|
|
||||||
use Symfony\Component\Form\Exception\LogicException;
|
use Symfony\Component\Form\Exception\LogicException;
|
||||||
use Symfony\Component\Form\Exception\BadMethodCallException;
|
use Symfony\Component\Form\Exception\BadMethodCallException;
|
||||||
use Symfony\Component\Form\Exception\UnexpectedTypeException;
|
|
||||||
use Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderAdapter;
|
|
||||||
use Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderInterface;
|
|
||||||
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
|
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -57,17 +54,9 @@ class FormRenderer implements FormRendererInterface
|
|||||||
*
|
*
|
||||||
* @param FormRendererEngineInterface $engine
|
* @param FormRendererEngineInterface $engine
|
||||||
* @param CsrfTokenManagerInterface|null $csrfTokenManager
|
* @param CsrfTokenManagerInterface|null $csrfTokenManager
|
||||||
*
|
|
||||||
* @throws UnexpectedTypeException
|
|
||||||
*/
|
*/
|
||||||
public function __construct(FormRendererEngineInterface $engine, $csrfTokenManager = null)
|
public function __construct(FormRendererEngineInterface $engine, CsrfTokenManagerInterface $csrfTokenManager = null)
|
||||||
{
|
{
|
||||||
if ($csrfTokenManager instanceof CsrfProviderInterface) {
|
|
||||||
$csrfTokenManager = new CsrfProviderAdapter($csrfTokenManager);
|
|
||||||
} elseif (null !== $csrfTokenManager && !$csrfTokenManager instanceof CsrfTokenManagerInterface) {
|
|
||||||
throw new UnexpectedTypeException($csrfTokenManager, 'CsrfProviderInterface or CsrfTokenManagerInterface or null');
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->engine = $engine;
|
$this->engine = $engine;
|
||||||
$this->csrfTokenManager = $csrfTokenManager;
|
$this->csrfTokenManager = $csrfTokenManager;
|
||||||
}
|
}
|
||||||
|
@ -11,13 +11,10 @@
|
|||||||
|
|
||||||
namespace Symfony\Component\Security\Http\Firewall;
|
namespace Symfony\Component\Security\Http\Firewall;
|
||||||
|
|
||||||
use Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderAdapter;
|
|
||||||
use Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderInterface;
|
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
|
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
|
||||||
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
|
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
|
||||||
use Symfony\Component\Security\Core\Exception\InvalidArgumentException;
|
|
||||||
use Symfony\Component\Security\Core\Exception\LogoutException;
|
use Symfony\Component\Security\Core\Exception\LogoutException;
|
||||||
use Symfony\Component\Security\Csrf\CsrfToken;
|
use Symfony\Component\Security\Csrf\CsrfToken;
|
||||||
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
|
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
|
||||||
@ -49,19 +46,13 @@ class LogoutListener implements ListenerInterface
|
|||||||
* @param array $options An array of options to process a logout attempt
|
* @param array $options An array of options to process a logout attempt
|
||||||
* @param CsrfTokenManagerInterface $csrfTokenManager A CsrfTokenManagerInterface instance
|
* @param CsrfTokenManagerInterface $csrfTokenManager A CsrfTokenManagerInterface instance
|
||||||
*/
|
*/
|
||||||
public function __construct(TokenStorageInterface $tokenStorage, HttpUtils $httpUtils, LogoutSuccessHandlerInterface $successHandler, array $options = array(), $csrfTokenManager = null)
|
public function __construct(TokenStorageInterface $tokenStorage, HttpUtils $httpUtils, LogoutSuccessHandlerInterface $successHandler, array $options = array(), CsrfTokenManagerInterface $csrfTokenManager = null)
|
||||||
{
|
{
|
||||||
if ($csrfTokenManager instanceof CsrfProviderInterface) {
|
|
||||||
$csrfTokenManager = new CsrfProviderAdapter($csrfTokenManager);
|
|
||||||
} elseif (null !== $csrfTokenManager && !$csrfTokenManager instanceof CsrfTokenManagerInterface) {
|
|
||||||
throw new InvalidArgumentException('The CSRF token manager should be an instance of CsrfProviderInterface or CsrfTokenManagerInterface.');
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->tokenStorage = $tokenStorage;
|
$this->tokenStorage = $tokenStorage;
|
||||||
$this->httpUtils = $httpUtils;
|
$this->httpUtils = $httpUtils;
|
||||||
$this->options = array_merge(array(
|
$this->options = array_merge(array(
|
||||||
'csrf_parameter' => '_csrf_token',
|
'csrf_parameter' => '_csrf_token',
|
||||||
'intention' => 'logout',
|
'csrf_token_id' => 'logout',
|
||||||
'logout_path' => '/logout',
|
'logout_path' => '/logout',
|
||||||
), $options);
|
), $options);
|
||||||
$this->successHandler = $successHandler;
|
$this->successHandler = $successHandler;
|
||||||
@ -101,7 +92,7 @@ class LogoutListener implements ListenerInterface
|
|||||||
if (null !== $this->csrfTokenManager) {
|
if (null !== $this->csrfTokenManager) {
|
||||||
$csrfToken = ParameterBagUtils::getRequestParameterValue($request, $this->options['csrf_parameter']);
|
$csrfToken = ParameterBagUtils::getRequestParameterValue($request, $this->options['csrf_parameter']);
|
||||||
|
|
||||||
if (false === $this->csrfTokenManager->isTokenValid(new CsrfToken($this->options['intention'], $csrfToken))) {
|
if (false === $this->csrfTokenManager->isTokenValid(new CsrfToken($this->options['csrf_token_id'], $csrfToken))) {
|
||||||
throw new LogoutException('Invalid CSRF token.');
|
throw new LogoutException('Invalid CSRF token.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,10 +12,7 @@
|
|||||||
namespace Symfony\Component\Security\Http\Firewall;
|
namespace Symfony\Component\Security\Http\Firewall;
|
||||||
|
|
||||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||||
use Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderAdapter;
|
|
||||||
use Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderInterface;
|
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Symfony\Component\Security\Core\Exception\InvalidArgumentException;
|
|
||||||
use Symfony\Component\Security\Core\Exception\InvalidCsrfTokenException;
|
use Symfony\Component\Security\Core\Exception\InvalidCsrfTokenException;
|
||||||
use Symfony\Component\Security\Csrf\CsrfToken;
|
use Symfony\Component\Security\Csrf\CsrfToken;
|
||||||
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
|
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
|
||||||
@ -56,20 +53,13 @@ class SimpleFormAuthenticationListener extends AbstractAuthenticationListener
|
|||||||
* @param SimpleFormAuthenticatorInterface $simpleAuthenticator A SimpleFormAuthenticatorInterface instance
|
* @param SimpleFormAuthenticatorInterface $simpleAuthenticator A SimpleFormAuthenticatorInterface instance
|
||||||
*
|
*
|
||||||
* @throws \InvalidArgumentException In case no simple authenticator is provided
|
* @throws \InvalidArgumentException In case no simple authenticator is provided
|
||||||
* @throws InvalidArgumentException In case an invalid CSRF token manager is passed
|
|
||||||
*/
|
*/
|
||||||
public function __construct(TokenStorageInterface $tokenStorage, AuthenticationManagerInterface $authenticationManager, SessionAuthenticationStrategyInterface $sessionStrategy, HttpUtils $httpUtils, $providerKey, AuthenticationSuccessHandlerInterface $successHandler, AuthenticationFailureHandlerInterface $failureHandler, array $options = array(), LoggerInterface $logger = null, EventDispatcherInterface $dispatcher = null, $csrfTokenManager = null, SimpleFormAuthenticatorInterface $simpleAuthenticator = null)
|
public function __construct(TokenStorageInterface $tokenStorage, AuthenticationManagerInterface $authenticationManager, SessionAuthenticationStrategyInterface $sessionStrategy, HttpUtils $httpUtils, $providerKey, AuthenticationSuccessHandlerInterface $successHandler, AuthenticationFailureHandlerInterface $failureHandler, array $options = array(), LoggerInterface $logger = null, EventDispatcherInterface $dispatcher = null, CsrfTokenManagerInterface $csrfTokenManager = null, SimpleFormAuthenticatorInterface $simpleAuthenticator = null)
|
||||||
{
|
{
|
||||||
if (!$simpleAuthenticator) {
|
if (!$simpleAuthenticator) {
|
||||||
throw new \InvalidArgumentException('Missing simple authenticator');
|
throw new \InvalidArgumentException('Missing simple authenticator');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($csrfTokenManager instanceof CsrfProviderInterface) {
|
|
||||||
$csrfTokenManager = new CsrfProviderAdapter($csrfTokenManager);
|
|
||||||
} elseif (null !== $csrfTokenManager && !$csrfTokenManager instanceof CsrfTokenManagerInterface) {
|
|
||||||
throw new InvalidArgumentException('The CSRF token manager should be an instance of CsrfProviderInterface or CsrfTokenManagerInterface.');
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->simpleAuthenticator = $simpleAuthenticator;
|
$this->simpleAuthenticator = $simpleAuthenticator;
|
||||||
$this->csrfTokenManager = $csrfTokenManager;
|
$this->csrfTokenManager = $csrfTokenManager;
|
||||||
|
|
||||||
@ -77,7 +67,7 @@ class SimpleFormAuthenticationListener extends AbstractAuthenticationListener
|
|||||||
'username_parameter' => '_username',
|
'username_parameter' => '_username',
|
||||||
'password_parameter' => '_password',
|
'password_parameter' => '_password',
|
||||||
'csrf_parameter' => '_csrf_token',
|
'csrf_parameter' => '_csrf_token',
|
||||||
'intention' => 'authenticate',
|
'csrf_token_id' => 'authenticate',
|
||||||
'post_only' => true,
|
'post_only' => true,
|
||||||
), $options);
|
), $options);
|
||||||
|
|
||||||
@ -104,7 +94,7 @@ class SimpleFormAuthenticationListener extends AbstractAuthenticationListener
|
|||||||
if (null !== $this->csrfTokenManager) {
|
if (null !== $this->csrfTokenManager) {
|
||||||
$csrfToken = ParameterBagUtils::getRequestParameterValue($request, $this->options['csrf_parameter']);
|
$csrfToken = ParameterBagUtils::getRequestParameterValue($request, $this->options['csrf_parameter']);
|
||||||
|
|
||||||
if (false === $this->csrfTokenManager->isTokenValid(new CsrfToken($this->options['intention'], $csrfToken))) {
|
if (false === $this->csrfTokenManager->isTokenValid(new CsrfToken($this->options['csrf_token_id'], $csrfToken))) {
|
||||||
throw new InvalidCsrfTokenException('Invalid CSRF token.');
|
throw new InvalidCsrfTokenException('Invalid CSRF token.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,8 +11,6 @@
|
|||||||
|
|
||||||
namespace Symfony\Component\Security\Http\Firewall;
|
namespace Symfony\Component\Security\Http\Firewall;
|
||||||
|
|
||||||
use Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderAdapter;
|
|
||||||
use Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderInterface;
|
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
use Symfony\Component\Security\Csrf\CsrfToken;
|
use Symfony\Component\Security\Csrf\CsrfToken;
|
||||||
@ -25,7 +23,6 @@ use Symfony\Component\Security\Http\HttpUtils;
|
|||||||
use Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface;
|
use Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface;
|
||||||
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
|
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
|
||||||
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
|
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
|
||||||
use Symfony\Component\Security\Core\Exception\InvalidArgumentException;
|
|
||||||
use Symfony\Component\Security\Core\Exception\InvalidCsrfTokenException;
|
use Symfony\Component\Security\Core\Exception\InvalidCsrfTokenException;
|
||||||
use Symfony\Component\Security\Core\Security;
|
use Symfony\Component\Security\Core\Security;
|
||||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||||
@ -40,19 +37,13 @@ class UsernamePasswordFormAuthenticationListener extends AbstractAuthenticationL
|
|||||||
{
|
{
|
||||||
private $csrfTokenManager;
|
private $csrfTokenManager;
|
||||||
|
|
||||||
public function __construct(TokenStorageInterface $tokenStorage, AuthenticationManagerInterface $authenticationManager, SessionAuthenticationStrategyInterface $sessionStrategy, HttpUtils $httpUtils, $providerKey, AuthenticationSuccessHandlerInterface $successHandler, AuthenticationFailureHandlerInterface $failureHandler, array $options = array(), LoggerInterface $logger = null, EventDispatcherInterface $dispatcher = null, $csrfTokenManager = null)
|
public function __construct(TokenStorageInterface $tokenStorage, AuthenticationManagerInterface $authenticationManager, SessionAuthenticationStrategyInterface $sessionStrategy, HttpUtils $httpUtils, $providerKey, AuthenticationSuccessHandlerInterface $successHandler, AuthenticationFailureHandlerInterface $failureHandler, array $options = array(), LoggerInterface $logger = null, EventDispatcherInterface $dispatcher = null, CsrfTokenManagerInterface $csrfTokenManager = null)
|
||||||
{
|
{
|
||||||
if ($csrfTokenManager instanceof CsrfProviderInterface) {
|
|
||||||
$csrfTokenManager = new CsrfProviderAdapter($csrfTokenManager);
|
|
||||||
} elseif (null !== $csrfTokenManager && !$csrfTokenManager instanceof CsrfTokenManagerInterface) {
|
|
||||||
throw new InvalidArgumentException('The CSRF token manager should be an instance of CsrfProviderInterface or CsrfTokenManagerInterface.');
|
|
||||||
}
|
|
||||||
|
|
||||||
parent::__construct($tokenStorage, $authenticationManager, $sessionStrategy, $httpUtils, $providerKey, $successHandler, $failureHandler, array_merge(array(
|
parent::__construct($tokenStorage, $authenticationManager, $sessionStrategy, $httpUtils, $providerKey, $successHandler, $failureHandler, array_merge(array(
|
||||||
'username_parameter' => '_username',
|
'username_parameter' => '_username',
|
||||||
'password_parameter' => '_password',
|
'password_parameter' => '_password',
|
||||||
'csrf_parameter' => '_csrf_token',
|
'csrf_parameter' => '_csrf_token',
|
||||||
'intention' => 'authenticate',
|
'csrf_token_id' => 'authenticate',
|
||||||
'post_only' => true,
|
'post_only' => true,
|
||||||
), $options), $logger, $dispatcher);
|
), $options), $logger, $dispatcher);
|
||||||
|
|
||||||
@ -79,7 +70,7 @@ class UsernamePasswordFormAuthenticationListener extends AbstractAuthenticationL
|
|||||||
if (null !== $this->csrfTokenManager) {
|
if (null !== $this->csrfTokenManager) {
|
||||||
$csrfToken = ParameterBagUtils::getRequestParameterValue($request, $this->options['csrf_parameter']);
|
$csrfToken = ParameterBagUtils::getRequestParameterValue($request, $this->options['csrf_parameter']);
|
||||||
|
|
||||||
if (false === $this->csrfTokenManager->isTokenValid(new CsrfToken($this->options['intention'], $csrfToken))) {
|
if (false === $this->csrfTokenManager->isTokenValid(new CsrfToken($this->options['csrf_token_id'], $csrfToken))) {
|
||||||
throw new InvalidCsrfTokenException('Invalid CSRF token.');
|
throw new InvalidCsrfTokenException('Invalid CSRF token.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,8 +11,6 @@
|
|||||||
|
|
||||||
namespace Symfony\Component\Security\Http\Logout;
|
namespace Symfony\Component\Security\Http\Logout;
|
||||||
|
|
||||||
use Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderAdapter;
|
|
||||||
use Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderInterface;
|
|
||||||
use Symfony\Component\HttpFoundation\RequestStack;
|
use Symfony\Component\HttpFoundation\RequestStack;
|
||||||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
||||||
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
|
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
|
||||||
@ -47,14 +45,8 @@ class LogoutUrlGenerator
|
|||||||
* @param string $csrfParameter The CSRF token parameter name
|
* @param string $csrfParameter The CSRF token parameter name
|
||||||
* @param CsrfTokenManagerInterface $csrfTokenManager A CsrfTokenManagerInterface instance
|
* @param CsrfTokenManagerInterface $csrfTokenManager A CsrfTokenManagerInterface instance
|
||||||
*/
|
*/
|
||||||
public function registerListener($key, $logoutPath, $csrfTokenId, $csrfParameter, $csrfTokenManager = null)
|
public function registerListener($key, $logoutPath, $csrfTokenId, $csrfParameter, CsrfTokenManagerInterface $csrfTokenManager = null)
|
||||||
{
|
{
|
||||||
if ($csrfTokenManager instanceof CsrfProviderInterface) {
|
|
||||||
$csrfTokenManager = new CsrfProviderAdapter($csrfTokenManager);
|
|
||||||
} elseif (null !== $csrfTokenManager && !$csrfTokenManager instanceof CsrfTokenManagerInterface) {
|
|
||||||
throw new \InvalidArgumentException('The CSRF token manager should be an instance of CsrfProviderInterface or CsrfTokenManagerInterface.');
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->listeners[$key] = array($logoutPath, $csrfTokenId, $csrfParameter, $csrfTokenManager);
|
$this->listeners[$key] = array($logoutPath, $csrfTokenId, $csrfParameter, $csrfTokenManager);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -213,7 +213,7 @@ class LogoutListenerTest extends \PHPUnit_Framework_TestCase
|
|||||||
$successHandler ?: $this->getSuccessHandler(),
|
$successHandler ?: $this->getSuccessHandler(),
|
||||||
$options = array(
|
$options = array(
|
||||||
'csrf_parameter' => '_csrf_token',
|
'csrf_parameter' => '_csrf_token',
|
||||||
'intention' => 'logout',
|
'csrf_token_id' => 'logout',
|
||||||
'logout_path' => '/logout',
|
'logout_path' => '/logout',
|
||||||
'target_url' => '/',
|
'target_url' => '/',
|
||||||
),
|
),
|
||||||
|
Reference in New Issue
Block a user