|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the core-bundle package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) 2018 WEBEWEB |
|
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 WBW\Bundle\CoreBundle\Exception; |
|
13
|
|
|
|
|
14
|
|
|
use Symfony\Component\Security\Core\User\UserInterface; |
|
15
|
|
|
use WBW\Bundle\CoreBundle\Helper\UserHelper; |
|
16
|
|
|
use WBW\Bundle\CoreBundle\Security\Core\User\UserTrait; |
|
17
|
|
|
use WBW\Library\Traits\Strings\ArrayRolesTrait; |
|
18
|
|
|
use WBW\Library\Traits\Strings\StringOriginUrlTrait; |
|
19
|
|
|
use WBW\Library\Traits\Strings\StringRedirectUrlTrait; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Bad user role exception. |
|
23
|
|
|
* |
|
24
|
|
|
* @author webeweb <https://github.com/webeweb> |
|
25
|
|
|
* @package WBW\Bundle\CoreBundle\Exception |
|
26
|
|
|
*/ |
|
27
|
1 |
|
class BadUserRoleException extends AbstractException { |
|
28
|
1 |
|
|
|
29
|
1 |
|
use ArrayRolesTrait; |
|
30
|
|
|
use StringOriginUrlTrait; |
|
31
|
|
|
use StringRedirectUrlTrait; |
|
32
|
|
|
use UserTrait; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Constructor. |
|
36
|
|
|
* |
|
37
|
|
|
* @param UserInterface $user The user. |
|
38
|
|
|
* @param array $roles The roles. |
|
39
|
|
|
* @param string $redirectUrl The redirect. |
|
40
|
|
|
* @param string $originUrl The route. |
|
41
|
|
|
*/ |
|
42
|
|
|
public function __construct(UserInterface $user, array $roles, string $redirectUrl, string $originUrl) { |
|
43
|
|
|
|
|
44
|
|
|
$format = 'User "%s" is not allowed to access to "%s" with roles [%s]'; |
|
45
|
|
|
$message = sprintf($format, UserHelper::getIdentifier($user), $originUrl, implode(",", $roles)); |
|
46
|
30 |
|
|
|
47
|
30 |
|
parent::__construct($message, 403); |
|
48
|
30 |
|
|
|
49
|
30 |
|
$this->setOriginUrl($originUrl); |
|
50
|
30 |
|
$this->setRedirectUrl($redirectUrl); |
|
51
|
30 |
|
$this->setRoles($roles); |
|
52
|
30 |
|
$this->setUser($user); |
|
53
|
30 |
|
} |
|
54
|
|
|
} |
|
55
|
|
|
|