1 | <?php |
||
39 | class EnvCheckMiddleware extends CheckMiddleware { |
||
40 | |||
41 | /** @var IHasher */ |
||
42 | private $hasher; |
||
43 | /** @var ISession */ |
||
44 | private $session; |
||
45 | /** @var Environment */ |
||
46 | private $environment; |
||
47 | /** @var IControllerMethodReflector */ |
||
48 | protected $reflector; |
||
49 | |||
50 | /*** |
||
51 | * Constructor |
||
52 | * |
||
53 | * @param string $appName |
||
54 | * @param IRequest $request |
||
55 | * @param IHasher $hasher |
||
56 | * @param ISession $session |
||
57 | * @param Environment $environment |
||
58 | * @param IControllerMethodReflector $reflector |
||
59 | * @param IURLGenerator $urlGenerator |
||
60 | * @param ILogger $logger |
||
61 | */ |
||
62 | 56 | public function __construct( |
|
84 | |||
85 | /** |
||
86 | * Checks that we have a valid token linked to a valid resource and that the |
||
87 | * user is authorised to access it |
||
88 | * |
||
89 | * Inspects the controller method annotations and if PublicPage is found |
||
90 | * it checks that we have a token and an optional password giving access to a valid resource. |
||
91 | * Once that's done, the environment is setup so that our services can find the resources they |
||
92 | * need. |
||
93 | * |
||
94 | * The checks are not performed on "guest" pages and the environment is not setup. Typical |
||
95 | * guest pages are anonymous error ages |
||
96 | * |
||
97 | * @inheritDoc |
||
98 | */ |
||
99 | 31 | public function beforeController($controller, $methodName) { |
|
110 | |||
111 | /** |
||
112 | * Checks that we have a token and an optional password giving access to a |
||
113 | * valid resource. Sets the token based environment after that |
||
114 | * |
||
115 | * @throws CheckException |
||
116 | */ |
||
117 | 11 | private function validateAndSetTokenBasedEnv() { |
|
132 | |||
133 | /** |
||
134 | * Validates a token to make sure its linked to a valid resource |
||
135 | * |
||
136 | * Logic mostly duplicated from @see \OCA\Files_Sharing\Helper |
||
137 | * |
||
138 | * @fixme setIncognitoMode in 8.1 https://github.com/owncloud/core/pull/12912 |
||
139 | * |
||
140 | * @param string $token |
||
141 | * |
||
142 | * @return array |
||
143 | * |
||
144 | * @throws CheckException |
||
145 | */ |
||
146 | 9 | private function getLinkItem($token) { |
|
159 | |||
160 | /** |
||
161 | * Makes sure that the token exists |
||
162 | * |
||
163 | * @param array|bool $linkItem |
||
164 | * |
||
165 | * @throws CheckException |
||
166 | */ |
||
167 | 13 | private function checkLinkItemExists($linkItem) { |
|
176 | |||
177 | /** |
||
178 | * Makes sure that the token contains all the information that we need |
||
179 | * |
||
180 | * @param array|bool $linkItem |
||
181 | * @param string $token |
||
182 | * |
||
183 | * @throws CheckException |
||
184 | */ |
||
185 | 10 | private function checkLinkItemIsValid($linkItem, $token) { |
|
195 | |||
196 | /** |
||
197 | * Makes sure an item type was set for that token |
||
198 | * |
||
199 | * @param array|bool $linkItem |
||
200 | * |
||
201 | * @throws CheckException |
||
202 | */ |
||
203 | 9 | private function checkItemType($linkItem) { |
|
209 | |||
210 | /** |
||
211 | * Checks if a password is required or if the one supplied is working |
||
212 | * |
||
213 | * @param array|bool $linkItem |
||
214 | * @param string|null $password optional password |
||
215 | * |
||
216 | * @throws CheckException |
||
217 | */ |
||
218 | 10 | private function checkAuthorisation($linkItem, $password) { |
|
229 | |||
230 | /** |
||
231 | * Authenticate link item with the given password |
||
232 | * or with the session if no password was given. |
||
233 | * |
||
234 | * @fixme @LukasReschke says: Migrate old hashes to new hash format |
||
235 | * Due to the fact that there is no reasonable functionality to update the password |
||
236 | * of an existing share no migration is yet performed there. |
||
237 | * The only possibility is to update the existing share which will result in a new |
||
238 | * share ID and is a major hack. |
||
239 | * |
||
240 | * In the future the migration should be performed once there is a proper method |
||
241 | * to update the share's password. (for example `$share->updatePassword($password)` |
||
242 | * |
||
243 | * @link https://github.com/owncloud/core/issues/10671 |
||
244 | * |
||
245 | * @param array|bool $linkItem |
||
246 | * @param string $password |
||
247 | * |
||
248 | * @return bool true if authorized, an exception is raised otherwise |
||
249 | * |
||
250 | * @throws CheckException |
||
251 | */ |
||
252 | 10 | private function authenticate($linkItem, $password) { |
|
264 | |||
265 | /** |
||
266 | * Validates the given password |
||
267 | * |
||
268 | * @param array|bool $linkItem |
||
269 | * @param string $password |
||
270 | * |
||
271 | * @throws CheckException |
||
272 | */ |
||
273 | 11 | private function checkPassword($linkItem, $password) { |
|
287 | |||
288 | /** |
||
289 | * Makes sure the user is already properly authenticated when a password is required and none |
||
290 | * was provided |
||
291 | * |
||
292 | * @param array|bool $linkItem |
||
293 | * |
||
294 | * @throws CheckException |
||
295 | */ |
||
296 | 4 | private function checkSession($linkItem) { |
|
304 | |||
305 | } |
||
306 |