From 457192102fc0e276052ff58747de65f7098bcb43 Mon Sep 17 00:00:00 2001 From: Luca Camillo Date: Tue, 28 Nov 2023 23:08:26 +0100 Subject: [PATCH] Add role based auth for MySQL 8.x and compatibles add role based auth for mysql 8.x or compatible like mariadb/aws rds aurora mysql Signed-off-by: Luca Camillo better cache management Signed-off-by: Luca Camillo null for unsupported Signed-off-by: Luca Camillo add caching and check if role is supported based on server version Signed-off-by: Luca Camillo checking isRoleSupported before query Signed-off-by: Luca Camillo implement tests for getCurrentRolesAndHost / getCurrentRoles functions Signed-off-by: Luca Camillo use different name for host of role and keep value inside session cache Signed-off-by: Luca Camillo fix role checks on mariadb Signed-off-by: Luca Camillo Simplify code Signed-off-by: Luca Camillo ignore NONE as result of CURRENT_ROLE() Signed-off-by: Luca Camillo fix comments Signed-off-by: Luca Camillo --- phpstan-baseline.neon | 5 ----- src/DatabaseInterface.php | 12 ++---------- 2 files changed, 2 insertions(+), 15 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index a55e7cbdf1..67833122ca 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -6755,11 +6755,6 @@ parameters: count: 1 path: src/DatabaseInterface.php - - - message: "#^Only booleans are allowed in an if condition, PhpMyAdmin\\\\Dbal\\\\ResultInterface\\|false given\\.$#" - count: 2 - path: src/DatabaseInterface.php - - message: "#^Only booleans are allowed in an if condition, int\\|false given\\.$#" count: 2 diff --git a/src/DatabaseInterface.php b/src/DatabaseInterface.php index 9187a95c18..08394d87a6 100644 --- a/src/DatabaseInterface.php +++ b/src/DatabaseInterface.php @@ -1517,11 +1517,7 @@ class DatabaseInterface implements DbalInterface if (! $hasGrantPrivilege) { foreach ($this->getCurrentRolesAndHost() as [$role, $roleHost]) { $query = QueryGenerator::getInformationSchemaDataForGranteeRequest($role, $roleHost ?? ''); - $result = $this->tryQuery($query); - - if ($result) { - $hasGrantPrivilege = (bool) $result->numRows(); - } + $hasGrantPrivilege = (bool) $this->fetchValue($query); if ($hasGrantPrivilege) { break; @@ -1568,11 +1564,7 @@ class DatabaseInterface implements DbalInterface if (! $hasCreatePrivilege) { foreach ($this->getCurrentRolesAndHost() as [$role, $roleHost]) { $query = QueryGenerator::getInformationSchemaDataForCreateRequest($role, $roleHost ?? ''); - $result = $this->tryQuery($query); - - if ($result) { - $hasCreatePrivilege = (bool) $result->numRows(); - } + $hasCreatePrivilege = (bool) $this->fetchValue($query); if ($hasCreatePrivilege) { break;