Skip to content

Commit 9b4e35d

Browse files
committed
Add back TokenCleanupJob to invalidate old temporary tokens
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
1 parent 9746229 commit 9b4e35d

File tree

6 files changed

+96
-0
lines changed

6 files changed

+96
-0
lines changed

lib/composer/composer/autoload_classmap.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -778,6 +778,7 @@
778778
'OC\\Authentication\\Token\\PublicKeyTokenMapper' => $baseDir . '/lib/private/Authentication/Token/PublicKeyTokenMapper.php',
779779
'OC\\Authentication\\Token\\PublicKeyTokenProvider' => $baseDir . '/lib/private/Authentication/Token/PublicKeyTokenProvider.php',
780780
'OC\\Authentication\\Token\\RemoteWipe' => $baseDir . '/lib/private/Authentication/Token/RemoteWipe.php',
781+
'OC\\Authentication\\Token\\TokenCleanupJob' => $baseDir . '/lib/private/Authentication/Token/TokenCleanupJob.php',
781782
'OC\\Authentication\\TwoFactorAuth\\Db\\ProviderUserAssignmentDao' => $baseDir . '/lib/private/Authentication/TwoFactorAuth/Db/ProviderUserAssignmentDao.php',
782783
'OC\\Authentication\\TwoFactorAuth\\EnforcementState' => $baseDir . '/lib/private/Authentication/TwoFactorAuth/EnforcementState.php',
783784
'OC\\Authentication\\TwoFactorAuth\\Manager' => $baseDir . '/lib/private/Authentication/TwoFactorAuth/Manager.php',
@@ -1426,6 +1427,7 @@
14261427
'OC\\Repair\\NC21\\AddCheckForUserCertificatesJob' => $baseDir . '/lib/private/Repair/NC21/AddCheckForUserCertificatesJob.php',
14271428
'OC\\Repair\\NC21\\ValidatePhoneNumber' => $baseDir . '/lib/private/Repair/NC21/ValidatePhoneNumber.php',
14281429
'OC\\Repair\\NC22\\LookupServerSendCheck' => $baseDir . '/lib/private/Repair/NC22/LookupServerSendCheck.php',
1430+
'OC\\Repair\\NC24\\AddTokenCleanupJob' => $baseDir . '/lib/private/Repair/NC24/AddTokenCleanupJob.php',
14291431
'OC\\Repair\\OldGroupMembershipShares' => $baseDir . '/lib/private/Repair/OldGroupMembershipShares.php',
14301432
'OC\\Repair\\Owncloud\\CleanPreviews' => $baseDir . '/lib/private/Repair/Owncloud/CleanPreviews.php',
14311433
'OC\\Repair\\Owncloud\\CleanPreviewsBackgroundJob' => $baseDir . '/lib/private/Repair/Owncloud/CleanPreviewsBackgroundJob.php',

