diff options
Diffstat (limited to 'lib/private/Authentication/Token/RemoteWipe.php')
-rw-r--r-- | lib/private/Authentication/Token/RemoteWipe.php | 42 |
1 files changed, 36 insertions, 6 deletions
diff --git a/lib/private/Authentication/Token/RemoteWipe.php b/lib/private/Authentication/Token/RemoteWipe.php index 38f1f439e8e..8e66abef7b2 100644 --- a/lib/private/Authentication/Token/RemoteWipe.php +++ b/lib/private/Authentication/Token/RemoteWipe.php @@ -25,19 +25,15 @@ declare(strict_types=1); namespace OC\Authentication\Token; -use BadMethodCallException; +use function array_filter; use OC\Authentication\Events\RemoteWipeFinished; use OC\Authentication\Events\RemoteWipeStarted; +use OC\Authentication\Exceptions\ExpiredTokenException; use OC\Authentication\Exceptions\InvalidTokenException; use OC\Authentication\Exceptions\WipeTokenException; -use OCP\Activity\IEvent; -use OCP\Activity\IManager as IActivityManager; -use OCP\AppFramework\Utility\ITimeFactory; use OCP\EventDispatcher\IEventDispatcher; use OCP\ILogger; use OCP\IUser; -use OCP\Notification\IManager as INotificationManager; -use Symfony\Component\EventDispatcher\EventDispatcher; class RemoteWipe { @@ -58,6 +54,15 @@ class RemoteWipe { $this->logger = $logger; } + /** + * @param int $id + * + * @return bool + * + * @throws InvalidTokenException + * @throws WipeTokenException + * @throws ExpiredTokenException + */ public function markTokenForWipe(int $id): bool { $token = $this->tokenProvider->getTokenById($id); @@ -72,6 +77,31 @@ class RemoteWipe { } /** + * @param IUser $user + * + * @return bool true if any tokens have been marked for remote wipe + */ + public function markAllTokensForWipe(IUser $user): bool { + $tokens = $this->tokenProvider->getTokenByUser($user->getUID()); + + /** @var IWipeableToken[] $wipeable */ + $wipeable = array_filter($tokens, function (IToken $token) { + return $token instanceof IWipeableToken; + }); + + if (empty($wipeable)) { + return false; + } + + foreach ($wipeable as $token) { + $token->wipe(); + $this->tokenProvider->updateToken($token); + } + + return true; + } + + /** * @param string $token * * @return bool whether wiping was started |