chg: [behavior:keycloak] Gracefully handle issues while syncing with keycloak

develop-unstable
Sami Mokaddem 2022-12-12 16:56:51 +01:00
parent 178a5b658f
commit d293cb52f8
No known key found for this signature in database
GPG Key ID: 164C473F627A06FA
1 changed files with 19 additions and 7 deletions

View File

@ -297,14 +297,26 @@ class AuthKeycloakBehavior extends Behavior
'modified' => [], 'modified' => [],
]; ];
foreach ($users as &$user) { foreach ($users as &$user) {
if (empty($keycloakUsersParsed[$user['username']])) { try {
if ($this->createUser($user, $clientId)) { if (empty($keycloakUsersParsed[$user['username']])) {
$changes['created'][] = $user['username']; if ($this->createUser($user, $clientId)) {
} $changes['created'][] = $user['username'];
} else { }
if ($this->checkAndUpdateUser($keycloakUsersParsed[$user['username']], $user)) { } else {
$changes['modified'][] = $user['username']; if ($this->checkAndUpdateUser($keycloakUsersParsed[$user['username']], $user)) {
$changes['modified'][] = $user['username'];
}
} }
} catch (\Exception $e) {
$this->_table->auditLogs()->insert([
'request_action' => 'syncUsers',
'model' => 'User',
'model_id' => 0,
'model_title' => __('Failed to create or modify user ({0}) in keycloak', $user['username']),
'changed' => [
'message' => $e->getMessage(),
]
]);
} }
} }
return $changes; return $changes;