Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix authenticating layers against qGIS auth config #4794

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion lizmap/modules/lizmap/classes/qgisVectorLayer.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
);
Expand Down Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class qgisVectorLayerDatasource
'user' => "user='?([^ ']+)'? ",
'password' => "password='?([^ ']+)'? ",
'sslmode' => "sslmode='?([^ ']+)'? ",
'authcfg' => "authcfg='?([^ ']+)'? ",
'key' => "key='?([^ ']+)'? ",
'estimatedmetadata' => 'estimatedmetadata=([^ ]+) ',
'selectatid' => 'selectatid=([^ ]+) ',
Expand Down
Loading