|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @copyright Copyright (c) 2016, Robin Appelman <[email protected]> |
|
5
|
|
|
* |
|
6
|
|
|
* This code is free software: you can redistribute it and/or modify |
|
7
|
|
|
* it under the terms of the GNU Affero General Public License, version 3, |
|
8
|
|
|
* as published by the Free Software Foundation. |
|
9
|
|
|
* |
|
10
|
|
|
* This program is distributed in the hope that it will be useful, |
|
11
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13
|
|
|
* GNU Affero General Public License for more details. |
|
14
|
|
|
* |
|
15
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3, |
|
16
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/> |
|
17
|
|
|
* |
|
18
|
|
|
*/ |
|
19
|
|
|
|
|
20
|
|
|
namespace OC\Lockdown; |
|
21
|
|
|
|
|
22
|
|
|
use OC\Authentication\Token\IToken; |
|
23
|
|
|
use OCP\ISession; |
|
24
|
|
|
use OCP\Lockdown\ILockdownManager; |
|
25
|
|
|
|
|
26
|
|
|
class LockdownManager implements ILockdownManager { |
|
27
|
|
|
/** @var ISession */ |
|
28
|
|
|
private $sessionCallback; |
|
29
|
|
|
|
|
30
|
|
|
private $enabled = false; |
|
31
|
|
|
|
|
32
|
|
|
/** @var array|null */ |
|
33
|
|
|
private $scope; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* LockdownManager constructor. |
|
37
|
|
|
* |
|
38
|
|
|
* @param callable $sessionCallback we need to inject the session lazily to avoid dependency loops |
|
39
|
|
|
*/ |
|
40
|
|
|
public function __construct(callable $sessionCallback) { |
|
41
|
|
|
$this->sessionCallback = $sessionCallback; |
|
|
|
|
|
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
|
|
45
|
|
|
public function enable() { |
|
46
|
|
|
$this->enabled = true; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @return ISession |
|
51
|
|
|
*/ |
|
52
|
|
|
private function getSession() { |
|
53
|
|
|
$callback = $this->sessionCallback; |
|
54
|
|
|
return $callback(); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
private function getScopeAsArray() { |
|
58
|
|
|
if (!$this->scope) { |
|
59
|
|
|
$session = $this->getSession(); |
|
60
|
|
|
$sessionScope = $session->get('token_scope'); |
|
61
|
|
|
if ($sessionScope) { |
|
62
|
|
|
$this->scope = $sessionScope; |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
return $this->scope; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
public function setToken(IToken $token) { |
|
69
|
|
|
$this->scope = $token->getScopeAsArray(); |
|
70
|
|
|
$session = $this->getSession(); |
|
71
|
|
|
$session->set('token_scope', $this->scope); |
|
72
|
|
|
$this->enable(); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
public function canAccessFilesystem() { |
|
76
|
|
|
$scope = $this->getScopeAsArray(); |
|
77
|
|
|
return !$scope || $scope['filesystem']; |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..