1
|
|
|
<?php |
2
|
|
|
/** @noinspection ALL */ |
3
|
|
|
declare(strict_types=1); |
4
|
|
|
/** |
5
|
|
|
* @copyright Copyright (c) 2018 Roeland Jago Douma <[email protected]> |
6
|
|
|
* |
7
|
|
|
* @author Roeland Jago Douma <[email protected]> |
8
|
|
|
* |
9
|
|
|
* @license GNU AGPL version 3 or any later version |
10
|
|
|
* |
11
|
|
|
* This program is free software: you can redistribute it and/or modify |
12
|
|
|
* it under the terms of the GNU Affero General Public License as |
13
|
|
|
* published by the Free Software Foundation, either version 3 of the |
14
|
|
|
* License, or (at your option) any later version. |
15
|
|
|
* |
16
|
|
|
* This program is distributed in the hope that it will be useful, |
17
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
18
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
19
|
|
|
* GNU Affero General Public License for more details. |
20
|
|
|
* |
21
|
|
|
* You should have received a copy of the GNU Affero General Public License |
22
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
23
|
|
|
* |
24
|
|
|
*/ |
25
|
|
|
|
26
|
|
|
namespace OC\Authentication\Token; |
27
|
|
|
|
28
|
|
|
use OCP\AppFramework\Db\Entity; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @method void setId(int $id) |
32
|
|
|
* @method void setUid(string $uid); |
33
|
|
|
* @method void setLoginName(string $loginname) |
34
|
|
|
* @method string getToken() |
35
|
|
|
* @method void setType(int $type) |
36
|
|
|
* @method int getType() |
37
|
|
|
* @method void setRemember(int $remember) |
38
|
|
|
* @method void setLastActivity(int $lastactivity) |
39
|
|
|
* @method int getLastActivity() |
40
|
|
|
* @method string getPrivateKey() |
41
|
|
|
* @method void setPrivateKey(string $key) |
42
|
|
|
* @method string getPublicKey() |
43
|
|
|
* @method void setPublicKey(string $key) |
44
|
|
|
* @method void setVersion(int $version) |
45
|
|
|
* @method bool getPasswordInvalid() |
46
|
|
|
*/ |
47
|
|
|
class PublicKeyToken extends Entity implements INamedToken { |
48
|
|
|
|
49
|
|
|
const VERSION = 2; |
50
|
|
|
|
51
|
|
|
/** @var string user UID */ |
52
|
|
|
protected $uid; |
53
|
|
|
|
54
|
|
|
/** @var string login name used for generating the token */ |
55
|
|
|
protected $loginName; |
56
|
|
|
|
57
|
|
|
/** @var string encrypted user password */ |
58
|
|
|
protected $password; |
59
|
|
|
|
60
|
|
|
/** @var string token name (e.g. browser/OS) */ |
61
|
|
|
protected $name; |
62
|
|
|
|
63
|
|
|
/** @var string */ |
64
|
|
|
protected $token; |
65
|
|
|
|
66
|
|
|
/** @var int */ |
67
|
|
|
protected $type; |
68
|
|
|
|
69
|
|
|
/** @var int */ |
70
|
|
|
protected $remember; |
71
|
|
|
|
72
|
|
|
/** @var int */ |
73
|
|
|
protected $lastActivity; |
74
|
|
|
|
75
|
|
|
/** @var int */ |
76
|
|
|
protected $lastCheck; |
77
|
|
|
|
78
|
|
|
/** @var string */ |
79
|
|
|
protected $scope; |
80
|
|
|
|
81
|
|
|
/** @var int */ |
82
|
|
|
protected $expires; |
83
|
|
|
|
84
|
|
|
/** @var string */ |
85
|
|
|
protected $privateKey; |
86
|
|
|
|
87
|
|
|
/** @var string */ |
88
|
|
|
protected $publicKey; |
89
|
|
|
|
90
|
|
|
/** @var int */ |
91
|
|
|
protected $version; |
92
|
|
|
|
93
|
|
|
/** @var bool */ |
94
|
|
|
protected $passwordInvalid; |
95
|
|
|
|
96
|
|
|
public function __construct() { |
97
|
|
|
$this->addType('uid', 'string'); |
98
|
|
|
$this->addType('loginName', 'string'); |
99
|
|
|
$this->addType('password', 'string'); |
100
|
|
|
$this->addType('name', 'string'); |
101
|
|
|
$this->addType('token', 'string'); |
102
|
|
|
$this->addType('type', 'int'); |
103
|
|
|
$this->addType('remember', 'int'); |
104
|
|
|
$this->addType('lastActivity', 'int'); |
105
|
|
|
$this->addType('lastCheck', 'int'); |
106
|
|
|
$this->addType('scope', 'string'); |
107
|
|
|
$this->addType('expires', 'int'); |
108
|
|
|
$this->addType('publicKey', 'string'); |
109
|
|
|
$this->addType('privateKey', 'string'); |
110
|
|
|
$this->addType('version', 'int'); |
111
|
|
|
$this->addType('passwordInvalid', 'bool'); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
public function getId(): int { |
115
|
|
|
return $this->id; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
public function getUID(): string { |
119
|
|
|
return $this->uid; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* Get the login name used when generating the token |
124
|
|
|
* |
125
|
|
|
* @return string |
126
|
|
|
*/ |
127
|
|
|
public function getLoginName(): string { |
128
|
|
|
return parent::getLoginName(); |
|
|
|
|
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* Get the (encrypted) login password |
133
|
|
|
* |
134
|
|
|
* @return string|null |
135
|
|
|
*/ |
136
|
|
|
public function getPassword() { |
137
|
|
|
return parent::getPassword(); |
|
|
|
|
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
public function jsonSerialize() { |
141
|
|
|
return [ |
142
|
|
|
'id' => $this->id, |
143
|
|
|
'name' => $this->name, |
144
|
|
|
'lastActivity' => $this->lastActivity, |
145
|
|
|
'type' => $this->type, |
146
|
|
|
'scope' => $this->getScopeAsArray() |
147
|
|
|
]; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* Get the timestamp of the last password check |
152
|
|
|
* |
153
|
|
|
* @return int |
154
|
|
|
*/ |
155
|
|
|
public function getLastCheck(): int { |
156
|
|
|
return parent::getLastCheck(); |
|
|
|
|
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* Get the timestamp of the last password check |
161
|
|
|
* |
162
|
|
|
* @param int $time |
163
|
|
|
*/ |
164
|
|
|
public function setLastCheck(int $time) { |
165
|
|
|
parent::setLastCheck($time); |
|
|
|
|
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
public function getScope(): string { |
169
|
|
|
$scope = parent::getScope(); |
|
|
|
|
170
|
|
|
if ($scope === null) { |
|
|
|
|
171
|
|
|
return ''; |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
return $scope; |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
public function getScopeAsArray(): array { |
178
|
|
|
$scope = json_decode($this->getScope(), true); |
179
|
|
|
if (!$scope) { |
180
|
|
|
return [ |
181
|
|
|
'filesystem'=> true |
182
|
|
|
]; |
183
|
|
|
} |
184
|
|
|
return $scope; |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
public function setScope($scope) { |
188
|
|
|
if (is_array($scope)) { |
189
|
|
|
parent::setScope(json_encode($scope)); |
|
|
|
|
190
|
|
|
} else { |
191
|
|
|
parent::setScope((string)$scope); |
192
|
|
|
} |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
public function getName(): string { |
196
|
|
|
return parent::getName(); |
|
|
|
|
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
public function setName(string $name): void { |
200
|
|
|
parent::setName($name); |
|
|
|
|
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
public function getRemember(): int { |
204
|
|
|
return parent::getRemember(); |
|
|
|
|
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
public function setToken(string $token) { |
208
|
|
|
parent::setToken($token); |
|
|
|
|
209
|
|
|
} |
210
|
|
|
|
211
|
|
|
public function setPassword(string $password = null) { |
212
|
|
|
parent::setPassword($password); |
|
|
|
|
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
public function setExpires($expires) { |
216
|
|
|
parent::setExpires($expires); |
|
|
|
|
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
/** |
220
|
|
|
* @return int|null |
221
|
|
|
*/ |
222
|
|
|
public function getExpires() { |
223
|
|
|
return parent::getExpires(); |
|
|
|
|
224
|
|
|
} |
225
|
|
|
|
226
|
|
|
public function setPasswordInvalid(bool $invalid) { |
227
|
|
|
parent::setPasswordInvalid($invalid); |
|
|
|
|
228
|
|
|
} |
229
|
|
|
} |
230
|
|
|
|