lib/composer/composer/autoload_static.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -811,6 +811,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
811811
'OC\\Authentication\\Token\\PublicKeyTokenMapper' => __DIR__ . '/../../..' . '/lib/private/Authentication/Token/PublicKeyTokenMapper.php',
812812
'OC\\Authentication\\Token\\PublicKeyTokenProvider' => __DIR__ . '/../../..' . '/lib/private/Authentication/Token/PublicKeyTokenProvider.php',
813813
'OC\\Authentication\\Token\\RemoteWipe' => __DIR__ . '/../../..' . '/lib/private/Authentication/Token/RemoteWipe.php',
814+
'OC\\Authentication\\Token\\TokenCleanupJob' => __DIR__ . '/../../..' . '/lib/private/Authentication/Token/TokenCleanupJob.php',
814815
'OC\\Authentication\\TwoFactorAuth\\Db\\ProviderUserAssignmentDao' => __DIR__ . '/../../..' . '/lib/private/Authentication/TwoFactorAuth/Db/ProviderUserAssignmentDao.php',
815816
'OC\\Authentication\\TwoFactorAuth\\EnforcementState' => __DIR__ . '/../../..' . '/lib/private/Authentication/TwoFactorAuth/EnforcementState.php',
816817
'OC\\Authentication\\TwoFactorAuth\\Manager' => __DIR__ . '/../../..' . '/lib/private/Authentication/TwoFactorAuth/Manager.php',
@@ -1459,6 +1460,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
14591460
'OC\\Repair\\NC21\\AddCheckForUserCertificatesJob' => __DIR__ . '/../../..' . '/lib/private/Repair/NC21/AddCheckForUserCertificatesJob.php',
14601461
'OC\\Repair\\NC21\\ValidatePhoneNumber' => __DIR__ . '/../../..' . '/lib/private/Repair/NC21/ValidatePhoneNumber.php',
14611462
'OC\\Repair\\NC22\\LookupServerSendCheck' => __DIR__ . '/../../..' . '/lib/private/Repair/NC22/LookupServerSendCheck.php',
1463+
'OC\\Repair\\NC24\\AddTokenCleanupJob' => __DIR__ . '/../../..' . '/lib/private/Repair/NC24/AddTokenCleanupJob.php',
14621464
'OC\\Repair\\OldGroupMembershipShares' => __DIR__ . '/../../..' . '/lib/private/Repair/OldGroupMembershipShares.php',
14631465
'OC\\Repair\\Owncloud\\CleanPreviews' => __DIR__ . '/../../..' . '/lib/private/Repair/Owncloud/CleanPreviews.php',
14641466
'OC\\Repair\\Owncloud\\CleanPreviewsBackgroundJob' => __DIR__ . '/../../..' . '/lib/private/Repair/Owncloud/CleanPreviewsBackgroundJob.php',
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
/**
3+
* @copyright 2022 Thomas Citharel <nextcloud@tcit.fr>
4+
*
5+
* @author Thomas Citharel <nextcloud@tcit.fr>
6+
*
7+
* @license AGPL-3.0
8+
*
9+
* This code is free software: you can redistribute it and/or modify
10+
* it under the terms of the GNU Affero General Public License, version 3,
11+
* as published by the Free Software Foundation.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU Affero General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU Affero General Public License, version 3,
19+
* along with this program. If not, see <http://www.gnu.org/licenses/>
20+
*
21+
*/
22+
namespace OC\Authentication\Token;
23+
24+
use OCP\AppFramework\Utility\ITimeFactory;
25+
use OCP\BackgroundJob\TimedJob;
26+
27+
class TokenCleanupJob extends TimedJob {
28+
private IProvider $provider;
29+
30+
public function __construct(ITimeFactory $time, IProvider $provider) {
31+
parent::__construct($time);
32+
$this->provider = $provider;
33+
// Run once a day at off-peak time
34+
$this->setInterval(24 * 60 * 60);
35+
$this->setTimeSensitivity(self::TIME_INSENSITIVE);
36+
}
37+
38+
protected function run($argument) {
39+
$this->provider->invalidateOldTokens();
40+
}
41+
}

lib/private/Repair.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
use OC\Repair\Collation;
4747
use OC\Repair\MoveUpdaterStepFile;
4848
use OC\Repair\NC22\LookupServerSendCheck;
49+
use OC\Repair\NC24\AddTokenCleanupJob;
4950
use OC\Repair\Owncloud\CleanPreviews;
5051
use OC\Repair\Owncloud\MigrateOauthTables;
5152
use OC\Repair\NC11\FixMountStorages;
@@ -209,6 +210,7 @@ public static function getRepairSteps() {
209210
\OC::$server->get(AddCheckForUserCertificatesJob::class),
210211
\OC::$server->get(RepairDavShares::class),
211212
\OC::$server->get(LookupServerSendCheck::class),
213+
\OC::$server->get(AddTokenCleanupJob::class),
212214
];
213215
}
214216

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* @copyright 2022 Thomas Citharel <nextcloud@tcit.fr>
7+
*
8+
* @author Thomas Citharel <nextcloud@tcit.fr>
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 OC\Repair\NC24;
27+
28+
use OC\Authentication\Token\TokenCleanupJob;
29+
use OCP\BackgroundJob\IJobList;
30+
use OCP\Migration\IOutput;
31+
use OCP\Migration\IRepairStep;
32+
33+
class AddTokenCleanupJob implements IRepairStep {
34+
private IJobList $jobList;
35+
36+
public function __construct(IJobList $jobList) {
37+
$this->jobList = $jobList;
38+
}
39+
40+
public function getName(): string {
41+
return 'Add token cleanup job';
42+
}
43+
44+
public function run(IOutput $output) {
45+
$this->jobList->add(TokenCleanupJob::class);
46+
}
47+
}

lib/private/Setup.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
use InvalidArgumentException;
5454
use OC\App\AppStore\Bundles\BundleFetcher;
5555
use OC\Authentication\Token\PublicKeyTokenProvider;
56+
use OC\Authentication\Token\TokenCleanupJob;
5657
use OC\Log\Rotate;
5758
use OC\Preview\BackgroundCleanupJob;
5859
use OCP\AppFramework\Utility\ITimeFactory;
@@ -450,6 +451,7 @@ public function install($options) {
450451

451452
public static function installBackgroundJobs() {
452453
$jobList = \OC::$server->getJobList();
454+
$jobList->add(TokenCleanupJob::class);
453455
$jobList->add(Rotate::class);
454456
$jobList->add(BackgroundCleanupJob::class);
455457
}

0 commit comments

Comments
 (0)