| 1 | <?php |
||
| 2 | namespace EWW\Dpf\Security; |
||
| 3 | |||
| 4 | /* |
||
| 5 | * This file is part of the TYPO3 CMS project. |
||
| 6 | * |
||
| 7 | * It is free software; you can redistribute it and/or modify it under |
||
| 8 | * the terms of the GNU General Public License, either version 2 |
||
| 9 | * of the License, or any later version. |
||
| 10 | * |
||
| 11 | * For the full copyright and license information, please read the |
||
| 12 | * LICENSE.txt file that was distributed with this source code. |
||
| 13 | * |
||
| 14 | * The TYPO3 project - inspiring people to share! |
||
| 15 | */ |
||
| 16 | |||
| 17 | |||
| 18 | class AuthorizationChecker |
||
| 19 | { |
||
| 20 | /** |
||
| 21 | * objectManager |
||
| 22 | * |
||
| 23 | * @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface |
||
| 24 | * @TYPO3\CMS\Extbase\Annotation\Inject |
||
| 25 | */ |
||
| 26 | protected $objectManager; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * security |
||
| 30 | * |
||
| 31 | * @var \EWW\Dpf\Security\Security |
||
| 32 | * @TYPO3\CMS\Extbase\Annotation\Inject |
||
| 33 | */ |
||
| 34 | protected $security = null; |
||
| 35 | |||
| 36 | public function denyAccessUnlessLoggedIn() |
||
| 37 | { |
||
| 38 | $security = $this->objectManager->get(\EWW\Dpf\Security\Security::class); |
||
|
0 ignored issues
–
show
Unused Code
introduced
by
Loading history...
|
|||
| 39 | |||
| 40 | if ( |
||
| 41 | $this->security->getUserRole() === Security::ROLE_LIBRARIAN || |
||
| 42 | $this->security->getUserRole() === Security::ROLE_RESEARCHER |
||
| 43 | ) { |
||
| 44 | return; |
||
| 45 | } else { |
||
| 46 | header('Temporary-Header: True', true, 403); |
||
| 47 | header_remove('Temporary-Header'); |
||
| 48 | $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:error.access_denied'; |
||
| 49 | $accessDeniedMessage = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate($key, 'dpf'); |
||
| 50 | die($accessDeniedMessage); |
||
|
0 ignored issues
–
show
|
|||
| 51 | } |
||
| 52 | } |
||
| 53 | |||
| 54 | public function denyAccessUnlessGranted($attribute, $subject = NULL) |
||
| 55 | { |
||
| 56 | if($this->isGranted($attribute, $subject)) { |
||
| 57 | return; |
||
| 58 | } else { |
||
| 59 | header('Temporary-Header: True', true, 403); |
||
| 60 | header_remove('Temporary-Header'); |
||
| 61 | $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:error.access_denied'; |
||
| 62 | $accessDeniedMessage = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate($key, 'dpf'); |
||
| 63 | die($accessDeniedMessage); |
||
|
0 ignored issues
–
show
|
|||
| 64 | } |
||
| 65 | } |
||
| 66 | |||
| 67 | |||
| 68 | /** |
||
| 69 | * @param string $attribute |
||
| 70 | * @param object $subject |
||
| 71 | * @return bool |
||
| 72 | */ |
||
| 73 | public function isGranted($attribute, $subject = NULL) { |
||
| 74 | $voters = Voter::getVoters(); |
||
| 75 | |||
| 76 | foreach ($voters as $voter) { |
||
| 77 | if ($voter->supports($attribute, $subject)) { |
||
| 78 | return $voter->voteOnAttribute($attribute, $subject); |
||
| 79 | } |
||
| 80 | } |
||
| 81 | |||
| 82 | return FALSE; |
||
| 83 | } |
||
| 84 | |||
| 85 | } |