scimserviceprovider/lib/Controller/ASCIMUser.php

118 lines
3.6 KiB
PHP
Raw Normal View History

2022-04-29 13:58:37 +00:00
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2018 John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
*
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
* @author Georg Ehrke <oc.list@georgehrke.com>
* @author Joas Schilling <coding@schilljs.com>
* @author John Molakvoæ <skjnldsv@protonmail.com>
* @author Roeland Jago Douma <roeland@famdouma.nl>
* @author Vincent Petry <vincent@nextcloud.com>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\SCIMServiceProvider\Controller;
use OC\Group\Manager;
use OCP\Accounts\IAccountManager;
use OCP\Accounts\PropertyDoesNotExistException;
use OCP\AppFramework\ApiController;
use OCP\AppFramework\Http;
use OCP\Files\NotFoundException;
use OCP\IConfig;
use OCP\IGroupManager;
use OCP\IRequest;
use OCP\IUserManager;
use OCP\IUserSession;
use OCP\L10N\IFactory;
2022-05-02 10:21:25 +00:00
use OCA\SCIMServiceProvider\Responses\SCIMErrorResponse;
2022-04-29 13:58:37 +00:00
abstract class ASCIMUser extends ApiController {
/** @var IUserManager */
protected $userManager;
/** @var IConfig */
protected $config;
/** @var IGroupManager|Manager */ // FIXME Requires a method that is not on the interface
protected $groupManager;
/** @var IUserSession */
protected $userSession;
/** @var IAccountManager */
protected $accountManager;
public function __construct(string $appName,
IRequest $request,
IUserManager $userManager,
IConfig $config,
IGroupManager $groupManager,
IUserSession $userSession,
IAccountManager $accountManager) {
parent::__construct($appName, $request);
$this->userManager = $userManager;
$this->config = $config;
$this->groupManager = $groupManager;
$this->userSession = $userSession;
$this->accountManager = $accountManager;
}
/**
2022-05-02 10:21:25 +00:00
* creates an object with all user data
2022-04-29 13:58:37 +00:00
*
* @param string $userId
* @param bool $includeScopes
* @return array
2022-05-02 10:21:25 +00:00
* @throws Exception
2022-04-29 13:58:37 +00:00
*/
protected function getSCIMUser(string $userId): array {
// Check if the target user exists
$targetUserObject = $this->userManager->get($userId);
if ($targetUserObject === null) {
2022-05-02 10:21:25 +00:00
return [];
2022-04-29 13:58:37 +00:00
}
2022-04-29 16:03:57 +00:00
$enabled = $this->config->getUserValue($targetUserObject->getUID(), 'core', 'enabled', 'true') === 'true';
2022-04-29 13:58:37 +00:00
return [
'schemas' => ["urn:ietf:params:scim:schemas:core:2.0:User"],
'id' => $userId,
2022-05-02 10:21:25 +00:00
'name' => [
'formatted' => $targetUserObject->getDisplayName()
],
2022-04-29 13:58:37 +00:00
'meta' => [
'resourceType' => 'User',
'location' => '/Users/' . $userId,
2022-05-02 10:21:25 +00:00
'created' => '2022-04-28T18:27:17.783Z', // todo
'lastModified' => '2022-04-28T18:27:17.783Z' // todo
2022-04-29 13:58:37 +00:00
],
'userName' => $userId,
'displayName' => $targetUserObject->getDisplayName(),
2022-05-02 10:21:25 +00:00
'emails' => [ // todo if no emails
2022-04-29 16:02:39 +00:00
[
2022-04-29 13:58:37 +00:00
'primary' => true,
'value' => $targetUserObject->getSystemEMailAddress()
2022-04-29 16:02:39 +00:00
]
2022-04-29 13:58:37 +00:00
],
2022-05-02 10:21:25 +00:00
'externalId' => '1234', // todo
2022-04-29 16:03:57 +00:00
'active' => $enabled
2022-04-29 13:58:37 +00:00
];
}
}