new: [user:edit] Added keycloak updates when a user gets modified
parent
37094e0abb
commit
21403995e3
|
@ -145,6 +145,30 @@ class AuthKeycloakBehavior extends Behavior
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* handleUserUpdate
|
||||||
|
*
|
||||||
|
* @param \App\Model\Entity\User $user
|
||||||
|
* @return boolean If the update was a success
|
||||||
|
*/
|
||||||
|
public function handleUserUpdate(\App\Model\Entity\User $user): bool
|
||||||
|
{
|
||||||
|
$user['individual'] = $this->_table->Individuals->find()->where([
|
||||||
|
'id' => $user['individual_id']
|
||||||
|
])->first();
|
||||||
|
$user['role'] = $this->_table->Roles->find()->where([
|
||||||
|
'id' => $user['role_id']
|
||||||
|
])->first();
|
||||||
|
$user['organisation'] = $this->_table->Organisations->find()->where([
|
||||||
|
'id' => $user['organisation_id']
|
||||||
|
])->first();
|
||||||
|
|
||||||
|
$users = [$user->toArray()];
|
||||||
|
$clientId = $this->getClientId();
|
||||||
|
$changes = $this->syncUsers($users, $clientId);
|
||||||
|
return !empty($changes);
|
||||||
|
}
|
||||||
|
|
||||||
private function getAdminAccessToken()
|
private function getAdminAccessToken()
|
||||||
{
|
{
|
||||||
$keycloakConfig = Configure::read('keycloak');
|
$keycloakConfig = Configure::read('keycloak');
|
||||||
|
|
|
@ -61,6 +61,12 @@ class UsersTable extends AppTable
|
||||||
$data['username'] = trim(mb_strtolower($data['username']));
|
$data['username'] = trim(mb_strtolower($data['username']));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function beforeSave(EventInterface $event, EntityInterface $entity, ArrayObject $options)
|
||||||
|
{
|
||||||
|
$success = $this->handleUserUpdateRouter($entity);
|
||||||
|
return $success;
|
||||||
|
}
|
||||||
|
|
||||||
private function initAuthBehaviors()
|
private function initAuthBehaviors()
|
||||||
{
|
{
|
||||||
if (!empty(Configure::read('keycloak'))) {
|
if (!empty(Configure::read('keycloak'))) {
|
||||||
|
@ -208,4 +214,13 @@ class UsersTable extends AppTable
|
||||||
$this->enrollUser($data);
|
$this->enrollUser($data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function handleUserUpdateRouter(\App\Model\Entity\User $user): bool
|
||||||
|
{
|
||||||
|
if (!empty(Configure::read('keycloak'))) {
|
||||||
|
$success = $this->handleUserUpdate($user);
|
||||||
|
return $success;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue