fix: [users:view] Gracefully handle the case where user exist in cerebrate but not in keycloak

develop-unstable
Sami Mokaddem 2022-12-13 15:44:37 +01:00
parent 8c94aae994
commit 0b052aaebf
No known key found for this signature in database
GPG Key ID: 164C473F627A06FA
2 changed files with 3 additions and 3 deletions

View File

@ -160,7 +160,7 @@ class UsersController extends AppController
'afterFind' => function($data) use ($keycloakUsersParsed) { 'afterFind' => function($data) use ($keycloakUsersParsed) {
$data = $this->fetchTable('PermissionLimitations')->attachLimitations($data); $data = $this->fetchTable('PermissionLimitations')->attachLimitations($data);
if (!empty(Configure::read('keycloak.enabled'))) { if (!empty(Configure::read('keycloak.enabled'))) {
$keycloakUser = $keycloakUsersParsed[$data->username]; $keycloakUser = $keycloakUsersParsed[$data->username] ?? [];
$data['keycloak_status'] = array_values($this->Users->checkKeycloakStatus([$data->toArray()], [$keycloakUser]))[0]; $data['keycloak_status'] = array_values($this->Users->checkKeycloakStatus([$data->toArray()], [$keycloakUser]))[0];
} }
return $data; return $data;

View File

@ -405,7 +405,8 @@ class AuthKeycloakBehavior extends Behavior
$status = []; $status = [];
foreach ($users as $username => $user) { foreach ($users as $username => $user) {
$differences = []; $differences = [];
$requireUpdate = $this->checkKeycloakUserRequiresUpdate($keycloakUsersParsed[$username], $user, $differences); $keycloakUser = $keycloakUsersParsed[$username] ?? [];
$requireUpdate = $this->checkKeycloakUserRequiresUpdate($keycloakUser, $user, $differences);
$status[$user['id']] = [ $status[$user['id']] = [
'require_update' => $requireUpdate, 'require_update' => $requireUpdate,
'differences' => $differences, 'differences' => $differences,
@ -416,7 +417,6 @@ class AuthKeycloakBehavior extends Behavior
private function checkKeycloakUserRequiresUpdate(array $keycloakUser, array $user, array &$differences = []): bool private function checkKeycloakUserRequiresUpdate(array $keycloakUser, array $user, array &$differences = []): bool
{ {
$condEnabled = $keycloakUser['enabled'] == $user['disabled']; $condEnabled = $keycloakUser['enabled'] == $user['disabled'];
$condFirstname = mb_strtolower($keycloakUser['firstName']) !== mb_strtolower($user['individual']['first_name']); $condFirstname = mb_strtolower($keycloakUser['firstName']) !== mb_strtolower($user['individual']['first_name']);
$condLastname = mb_strtolower($keycloakUser['lastName']) !== mb_strtolower($user['individual']['last_name']); $condLastname = mb_strtolower($keycloakUser['lastName']) !== mb_strtolower($user['individual']['last_name']);