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,6 +297,7 @@ class AuthKeycloakBehavior extends Behavior
'modified' => [], 'modified' => [],
]; ];
foreach ($users as &$user) { foreach ($users as &$user) {
try {
if (empty($keycloakUsersParsed[$user['username']])) { if (empty($keycloakUsersParsed[$user['username']])) {
if ($this->createUser($user, $clientId)) { if ($this->createUser($user, $clientId)) {
$changes['created'][] = $user['username']; $changes['created'][] = $user['username'];
@ -306,6 +307,17 @@ class AuthKeycloakBehavior extends Behavior
$changes['modified'][] = $user['username']; $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;
} }