2020-05-15 11:09:57 -04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
2020-08-24 08:54:25 -04:00
|
|
|
|
2020-05-15 11:09:57 -04:00
|
|
|
/**
|
2024-06-06 03:55:47 -04:00
|
|
|
* SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
2020-05-15 11:09:57 -04:00
|
|
|
*/
|
|
|
|
|
namespace OCA\Files_External\BackgroundJob;
|
|
|
|
|
|
|
|
|
|
use OCA\Files_External\Lib\Auth\Password\LoginCredentials;
|
|
|
|
|
use OCA\Files_External\Lib\StorageConfig;
|
|
|
|
|
use OCA\Files_External\Service\UserGlobalStoragesService;
|
|
|
|
|
use OCP\AppFramework\Utility\ITimeFactory;
|
|
|
|
|
use OCP\BackgroundJob\TimedJob;
|
|
|
|
|
use OCP\IUser;
|
|
|
|
|
use OCP\IUserManager;
|
|
|
|
|
use OCP\Security\ICredentialsManager;
|
|
|
|
|
|
|
|
|
|
class CredentialsCleanup extends TimedJob {
|
|
|
|
|
public function __construct(
|
|
|
|
|
ITimeFactory $time,
|
2024-10-18 06:04:22 -04:00
|
|
|
private ICredentialsManager $credentialsManager,
|
|
|
|
|
private UserGlobalStoragesService $userGlobalStoragesService,
|
|
|
|
|
private IUserManager $userManager,
|
2020-05-15 11:09:57 -04:00
|
|
|
) {
|
|
|
|
|
parent::__construct($time);
|
|
|
|
|
|
|
|
|
|
// run every day
|
|
|
|
|
$this->setInterval(24 * 60 * 60);
|
2024-10-07 11:36:55 -04:00
|
|
|
$this->setTimeSensitivity(self::TIME_INSENSITIVE);
|
2020-05-15 11:09:57 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function run($argument) {
|
2024-09-20 11:38:36 -04:00
|
|
|
$this->userManager->callForSeenUsers(function (IUser $user): void {
|
2020-05-15 11:09:57 -04:00
|
|
|
$storages = $this->userGlobalStoragesService->getAllStoragesForUser($user);
|
|
|
|
|
|
|
|
|
|
$usesLoginCredentials = array_reduce($storages, function (bool $uses, StorageConfig $storage) {
|
|
|
|
|
return $uses || $storage->getAuthMechanism() instanceof LoginCredentials;
|
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
|
|
if (!$usesLoginCredentials) {
|
|
|
|
|
$this->credentialsManager->delete($user->getUID(), LoginCredentials::CREDENTIALS_IDENTIFIER);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|