Skip to content

Navigation Menu

Sign in
Appearance settings

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 6d4c810

Browse filesBrowse files
committed
[Worflow] Fixed GuardListener when using the new Security system
1 parent b604fd7 commit 6d4c810
Copy full SHA for 6d4c810

File tree

Expand file treeCollapse file tree

4 files changed

+33
-6
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+33
-6
lines changed

‎src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/WorkflowGuardListenerPass.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/WorkflowGuardListenerPass.php
+13-2Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@ class WorkflowGuardListenerPass implements CompilerPassInterface
2626
*/
2727
public function process(ContainerBuilder $container)
2828
{
29-
if (!$container->hasParameter('workflow.has_guard_listeners')) {
29+
if (!$container->hasParameter('workflow.guard_definition_id')) {
3030
return;
3131
}
3232

33-
$container->getParameterBag()->remove('workflow.has_guard_listeners');
33+
$guardDefinitionIds = $container->getParameter('workflow.guard_definition_id');
34+
35+
$container->getParameterBag()->remove('workflow.guard_definition_id');
3436

3537
$servicesNeeded = [
3638
'security.token_storage',
@@ -44,5 +46,14 @@ public function process(ContainerBuilder $container)
4446
throw new LogicException(sprintf('The "%s" service is needed to be able to use the workflow guard listener.', $service));
4547
}
4648
}
49+
50+
if ($container->hasParameter('security.enable_authenticator_manager') && $container->getParameter('security.enable_authenticator_manager')) {
51+
foreach ($guardDefinitionIds as $guardDefinitionId) {
52+
$container
53+
->getDefinition($guardDefinitionId)
54+
->replaceArgument(7, true)
55+
;
56+
}
57+
}
4758
}
4859
}

‎src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
+7-2Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,7 @@ private function registerWorkflowConfiguration(array $config, ContainerBuilder $
704704
$loader->load('workflow.php');
705705

706706
$registryDefinition = $container->getDefinition('workflow.registry');
707+
$guardDefinitionIds = [];
707708

708709
foreach ($config['workflows'] as $name => $workflow) {
709710
$type = $workflow['type'];
@@ -874,15 +875,19 @@ private function registerWorkflowConfiguration(array $config, ContainerBuilder $
874875
new Reference('security.authentication.trust_resolver'),
875876
new Reference('security.role_hierarchy'),
876877
new Reference('validator', ContainerInterface::NULL_ON_INVALID_REFERENCE),
878+
false,
877879
]);
878880
foreach ($guardsConfiguration as $eventName => $config) {
879881
$guard->addTag('kernel.event_listener', ['event' => $eventName, 'method' => 'onTransition']);
880882
}
881883

882-
$container->setDefinition(sprintf('.%s.listener.guard', $workflowId), $guard);
883-
$container->setParameter('workflow.has_guard_listeners', true);
884+
$container->setDefinition($guardDefinitionIds[] = sprintf('.%s.listener.guard', $workflowId), $guard);
884885
}
885886
}
887+
888+
if ($guardDefinitionIds) {
889+
$container->setParameter('workflow.guard_definition_id', $guardDefinitionIds);
890+
}
886891
}
887892

888893
private function registerDebugConfiguration(array $config, ContainerBuilder $container, PhpFileLoader $loader)

‎src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ public function load(array $configs, ContainerBuilder $container)
111111
$loader->load('security_rememberme.php');
112112

113113
if ($this->authenticatorManagerEnabled = $config['enable_authenticator_manager']) {
114+
$container->setParameter('security.enable_authenticator_manager', true);
115+
114116
if ($config['always_authenticate_before_granting']) {
115117
throw new InvalidConfigurationException('The security option "always_authenticate_before_granting" cannot be used when "enable_authenticator_manager" is set to true. If you rely on this behavior, set it to false.');
116118
}

‎src/Symfony/Component/Workflow/EventListener/GuardListener.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Workflow/EventListener/GuardListener.php
+11-2Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Workflow\EventListener;
1313

1414
use Symfony\Component\Security\Core\Authentication\AuthenticationTrustResolverInterface;
15+
use Symfony\Component\Security\Core\Authentication\Token\NullToken;
1516
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
1617
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
1718
use Symfony\Component\Security\Core\Role\RoleHierarchyInterface;
@@ -32,8 +33,9 @@ class GuardListener
3233
private $trustResolver;
3334
private $roleHierarchy;
3435
private $validator;
36+
private $useAuthenticatorManager;
3537

36-
public function __construct(array $configuration, ExpressionLanguage $expressionLanguage, TokenStorageInterface $tokenStorage, AuthorizationCheckerInterface $authorizationChecker, AuthenticationTrustResolverInterface $trustResolver, RoleHierarchyInterface $roleHierarchy = null, ValidatorInterface $validator = null)
38+
public function __construct(array $configuration, ExpressionLanguage $expressionLanguage, TokenStorageInterface $tokenStorage, AuthorizationCheckerInterface $authorizationChecker, AuthenticationTrustResolverInterface $trustResolver, RoleHierarchyInterface $roleHierarchy = null, ValidatorInterface $validator = null, bool $useAuthenticatorManager = false)
3739
{
3840
$this->configuration = $configuration;
3941
$this->expressionLanguage = $expressionLanguage;
@@ -42,6 +44,7 @@ public function __construct(array $configuration, ExpressionLanguage $expression
4244
$this->trustResolver = $trustResolver;
4345
$this->roleHierarchy = $roleHierarchy;
4446
$this->validator = $validator;
47+
$this->useAuthenticatorManager = $useAuthenticatorManager;
4548
}
4649

4750
public function onTransition(GuardEvent $event, string $eventName)
@@ -77,7 +80,13 @@ private function getVariables(GuardEvent $event): array
7780
$token = $this->tokenStorage->getToken();
7881

7982
if (null === $token) {
80-
throw new InvalidTokenConfigurationException(sprintf('There are no tokens available for workflow "%s".', $event->getWorkflowName()));
83+
if (!$this->useAuthenticatorManager) {
84+
throw new InvalidTokenConfigurationException(sprintf('There are no tokens available for workflow "%s".', $event->getWorkflowName()));
85+
}
86+
if (!class_exists(NullToken::class)) {
87+
throw new \LogicException('The workflow guard feature is not compatible when "security.enable_authenticator_manager" is set to true with until 5.2.1.');
88+
}
89+
$token = new NullToken();
8190
}
8291

8392
$variables = [

0 commit comments

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