Skip to content

Commit 504f265

Browse files
committed
Merge branch '3.4'
* 3.4: (26 commits) bumped Symfony version to 3.3.11 updated VERSION for 3.3.10 updated CHANGELOG for 3.3.10 bumped Symfony version to 2.8.29 updated VERSION for 2.8.28 updated CHANGELOG for 2.8.28 bumped Symfony version to 2.7.36 updated VERSION for 2.7.35 update CONTRIBUTORS for 2.7.35 updated CHANGELOG for 2.7.35 Added deprecation to cwd not existing Fixes #18249 [Session] fix MongoDb session handler to gc all expired sessions Add changelog for deprecated DbalSessionHandler [Security] Look at headers for switch user username parameter Updated Test name and exception name to be more accurate newline at end of file changed exception message Ahh, I see. It actually wants a newline! Removed newline Created new Exception to throw and modified tests. ...
2 parents a00da8f + c6e057f commit 504f265

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

EventListener/GuardListener.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
1717
use Symfony\Component\Security\Core\Role\RoleHierarchyInterface;
1818
use Symfony\Component\Workflow\Event\GuardEvent;
19+
use Symfony\Component\Workflow\Exception\InvalidTokenConfigurationException;
1920

2021
/**
2122
* @author Grégoire Pineau <lyrixx@lyrixx.info>
@@ -55,6 +56,10 @@ private function getVariables(GuardEvent $event): array
5556
{
5657
$token = $this->tokenStorage->getToken();
5758

59+
if (null === $token) {
60+
throw new InvalidTokenConfigurationException(sprintf('There are no tokens available for workflow %s.', $event->getWorkflowName()));
61+
}
62+
5863
if (null !== $this->roleHierarchy) {
5964
$roles = $this->roleHierarchy->getReachableRoles($token->getRoles());
6065
} else {
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Workflow\Exception;
13+
14+
/**
15+
* Thrown by GuardListener when there is no token set, but guards are placed on a transition.
16+
*
17+
* @author Matt Johnson <matj1985@gmail.com>
18+
*/
19+
class InvalidTokenConfigurationException extends LogicException implements ExceptionInterface
20+
{
21+
}

Tests/EventListener/GuardListenerTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,18 @@ public function testWithSupportedEventAndAccept()
6969
$this->assertTrue($event->isBlocked());
7070
}
7171

72+
/**
73+
* @expectedException \Symfony\Component\Workflow\Exception\InvalidTokenConfigurationException
74+
* @expectedExceptionMessage There are no tokens available for workflow unnamed.
75+
*/
76+
public function testWithNoTokensInTokenStorage()
77+
{
78+
$event = $this->createEvent();
79+
$this->tokenStorage->setToken(null);
80+
81+
$this->listener->onTransition($event, 'event_name_a');
82+
}
83+
7284
private function createEvent()
7385
{
7486
$subject = new \stdClass();

0 commit comments

Comments
 (0)