Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph Wurst <christoph@winzerhof-wurst.at>2019-07-03 11:10:56 +0300
committerRoeland Jago Douma <roeland@famdouma.nl>2019-07-09 14:57:04 +0300
commitd058ef2b6c6b3faf354fd8abeecb4cd71949d5a6 (patch)
tree34275b1f142f429f8c8982f7a79cc2327ee1c0b7 /apps/provisioning_api
parent1c261675ad3da9804bd9a8c88326103eb2f56bd3 (diff)
Make it possible to wipe all tokens/devices of a user
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'apps/provisioning_api')
-rw-r--r--apps/provisioning_api/appinfo/routes.php1
-rw-r--r--apps/provisioning_api/lib/Controller/UsersController.php39
2 files changed, 39 insertions, 1 deletions
diff --git a/apps/provisioning_api/appinfo/routes.php b/apps/provisioning_api/appinfo/routes.php
index f9005ba768d..fb0a6b235ce 100644
--- a/apps/provisioning_api/appinfo/routes.php
+++ b/apps/provisioning_api/appinfo/routes.php
@@ -50,6 +50,7 @@ return [
['root' => '/cloud', 'name' => 'Users#getCurrentUser', 'url' => '/user', 'verb' => 'GET'],
['root' => '/cloud', 'name' => 'Users#getEditableFields', 'url' => '/user/fields', 'verb' => 'GET'],
['root' => '/cloud', 'name' => 'Users#editUser', 'url' => '/users/{userId}', 'verb' => 'PUT'],
+ ['root' => '/cloud', 'name' => 'Users#wipeUserDevices', 'url' => '/users/{userId}/wipe', 'verb' => 'POST'],
['root' => '/cloud', 'name' => 'Users#deleteUser', 'url' => '/users/{userId}', 'verb' => 'DELETE'],
['root' => '/cloud', 'name' => 'Users#enableUser', 'url' => '/users/{userId}/enable', 'verb' => 'PUT'],
['root' => '/cloud', 'name' => 'Users#disableUser', 'url' => '/users/{userId}/disable', 'verb' => 'PUT'],
diff --git a/apps/provisioning_api/lib/Controller/UsersController.php b/apps/provisioning_api/lib/Controller/UsersController.php
index 1fa1f1fa5b3..dd54d7ebf75 100644
--- a/apps/provisioning_api/lib/Controller/UsersController.php
+++ b/apps/provisioning_api/lib/Controller/UsersController.php
@@ -34,6 +34,7 @@ declare(strict_types=1);
namespace OCA\Provisioning_API\Controller;
use OC\Accounts\AccountManager;
+use OC\Authentication\Token\RemoteWipe;
use OC\HintException;
use OC\Settings\Mailer\NewUserMailHelper;
use OCA\Provisioning_API\FederatedFileSharingFactory;
@@ -46,6 +47,7 @@ use OCP\IGroup;
use OCP\IGroupManager;
use OCP\ILogger;
use OCP\IRequest;
+use OCP\IUser;
use OCP\IUserManager;
use OCP\IUserSession;
use OCP\L10N\IFactory;
@@ -65,6 +67,8 @@ class UsersController extends AUserData {
private $federatedFileSharingFactory;
/** @var ISecureRandom */
private $secureRandom;
+ /** @var RemoteWipe */
+ private $remoteWipe;
/**
* @param string $appName
@@ -93,7 +97,8 @@ class UsersController extends AUserData {
IFactory $l10nFactory,
NewUserMailHelper $newUserMailHelper,
FederatedFileSharingFactory $federatedFileSharingFactory,
- ISecureRandom $secureRandom) {
+ ISecureRandom $secureRandom,
+ RemoteWipe $remoteWipe) {
parent::__construct($appName,
$request,
$userManager,
@@ -108,6 +113,7 @@ class UsersController extends AUserData {
$this->newUserMailHelper = $newUserMailHelper;
$this->federatedFileSharingFactory = $federatedFileSharingFactory;
$this->secureRandom = $secureRandom;
+ $this->remoteWipe = $remoteWipe;
}
/**
@@ -592,6 +598,37 @@ class UsersController extends AUserData {
* @NoAdminRequired
*
* @param string $userId
+ *
+ * @return DataResponse
+ *
+ * @throws OCSException
+ */
+ public function wipeUserDevices(string $userId): DataResponse {
+ /** @var IUser $currentLoggedInUser */
+ $currentLoggedInUser = $this->userSession->getUser();
+
+ $targetUser = $this->userManager->get($userId);
+
+ if ($targetUser === null || $targetUser->getUID() === $currentLoggedInUser->getUID()) {
+ throw new OCSException('', 101);
+ }
+
+ // If not permitted
+ $subAdminManager = $this->groupManager->getSubAdmin();
+ if (!$this->groupManager->isAdmin($currentLoggedInUser->getUID()) && !$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)) {
+ throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED);
+ }
+
+ $this->remoteWipe->markAllTokensForWipe($targetUser);
+
+ return new DataResponse();
+ }
+
+ /**
+ * @PasswordConfirmationRequired
+ * @NoAdminRequired
+ *
+ * @param string $userId
* @return DataResponse
* @throws OCSException
*/