Adds externalId

and manages better emails.
This commit is contained in:
Pierre Ozoux 2022-05-19 16:51:31 +02:00
parent 14a631aac3
commit b3f3df69c6
3 changed files with 32 additions and 10 deletions

View file

@ -26,9 +26,7 @@ For CI, there is still [a bug](https://github.com/Kong/insomnia/issues/4747) we
- createdAt
- lastModified
- [ ] ExternalID
- [ ] Users
- [ ] Groups - [waiting for feedback](https://help.nextcloud.com/t/add-metadata-to-groups/139271)
- [ ] if no emails in user, return nice array
- [ ] json exceptions
- [ ] group member removal
- [ ] pagination

View file

@ -89,6 +89,7 @@ class UserController extends ApiController {
* @param bool $active
* @param string $displayName
* @param array $emails
* @param string $externalId
* @param string $userName
* @return SCIMJSONResponse
* @throws Exception
@ -96,6 +97,7 @@ class UserController extends ApiController {
public function create(bool $active = true,
string $displayName = '',
array $emails = [],
string $externalId = '',
string $userName = ''): SCIMJSONResponse {
if ($this->userManager->userExists($userName)) {
$this->logger->error('Failed createUser attempt: User already exists.', ['app' => 'SCIMServiceProvider']);
@ -112,6 +114,7 @@ class UserController extends ApiController {
}
}
$newUser->setEnabled($active);
$this->SCIMUser->setExternalId($userName, $externalId);
return new SCIMJSONResponse($this->SCIMUser->get($userName));
} catch (Exception $e) {
$this->logger->warning('Failed createUser attempt with SCIMException exeption.', ['app' => 'SCIMServiceProvider']);

View file

@ -35,8 +35,11 @@ class SCIMUser {
}
$enabled = $this->config->getUserValue($targetUserObject->getUID(), 'core', 'enabled', 'true') === 'true';
$externalId = $this->config->getUserValue($targetUserObject->getUID(), 'SCIMServiceProvider', 'ExternalId', '');
$email = $targetUserObject->getSystemEMailAddress();
return [
$SCIMUser = [
'schemas' => ["urn:ietf:params:scim:schemas:core:2.0:User"],
'id' => $userId,
'name' => [
@ -50,14 +53,32 @@ class SCIMUser {
],
'userName' => $userId,
'displayName' => $targetUserObject->getDisplayName(),
'emails' => [ // todo if no emails
[
'primary' => true,
'value' => $targetUserObject->getSystemEMailAddress()
]
],
'externalId' => '1234', // todo
'active' => $enabled
];
if ($externalId !== '') {
$SCIMUser['externalId'] = $externalId;
}
if ($email !== null) {
$SCIMUser['email'] = [ // todo if no emails
[
'primary' => true,
'value' => $email
]
];
}
return $SCIMUser;
}
/**
* Sets externalId on user
*
* @param string $userId
* @param string $externalId
* @throws Exception
*/
public function setExternalId(string $userId, string $externalId) {
$this->config->setUserValue($userId, 'SCIMServiceProvider', 'ExternalId', $externalId);
}
}