fix reading and updated name-id-format selection

Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
This commit is contained in:
Arthur Schiwon 2022-02-28 22:45:38 +01:00 committed by blizzz (Rebase PR Action)
parent ee8845252a
commit 4c97efc51b
3 changed files with 19 additions and 2 deletions

View file

@ -229,6 +229,8 @@ $(function() {
} else if (htmlElement.tagName === 'INPUT' && htmlElement.getAttribute('type') === 'checkbox') {
htmlElement.checked = entries[configKey] === '1';
htmlElement.setAttribute('value', entries[configKey] === '1' ? '1' : '0');
} else if (htmlElement.tagName === 'SELECT') {
htmlElement.querySelector('[value="' + entries[configKey] + '"]').selected = true;
} else {
console.error("Could not handle " + configKey + " Tag is " + htmlElement.tagName + " and type is " + htmlElement.getAttribute("type"));
}

View file

@ -30,6 +30,7 @@ use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\Http\Response;
use OCP\IConfig;
use OCP\IRequest;
use OneLogin\Saml2\Constants;
class SettingsController extends Controller {
@ -76,7 +77,9 @@ class SettingsController extends Controller {
'x509cert' => ['required' => false],
];
/* Fetch all config values for the given providerId */
$settings = [];
// initialize settings with default value for option box (others are left empty)
$settings['sp']['name-id-format'] = Constants::NAMEID_UNSPECIFIED;
$storedSettings = $this->samlSettings->get($providerId);
foreach ($params as $category => $content) {
if (empty($content) || $category === 'providers' || $category === 'type') {
@ -92,6 +95,12 @@ class SettingsController extends Controller {
if (strpos($category, 'attribute-mapping') === 0) {
$category = 'attribute-mapping';
$key = 'saml-attribute-mapping' . '-' . $setting;
} else if($category === 'name-id-formats') {
if ($setting === $storedSettings['sp-name-id-format']) {
$settings['sp']['name-id-format'] = $storedSettings['sp-name-id-format'];
//continue 2;
}
continue;
} else {
$key = $category . '-' . $setting;
}

View file

@ -138,6 +138,7 @@ class Admin implements ISettings {
];
$firstIdPConfig = isset($providers[0]) ? $this->samlSettings->get($providers[0]['id']) : null;
$nameIdFormats = [
Constants::NAMEID_EMAIL_ADDRESS => [
'label' => $this->l10n->t('Email address'),
@ -176,6 +177,11 @@ class Admin implements ISettings {
'selected' => false,
],
];
if ($firstIdPConfig !== null && isset($nameIdFormats[$firstIdPConfig['sp-name-id-format']])) {
$nameIdFormats[$firstIdPConfig['sp-name-id-format']]['selected'] = true;
} else {
$nameIdFormats[Constants::NAMEID_UNSPECIFIED]['selected'] = true;
}
$type = $this->config->getAppValue('user_saml', 'type');
if ($type === 'saml') {
@ -207,7 +213,7 @@ class Admin implements ISettings {
'name-id-formats' => $nameIdFormats,
'type' => $type,
'providers' => $providers,
'config' => isset($providers[0]) ? $this->samlSettings->get($providers[0]['id']) : null,
'config' => $firstIdPConfig,
];
return new TemplateResponse('user_saml', 'admin', $params);