diff --git a/lizmap/modules/lizmap/classes/qgisVectorLayer.class.php b/lizmap/modules/lizmap/classes/qgisVectorLayer.class.php index ec078c6b76..1f16318ebf 100644 --- a/lizmap/modules/lizmap/classes/qgisVectorLayer.class.php +++ b/lizmap/modules/lizmap/classes/qgisVectorLayer.class.php @@ -208,7 +208,7 @@ public function getDatasourceParameters() ); $parameters = array( 'dbname', 'service', 'host', 'port', 'user', 'password', - 'sslmode', 'key', 'estimatedmetadata', 'selectatid', + 'sslmode', 'authcfg', 'key', 'estimatedmetadata', 'selectatid', 'srid', 'type', 'checkPrimaryKeyUnicity', 'table', 'geocol', 'sql', 'schema', 'tablename', ); @@ -279,6 +279,22 @@ public function getDatasourceProfile($timeout = 30, $setSearchPathFromLayer = tr if (!empty($dtParams->sslmode)) { $jdbParams['sslmode'] = $dtParams->sslmode; } + // when qgis authentication config is used to authenticate a layer against, it requires to have preconfigured jdb::profile to align with the login credentials set in qgis authcfg + if (!empty($dtParams->authcfg)) { + $jdbParams['authcfg'] = $dtParams->authcfg; + // retrieving user/password from the corresponding jdb::profile in profiles.ini.php. + $ini = new \Jelix\IniFile\IniModifier(jApp::varConfigPath('profiles.ini.php')); + $profiles = $ini->getSectionList(); + foreach ($profiles as $profile) { + if ($profile == 'jdb:'.$dtParams->authcfg) { + $options = $ini->getValues($profile); + $jdbParams['user'] = $options['user']; + $jdbParams['password'] = $options['password']; + + break; + } + } + } } if (!empty($dtParams->schema) && $setSearchPathFromLayer) { $jdbParams['search_path'] = '"'.$dtParams->schema.'",public'; diff --git a/lizmap/modules/lizmap/classes/qgisVectorLayerDatasource.class.php b/lizmap/modules/lizmap/classes/qgisVectorLayerDatasource.class.php index fe39033d09..9eb2f33d97 100644 --- a/lizmap/modules/lizmap/classes/qgisVectorLayerDatasource.class.php +++ b/lizmap/modules/lizmap/classes/qgisVectorLayerDatasource.class.php @@ -22,6 +22,7 @@ class qgisVectorLayerDatasource 'user' => "user='?([^ ']+)'? ", 'password' => "password='?([^ ']+)'? ", 'sslmode' => "sslmode='?([^ ']+)'? ", + 'authcfg' => "authcfg='?([^ ']+)'? ", 'key' => "key='?([^ ']+)'? ", 'estimatedmetadata' => 'estimatedmetadata=([^ ]+) ', 'selectatid' => 'selectatid=([^ ]+) ',