|
1
|
|
|
<?php |
|
2
|
|
|
namespace Aoe\Restler\Controller; |
|
3
|
|
|
|
|
4
|
|
|
/*************************************************************** |
|
5
|
|
|
* Copyright notice |
|
6
|
|
|
* |
|
7
|
|
|
* (c) 2021 AOE GmbH <[email protected]> |
|
8
|
|
|
* |
|
9
|
|
|
* All rights reserved |
|
10
|
|
|
* |
|
11
|
|
|
* This script is part of the TYPO3 project. The TYPO3 project is |
|
12
|
|
|
* free software; you can redistribute it and/or modify |
|
13
|
|
|
* it under the terms of the GNU General Public License as published by |
|
14
|
|
|
* the Free Software Foundation; either version 3 of the License, or |
|
15
|
|
|
* (at your option) any later version. |
|
16
|
|
|
* |
|
17
|
|
|
* The GNU General Public License can be found at |
|
18
|
|
|
* http://www.gnu.org/copyleft/gpl.html. |
|
19
|
|
|
* |
|
20
|
|
|
* This script is distributed in the hope that it will be useful, |
|
21
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
22
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
23
|
|
|
* GNU General Public License for more details. |
|
24
|
|
|
* |
|
25
|
|
|
* This copyright notice MUST APPEAR in all copies of the script! |
|
26
|
|
|
***************************************************************/ |
|
27
|
|
|
|
|
28
|
|
|
use Aoe\Restler\System\TYPO3\Loader as TYPO3Loader; |
|
29
|
|
|
use Luracast\Restler\iAuthenticate; |
|
30
|
|
|
use Luracast\Restler\Restler; |
|
31
|
|
|
use Luracast\Restler\Scope; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* This class checks, if client is allowed to access the requested and protected API-class |
|
35
|
|
|
* This class checks, if FE-user is logged in |
|
36
|
|
|
*/ |
|
37
|
|
|
class FeUserAuthenticationController implements iAuthenticate |
|
38
|
|
|
{ |
|
39
|
|
|
/** |
|
40
|
|
|
* This property defines (when it's set), the argument-name, which contains the pageId, |
|
41
|
|
|
* which should be used to initialize TYPO3 |
|
42
|
|
|
* This property will be automatically set by restler, when in |
|
43
|
|
|
* the API-class/controller this is configured (in PHPdoc/annotations) |
|
44
|
|
|
* |
|
45
|
|
|
* Where do we set this property? |
|
46
|
|
|
* When the property should be used, than it must be set inside the PHPdoc-comment of |
|
47
|
|
|
* the API-class-method, which handle the API-request |
|
48
|
|
|
* |
|
49
|
|
|
* Syntax: |
|
50
|
|
|
* The PHPdoc-comment must look like this: |
|
51
|
|
|
* @class [className] {@[propertyName] [propertyValue]} |
|
52
|
|
|
* |
|
53
|
|
|
* Example: |
|
54
|
|
|
* When this controller should use a specific pageId while initializing TYPO3 (this is needed, when we want to |
|
55
|
|
|
* render TYPO3-contentElements, after the user is authenticated), than the PHPdoc-comment must look like this: |
|
56
|
|
|
* @class Aoe\Restler\Controller\FeUserAuthenticationController {@argumentNameOfPageId pageId} |
|
57
|
|
|
* |
|
58
|
|
|
* @see \Aoe\RestlerExamples\Controller\ContentController::getContentElementByUidForLoggedInFeUser |
|
59
|
|
|
* |
|
60
|
|
|
* @var string |
|
61
|
|
|
*/ |
|
62
|
|
|
public $argumentNameOfPageId = ''; |
|
63
|
|
|
/** |
|
64
|
|
|
* This property defines (when it's set), that this controller should check authentication |
|
65
|
|
|
* This property will be automatically set by restler, when in the API-class/controller this |
|
66
|
|
|
* is configured (in PHPdoc/annotations) |
|
67
|
|
|
* |
|
68
|
|
|
* Where do we set this property? |
|
69
|
|
|
* When the property should be used, than it must be set inside the PHPdoc-comment of the API-class-method, |
|
70
|
|
|
* which handle the API-request |
|
71
|
|
|
* |
|
72
|
|
|
* Syntax: |
|
73
|
|
|
* The PHPdoc-comment must look like this: |
|
74
|
|
|
* @class [className] {@[propertyName] [propertyValue]} |
|
75
|
|
|
* |
|
76
|
|
|
* Example: |
|
77
|
|
|
* When this controller should be used for authentication-checks, than the PHPdoc-comment must look like this: |
|
78
|
|
|
* @class Aoe\Restler\Controller\FeUserAuthenticationController {@checkAuthentication true} |
|
79
|
|
|
* |
|
80
|
|
|
* @see \Aoe\RestlerExamples\Controller\FeUserController::getDataOfLoggedInFeUser |
|
81
|
|
|
* @see \Aoe\RestlerExamples\Controller\ContentController::getContentElementByUidForLoggedInFeUser |
|
82
|
|
|
* |
|
83
|
|
|
* @var boolean |
|
84
|
|
|
*/ |
|
85
|
|
|
public $checkAuthentication = false; |
|
86
|
|
|
/** |
|
87
|
|
|
* @var TYPO3Loader |
|
88
|
|
|
*/ |
|
89
|
|
|
private $typo3Loader; |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* @var Restler |
|
93
|
|
|
*/ |
|
94
|
|
|
private $restler; |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* @param TYPO3Loader $typo3Loader |
|
98
|
|
|
*/ |
|
99
|
6 |
|
public function __construct(TYPO3Loader $typo3Loader) |
|
100
|
|
|
{ |
|
101
|
6 |
|
$this->typo3Loader = $typo3Loader; |
|
102
|
6 |
|
$this->restler = Scope::get('Restler'); |
|
103
|
6 |
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* This method checks, if client is allowed to access the requested API-class |
|
107
|
|
|
* |
|
108
|
|
|
* @return boolean |
|
109
|
|
|
*/ |
|
110
|
3 |
|
public function __isAllowed() |
|
111
|
|
|
{ |
|
112
|
3 |
|
if ($this->checkAuthentication !== true) { |
|
113
|
|
|
// this controller is not responsible for the authentication |
|
114
|
1 |
|
return false; |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
2 |
|
$this->typo3Loader->initializeFrontendUser($this->determinePageId()); |
|
118
|
|
|
|
|
119
|
2 |
|
return $this->typo3Loader->hasActiveFrontendUser(); |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
/** |
|
123
|
|
|
* return dummy string, because we DON'T need that for our case (we use NO base-authentification via REST-API) |
|
124
|
|
|
* |
|
125
|
|
|
* @return string |
|
126
|
|
|
* @see \Luracast\Restler\iAuthenticate |
|
127
|
|
|
*/ |
|
128
|
1 |
|
public function __getWWWAuthenticateString() |
|
129
|
|
|
{ |
|
130
|
1 |
|
return ''; |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
/** |
|
134
|
|
|
* List of page IDs (comma separated) or page ID where to look for frontend user records |
|
135
|
|
|
* |
|
136
|
|
|
* @return string |
|
137
|
|
|
*/ |
|
138
|
2 |
|
private function determinePageId() |
|
139
|
|
|
{ |
|
140
|
2 |
|
if (false === empty($this->argumentNameOfPageId)) { |
|
141
|
2 |
|
return $this->argumentNameOfPageId; |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
return $this->determinePageIdFromArguments(); |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
/** |
|
148
|
|
|
* determine pageId from arguments, which restler has detected |
|
149
|
|
|
* We need the pageId, when we want to render TYPO3-contentElements, after the user is authenticated |
|
150
|
|
|
* |
|
151
|
|
|
* @return string |
|
152
|
|
|
*/ |
|
153
|
2 |
|
private function determinePageIdFromArguments() |
|
154
|
|
|
{ |
|
155
|
2 |
|
if (false === array_key_exists($this->argumentNameOfPageId, $this->restler->apiMethodInfo->arguments)) { |
|
156
|
1 |
|
return '0'; |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
1 |
|
$index = $this->restler->apiMethodInfo->arguments[$this->argumentNameOfPageId]; |
|
160
|
1 |
|
return $this->restler->apiMethodInfo->parameters[$index]; |
|
161
|
|
|
} |
|
162
|
|
|
} |
|
163
|
|
|
|