|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* TPermission.php |
|
4
|
|
|
* |
|
5
|
|
|
* @copyright More in license.md |
|
6
|
|
|
* @license http://www.ipublikuj.eu |
|
7
|
|
|
* @author Adam Kadlec http://www.ipublikuj.eu |
|
8
|
|
|
* @package iPublikuj:Permissions! |
|
9
|
|
|
* @subpackage common |
|
10
|
|
|
* @since 1.0.0 |
|
11
|
|
|
* |
|
12
|
|
|
* @date 13.10.14 |
|
13
|
|
|
*/ |
|
14
|
|
|
|
|
15
|
|
|
namespace IPub\Permissions; |
|
16
|
|
|
|
|
17
|
|
|
use Nette; |
|
18
|
|
|
use Nette\Application; |
|
19
|
|
|
|
|
20
|
|
|
use IPub; |
|
21
|
|
|
use IPub\Permissions\Security; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Helper trait |
|
25
|
|
|
* |
|
26
|
|
|
* @package iPublikuj:Permissions! |
|
27
|
|
|
* @subpackage common |
|
28
|
|
|
* |
|
29
|
|
|
* @author Adam Kadlec <[email protected]> |
|
30
|
|
|
*/ |
|
31
|
1 |
|
trait TPermission |
|
32
|
|
|
{ |
|
33
|
|
|
/** |
|
34
|
|
|
* @var Configuration |
|
35
|
|
|
*/ |
|
36
|
|
|
protected $permissionConfiguration; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @var Access\ICheckRequirements |
|
40
|
|
|
*/ |
|
41
|
|
|
protected $requirementsChecker; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @param Access\ICheckRequirements $requirementsChecker |
|
45
|
|
|
* @param Configuration $configuration |
|
46
|
|
|
*/ |
|
47
|
|
|
public function injectPermission( |
|
48
|
|
|
Access\ICheckRequirements $requirementsChecker, |
|
49
|
|
|
Configuration $configuration |
|
50
|
|
|
) { |
|
51
|
1 |
|
$this->requirementsChecker = $requirementsChecker; |
|
52
|
1 |
|
$this->permissionConfiguration = $configuration; |
|
53
|
1 |
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @param $element |
|
57
|
|
|
* |
|
58
|
|
|
* @throws Application\ForbiddenRequestException |
|
59
|
|
|
*/ |
|
60
|
|
|
public function checkRequirements($element) |
|
61
|
|
|
{ |
|
62
|
1 |
|
$redirectUrl = $this->permissionConfiguration->getRedirectUrl([ |
|
|
|
|
|
|
63
|
1 |
|
'backlink' => $this->storeRequest(), |
|
|
|
|
|
|
64
|
|
|
]); |
|
65
|
|
|
|
|
66
|
|
|
try { |
|
67
|
1 |
|
parent::checkRequirements($element); |
|
68
|
|
|
|
|
69
|
1 |
|
if (!$this->requirementsChecker->isAllowed($element)) { |
|
70
|
1 |
|
throw new Application\ForbiddenRequestException; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
1 |
|
} catch (Application\ForbiddenRequestException $ex) { |
|
74
|
|
|
/* |
|
|
|
|
|
|
75
|
|
|
if ($redirectUrl) { |
|
76
|
|
|
$this->getPresenter()->redirectUrl($redirectUrl); |
|
77
|
|
|
|
|
78
|
|
|
} else { |
|
79
|
|
|
*/ |
|
80
|
1 |
|
throw $ex; |
|
81
|
|
|
/* |
|
82
|
|
|
} |
|
83
|
|
|
*/ |
|
84
|
|
|
} |
|
85
|
1 |
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.