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 - createdAt
- lastModified - lastModified
- [ ] ExternalID - [ ] ExternalID
- [ ] Users
- [ ] Groups - [waiting for feedback](https://help.nextcloud.com/t/add-metadata-to-groups/139271) - [ ] Groups - [waiting for feedback](https://help.nextcloud.com/t/add-metadata-to-groups/139271)
- [ ] if no emails in user, return nice array
- [ ] json exceptions - [ ] json exceptions
- [ ] group member removal - [ ] group member removal
- [ ] pagination - [ ] pagination

View file

@ -89,6 +89,7 @@ class UserController extends ApiController {
* @param bool $active * @param bool $active
* @param string $displayName * @param string $displayName
* @param array $emails * @param array $emails
* @param string $externalId
* @param string $userName * @param string $userName
* @return SCIMJSONResponse * @return SCIMJSONResponse
* @throws Exception * @throws Exception
@ -96,6 +97,7 @@ class UserController extends ApiController {
public function create(bool $active = true, public function create(bool $active = true,
string $displayName = '', string $displayName = '',
array $emails = [], array $emails = [],
string $externalId = '',
string $userName = ''): SCIMJSONResponse { string $userName = ''): SCIMJSONResponse {
if ($this->userManager->userExists($userName)) { if ($this->userManager->userExists($userName)) {
$this->logger->error('Failed createUser attempt: User already exists.', ['app' => 'SCIMServiceProvider']); $this->logger->error('Failed createUser attempt: User already exists.', ['app' => 'SCIMServiceProvider']);
@ -112,6 +114,7 @@ class UserController extends ApiController {
} }
} }
$newUser->setEnabled($active); $newUser->setEnabled($active);
$this->SCIMUser->setExternalId($userName, $externalId);
return new SCIMJSONResponse($this->SCIMUser->get($userName)); return new SCIMJSONResponse($this->SCIMUser->get($userName));
} catch (Exception $e) { } catch (Exception $e) {
$this->logger->warning('Failed createUser attempt with SCIMException exeption.', ['app' => 'SCIMServiceProvider']); $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'; $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"], 'schemas' => ["urn:ietf:params:scim:schemas:core:2.0:User"],
'id' => $userId, 'id' => $userId,
'name' => [ 'name' => [
@ -50,14 +53,32 @@ class SCIMUser {
], ],
'userName' => $userId, 'userName' => $userId,
'displayName' => $targetUserObject->getDisplayName(), 'displayName' => $targetUserObject->getDisplayName(),
'emails' => [ // todo if no emails
[
'primary' => true,
'value' => $targetUserObject->getSystemEMailAddress()
]
],
'externalId' => '1234', // todo
'active' => $enabled '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);
}
} }