Skip to content

Commit 5245d20

Browse files
authored
Merge pull request #41017 from nextcloud/fix/move-token-iprovider-to-ocp
Move IToken and IProvider::getToken to OCP
2 parents d43c66e + d8b42c6 commit 5245d20

File tree

14 files changed

+332
-138
lines changed

14 files changed

+332
-138
lines changed

apps/settings/lib/Controller/AuthSettingsController.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,13 @@
5353
use Psr\Log\LoggerInterface;
5454

5555
class AuthSettingsController extends Controller {
56-
5756
/** @var IProvider */
5857
private $tokenProvider;
5958

6059
/** @var ISession */
6160
private $session;
6261

63-
/** IUserSession */
62+
/** @var IUserSession */
6463
private $userSession;
6564

6665
/** @var string */

build/psalm-baseline.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2080,7 +2080,7 @@
20802080
<code>$trySession</code>
20812081
</RedundantCondition>
20822082
</file>
2083-
<file src="lib/private/Authentication/Token/IToken.php">
2083+
<file src="lib/public/Authentication/Token/IToken.php">
20842084
<AmbiguousConstantInheritance>
20852085
<code>DO_NOT_REMEMBER</code>
20862086
<code>PERMANENT_TOKEN</code>

lib/composer/composer/autoload_classmap.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,17 @@
106106
'OCP\\Authentication\\Events\\AnyLoginFailedEvent' => $baseDir . '/lib/public/Authentication/Events/AnyLoginFailedEvent.php',
107107
'OCP\\Authentication\\Events\\LoginFailedEvent' => $baseDir . '/lib/public/Authentication/Events/LoginFailedEvent.php',
108108
'OCP\\Authentication\\Exceptions\\CredentialsUnavailableException' => $baseDir . '/lib/public/Authentication/Exceptions/CredentialsUnavailableException.php',
109+
'OCP\\Authentication\\Exceptions\\ExpiredTokenException' => $baseDir . '/lib/public/Authentication/Exceptions/ExpiredTokenException.php',
110+
'OCP\\Authentication\\Exceptions\\InvalidTokenException' => $baseDir . '/lib/public/Authentication/Exceptions/InvalidTokenException.php',
109111
'OCP\\Authentication\\Exceptions\\PasswordUnavailableException' => $baseDir . '/lib/public/Authentication/Exceptions/PasswordUnavailableException.php',
112+
'OCP\\Authentication\\Exceptions\\WipeTokenException' => $baseDir . '/lib/public/Authentication/Exceptions/WipeTokenException.php',
110113
'OCP\\Authentication\\IAlternativeLogin' => $baseDir . '/lib/public/Authentication/IAlternativeLogin.php',
111114
'OCP\\Authentication\\IApacheBackend' => $baseDir . '/lib/public/Authentication/IApacheBackend.php',
112115
'OCP\\Authentication\\IProvideUserSecretBackend' => $baseDir . '/lib/public/Authentication/IProvideUserSecretBackend.php',
113116
'OCP\\Authentication\\LoginCredentials\\ICredentials' => $baseDir . '/lib/public/Authentication/LoginCredentials/ICredentials.php',
114117
'OCP\\Authentication\\LoginCredentials\\IStore' => $baseDir . '/lib/public/Authentication/LoginCredentials/IStore.php',
115118
'OCP\\Authentication\\Token\\IProvider' => $baseDir . '/lib/public/Authentication/Token/IProvider.php',
119+
'OCP\\Authentication\\Token\\IToken' => $baseDir . '/lib/public/Authentication/Token/IToken.php',
116120
'OCP\\Authentication\\TwoFactorAuth\\ALoginSetupController' => $baseDir . '/lib/public/Authentication/TwoFactorAuth/ALoginSetupController.php',
117121
'OCP\\Authentication\\TwoFactorAuth\\IActivatableAtLogin' => $baseDir . '/lib/public/Authentication/TwoFactorAuth/IActivatableAtLogin.php',
118122
'OCP\\Authentication\\TwoFactorAuth\\IActivatableByAdmin' => $baseDir . '/lib/public/Authentication/TwoFactorAuth/IActivatableByAdmin.php',

lib/composer/composer/autoload_static.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,17 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
139139
'OCP\\Authentication\\Events\\AnyLoginFailedEvent' => __DIR__ . '/../../..' . '/lib/public/Authentication/Events/AnyLoginFailedEvent.php',
140140
'OCP\\Authentication\\Events\\LoginFailedEvent' => __DIR__ . '/../../..' . '/lib/public/Authentication/Events/LoginFailedEvent.php',
141141
'OCP\\Authentication\\Exceptions\\CredentialsUnavailableException' => __DIR__ . '/../../..' . '/lib/public/Authentication/Exceptions/CredentialsUnavailableException.php',
142+
'OCP\\Authentication\\Exceptions\\ExpiredTokenException' => __DIR__ . '/../../..' . '/lib/public/Authentication/Exceptions/ExpiredTokenException.php',
143+
'OCP\\Authentication\\Exceptions\\InvalidTokenException' => __DIR__ . '/../../..' . '/lib/public/Authentication/Exceptions/InvalidTokenException.php',
142144
'OCP\\Authentication\\Exceptions\\PasswordUnavailableException' => __DIR__ . '/../../..' . '/lib/public/Authentication/Exceptions/PasswordUnavailableException.php',
145+
'OCP\\Authentication\\Exceptions\\WipeTokenException' => __DIR__ . '/../../..' . '/lib/public/Authentication/Exceptions/WipeTokenException.php',
143146
'OCP\\Authentication\\IAlternativeLogin' => __DIR__ . '/../../..' . '/lib/public/Authentication/IAlternativeLogin.php',
144147
'OCP\\Authentication\\IApacheBackend' => __DIR__ . '/../../..' . '/lib/public/Authentication/IApacheBackend.php',
145148
'OCP\\Authentication\\IProvideUserSecretBackend' => __DIR__ . '/../../..' . '/lib/public/Authentication/IProvideUserSecretBackend.php',
146149
'OCP\\Authentication\\LoginCredentials\\ICredentials' => __DIR__ . '/../../..' . '/lib/public/Authentication/LoginCredentials/ICredentials.php',
147150
'OCP\\Authentication\\LoginCredentials\\IStore' => __DIR__ . '/../../..' . '/lib/public/Authentication/LoginCredentials/IStore.php',
148151
'OCP\\Authentication\\Token\\IProvider' => __DIR__ . '/../../..' . '/lib/public/Authentication/Token/IProvider.php',
152+
'OCP\\Authentication\\Token\\IToken' => __DIR__ . '/../../..' . '/lib/public/Authentication/Token/IToken.php',
149153
'OCP\\Authentication\\TwoFactorAuth\\ALoginSetupController' => __DIR__ . '/../../..' . '/lib/public/Authentication/TwoFactorAuth/ALoginSetupController.php',
150154
'OCP\\Authentication\\TwoFactorAuth\\IActivatableAtLogin' => __DIR__ . '/../../..' . '/lib/public/Authentication/TwoFactorAuth/IActivatableAtLogin.php',
151155
'OCP\\Authentication\\TwoFactorAuth\\IActivatableByAdmin' => __DIR__ . '/../../..' . '/lib/public/Authentication/TwoFactorAuth/IActivatableByAdmin.php',

lib/private/Authentication/Exceptions/ExpiredTokenException.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,19 @@
2727

2828
use OC\Authentication\Token\IToken;
2929

30-
class ExpiredTokenException extends InvalidTokenException {
31-
/** @var IToken */
32-
private $token;
33-
34-
public function __construct(IToken $token) {
35-
parent::__construct();
36-
37-
$this->token = $token;
30+
/**
31+
* @deprecated 28.0.0 use {@see \OCP\Authentication\Exceptions\ExpiredTokenException} instead
32+
*/
33+
class ExpiredTokenException extends \OCP\Authentication\Exceptions\ExpiredTokenException {
34+
public function __construct(
35+
IToken $token,
36+
) {
37+
parent::__construct($token);
3838
}
3939

4040
public function getToken(): IToken {
41-
return $this->token;
41+
$token = parent::getToken();
42+
/** @var IToken $token We know that we passed OC interface from constructor */
43+
return $token;
4244
}
4345
}

lib/private/Authentication/Exceptions/InvalidTokenException.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
*/
2525
namespace OC\Authentication\Exceptions;
2626

27-
use Exception;
28-
29-
class InvalidTokenException extends Exception {
27+
/**
28+
* @deprecated 28.0.0 use OCP version instead
29+
*/
30+
class InvalidTokenException extends \OCP\Authentication\Exceptions\InvalidTokenException {
3031
}

lib/private/Authentication/Exceptions/WipeTokenException.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,19 @@
2727

2828
use OC\Authentication\Token\IToken;
2929

30-
class WipeTokenException extends InvalidTokenException {
31-
/** @var IToken */
32-
private $token;
33-
34-
public function __construct(IToken $token) {
35-
parent::__construct();
36-
37-
$this->token = $token;
30+
/**
31+
* @deprecated 28.0.0 use {@see \OCP\Authentication\Exceptions\WipeTokenException} instead
32+
*/
33+
class WipeTokenException extends \OCP\Authentication\Exceptions\WipeTokenException {
34+
public function __construct(
35+
IToken $token,
36+
) {
37+
parent::__construct($token);
3838
}
3939

4040
public function getToken(): IToken {
41-
return $this->token;
41+
$token = parent::getToken();
42+
/** @var IToken $token We know that we passed OC interface from constructor */
43+
return $token;
4244
}
4345
}

lib/private/Authentication/Token/IToken.php

Lines changed: 5 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -26,109 +26,10 @@
2626
*/
2727
namespace OC\Authentication\Token;
2828

29-
use JsonSerializable;
29+
use OCP\Authentication\Token\IToken as OCPIToken;
3030

31-
interface IToken extends JsonSerializable {
32-
public const TEMPORARY_TOKEN = 0;
33-
public const PERMANENT_TOKEN = 1;
34-
public const WIPE_TOKEN = 2;
35-
public const DO_NOT_REMEMBER = 0;
36-
public const REMEMBER = 1;
37-
38-
/**
39-
* Get the token ID
40-
*
41-
* @return int
42-
*/
43-
public function getId(): int;
44-
45-
/**
46-
* Get the user UID
47-
*
48-
* @return string
49-
*/
50-
public function getUID(): string;
51-
52-
/**
53-
* Get the login name used when generating the token
54-
*
55-
* @return string
56-
*/
57-
public function getLoginName(): string;
58-
59-
/**
60-
* Get the (encrypted) login password
61-
*
62-
* @return string|null
63-
*/
64-
public function getPassword();
65-
66-
/**
67-
* Get the timestamp of the last password check
68-
*
69-
* @return int
70-
*/
71-
public function getLastCheck(): int;
72-
73-
/**
74-
* Set the timestamp of the last password check
75-
*
76-
* @param int $time
77-
*/
78-
public function setLastCheck(int $time);
79-
80-
/**
81-
* Get the authentication scope for this token
82-
*
83-
* @return string
84-
*/
85-
public function getScope(): string;
86-
87-
/**
88-
* Get the authentication scope for this token
89-
*
90-
* @return array
91-
*/
92-
public function getScopeAsArray(): array;
93-
94-
/**
95-
* Set the authentication scope for this token
96-
*
97-
* @param array $scope
98-
*/
99-
public function setScope($scope);
100-
101-
/**
102-
* Get the name of the token
103-
* @return string
104-
*/
105-
public function getName(): string;
106-
107-
/**
108-
* Get the remember state of the token
109-
*
110-
* @return int
111-
*/
112-
public function getRemember(): int;
113-
114-
/**
115-
* Set the token
116-
*
117-
* @param string $token
118-
*/
119-
public function setToken(string $token);
120-
121-
/**
122-
* Set the password
123-
*
124-
* @param string $password
125-
*/
126-
public function setPassword(string $password);
127-
128-
/**
129-
* Set the expiration time of the token
130-
*
131-
* @param int|null $expires
132-
*/
133-
public function setExpires($expires);
31+
/**
32+
* @deprecated 28.0.0 use {@see \OCP\Authentication\Token\IToken} instead
33+
*/
34+
interface IToken extends OCPIToken {
13435
}

lib/private/Authentication/Token/PublicKeyToken.php

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,8 @@ public function getLoginName(): string {
137137

138138
/**
139139
* Get the (encrypted) login password
140-
*
141-
* @return string|null
142140
*/
143-
public function getPassword() {
141+
public function getPassword(): ?string {
144142
return parent::getPassword();
145143
}
146144

@@ -165,10 +163,8 @@ public function getLastCheck(): int {
165163

166164
/**
167165
* Get the timestamp of the last password check
168-
*
169-
* @param int $time
170166
*/
171-
public function setLastCheck(int $time) {
167+
public function setLastCheck(int $time): void {
172168
parent::setLastCheck($time);
173169
}
174170

@@ -191,7 +187,7 @@ public function getScopeAsArray(): array {
191187
return $scope;
192188
}
193189

194-
public function setScope($scope) {
190+
public function setScope(array|string|null $scope): void {
195191
if (is_array($scope)) {
196192
parent::setScope(json_encode($scope));
197193
} else {
@@ -211,15 +207,15 @@ public function getRemember(): int {
211207
return parent::getRemember();
212208
}
213209

214-
public function setToken(string $token) {
210+
public function setToken(string $token): void {
215211
parent::setToken($token);
216212
}
217213

218-
public function setPassword(string $password = null) {
214+
public function setPassword(string $password = null): void {
219215
parent::setPassword($password);
220216
}
221217

222-
public function setExpires($expires) {
218+
public function setExpires($expires): void {
223219
parent::setExpires($expires);
224220
}
225221

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* @copyright Copyright (c) 2018 Roeland Jago Douma <[email protected]>
7+
*
8+
* @author Roeland Jago Douma <[email protected]>
9+
*
10+
* @license GNU AGPL version 3 or any later version
11+
*
12+
* This program is free software: you can redistribute it and/or modify
13+
* it under the terms of the GNU Affero General Public License as
14+
* published by the Free Software Foundation, either version 3 of the
15+
* License, or (at your option) any later version.
16+
*
17+
* This program is distributed in the hope that it will be useful,
18+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
19+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20+
* GNU Affero General Public License for more details.
21+
*
22+
* You should have received a copy of the GNU Affero General Public License
23+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
24+
*
25+
*/
26+
namespace OCP\Authentication\Exceptions;
27+
28+
use OCP\Authentication\Token\IToken;
29+
30+
/**
31+
* @since 28.0.0
32+
*/
33+
class ExpiredTokenException extends InvalidTokenException {
34+
/**
35+
* @since 28.0.0
36+
*/
37+
public function __construct(
38+
private IToken $token,
39+
) {
40+
parent::__construct();
41+
}
42+
43+
/**
44+
* @since 28.0.0
45+
*/
46+
public function getToken(): IToken {
47+
return $this->token;
48+
}
49+
}

0 commit comments

Comments
 (0)