scimserviceprovider/lib/Service/SCIMUser.php

64 lines
1.5 KiB
PHP
Raw Normal View History

2022-04-29 13:58:37 +00:00
<?php
declare(strict_types=1);
2022-05-18 16:51:34 +00:00
namespace OCA\SCIMServiceProvider\Service;
2022-04-29 13:58:37 +00:00
use OCP\IConfig;
use OCP\IUserManager;
2022-05-18 16:51:34 +00:00
class SCIMUser {
2022-04-29 13:58:37 +00:00
/** @var IUserManager */
protected $userManager;
/** @var IConfig */
protected $config;
2022-05-18 16:51:34 +00:00
public function __construct(IUserManager $userManager,
IConfig $config) {
2022-04-29 13:58:37 +00:00
$this->userManager = $userManager;
$this->config = $config;
}
/**
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
*/
2022-05-18 16:51:34 +00:00
public function get(string $userId): array {
2022-04-29 13:58:37 +00:00
// 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()
],
'meta' => [
2022-04-29 13:58:37 +00:00
'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
],
'userName' => $userId,
'displayName' => $targetUserObject->getDisplayName(),
'emails' => [ // todo if no emails
2022-04-29 16:02:39 +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
'active' => $enabled
];
2022-04-29 13:58:37 +00:00
}
}