From cf565484b9115cd672b0b77cb3812d7560e91bec Mon Sep 17 00:00:00 2001 From: DocArmoryTech Date: Wed, 31 Aug 2022 13:20:28 +0100 Subject: [PATCH 1/2] Added checks for KC being enabled (#106) Initialisation of Auth behaviour and enrollment of users in KC, was dependent on the presence of a `keycloak` section in config.json Added checks to ensure KC is configured as "enabled", rather than just checking if a keycloak config section was present. --- src/Model/Table/UsersTable.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Model/Table/UsersTable.php b/src/Model/Table/UsersTable.php index 61f06b8..255fd40 100644 --- a/src/Model/Table/UsersTable.php +++ b/src/Model/Table/UsersTable.php @@ -57,7 +57,9 @@ class UsersTable extends AppTable private function initAuthBehaviors() { if (!empty(Configure::read('keycloak'))) { - $this->addBehavior('AuthKeycloak'); + if (Configure::read('keycloak.enabled')) { + $this->addBehavior('AuthKeycloak'); + } } } @@ -188,7 +190,9 @@ class UsersTable extends AppTable public function enrollUserRouter($data): void { if (!empty(Configure::read('keycloak'))) { - $this->enrollUser($data); + if (Configure::read('keycloak.enabled')) { + $this->enrollUser($data); + } } } } From 9f689cff247caf0885055d5471a74b77ac59d1cf Mon Sep 17 00:00:00 2001 From: DocArmoryTech Date: Fri, 2 Sep 2022 10:10:05 +0100 Subject: [PATCH 2/2] soft squash for stylistic consistency Replaced nested conditionals with cleaner equivalent to better match style --- src/Model/Table/UsersTable.php | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/Model/Table/UsersTable.php b/src/Model/Table/UsersTable.php index 255fd40..dd900c5 100644 --- a/src/Model/Table/UsersTable.php +++ b/src/Model/Table/UsersTable.php @@ -56,10 +56,8 @@ class UsersTable extends AppTable private function initAuthBehaviors() { - if (!empty(Configure::read('keycloak'))) { - if (Configure::read('keycloak.enabled')) { - $this->addBehavior('AuthKeycloak'); - } + if (!empty(Configure::read('keycloak.enabled'))) { + $this->addBehavior('AuthKeycloak'); } } @@ -189,10 +187,8 @@ class UsersTable extends AppTable public function enrollUserRouter($data): void { - if (!empty(Configure::read('keycloak'))) { - if (Configure::read('keycloak.enabled')) { - $this->enrollUser($data); - } + if (!empty(Configure::read('keycloak.enabled'))) { + $this->enrollUser($data); } } }