summaryrefslogtreecommitdiffstats
path: root/lib/private
diff options
context:
space:
mode:
authorChristoph Wurst <christoph@winzerhof-wurst.at>2019-07-03 10:10:56 +0200
committerRoeland Jago Douma <roeland@famdouma.nl>2019-07-09 13:57:04 +0200
commitd058ef2b6c6b3faf354fd8abeecb4cd71949d5a6 (patch)
tree34275b1f142f429f8c8982f7a79cc2327ee1c0b7 /lib/private
parent1c261675ad3da9804bd9a8c88326103eb2f56bd3 (diff)
downloadnextcloud-server-d058ef2b6c6b3faf354fd8abeecb4cd71949d5a6.tar.gz
nextcloud-server-d058ef2b6c6b3faf354fd8abeecb4cd71949d5a6.zip
Make it possible to wipe all tokens/devices of a user
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'lib/private')
-rw-r--r--lib/private/Authentication/Token/RemoteWipe.php42
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