2018-05-13 19:14:05 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @copyright Copyright (c) 2018 Julius Härtl <jus@bitgrid.net>
|
|
|
|
*
|
|
|
|
* @author Julius Härtl <jus@bitgrid.net>
|
|
|
|
*
|
|
|
|
* @license GNU AGPL version 3 or any later version
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace OCA\User_SAML\Controller;
|
|
|
|
|
2021-11-09 02:45:45 +01:00
|
|
|
use OCA\User_SAML\SAMLSettings;
|
2018-05-13 19:14:05 +02:00
|
|
|
use OCA\User_SAML\Settings\Admin;
|
|
|
|
use OCP\AppFramework\Controller;
|
2021-11-09 02:45:45 +01:00
|
|
|
use OCP\AppFramework\Http\DataResponse;
|
2018-07-06 20:55:24 +02:00
|
|
|
use OCP\AppFramework\Http\Response;
|
2018-05-13 19:14:05 +02:00
|
|
|
use OCP\IConfig;
|
|
|
|
use OCP\IRequest;
|
2022-02-28 22:45:38 +01:00
|
|
|
use OneLogin\Saml2\Constants;
|
2018-05-13 19:14:05 +02:00
|
|
|
|
|
|
|
class SettingsController extends Controller {
|
|
|
|
|
|
|
|
/** @var IConfig */
|
|
|
|
private $config;
|
|
|
|
/** @var Admin */
|
|
|
|
private $admin;
|
2021-11-09 02:45:45 +01:00
|
|
|
/** @var SAMLSettings */
|
|
|
|
private $samlSettings;
|
2018-05-13 19:14:05 +02:00
|
|
|
|
2021-11-09 02:45:45 +01:00
|
|
|
public function __construct(
|
|
|
|
$appName,
|
|
|
|
IRequest $request,
|
|
|
|
IConfig $config,
|
|
|
|
Admin $admin,
|
|
|
|
SAMLSettings $samlSettings
|
|
|
|
) {
|
2018-05-13 19:14:05 +02:00
|
|
|
parent::__construct($appName, $request);
|
|
|
|
$this->config = $config;
|
|
|
|
$this->admin = $admin;
|
2021-11-09 02:45:45 +01:00
|
|
|
$this->samlSettings = $samlSettings;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getSamlProviderIds(): DataResponse {
|
|
|
|
$keys = array_keys($this->samlSettings->getListOfIdps());
|
|
|
|
return new DataResponse([ 'providerIds' => implode(',', $keys)]);
|
2018-05-13 19:14:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $providerId
|
|
|
|
* @return array of categories containing entries for each config parameter with their value
|
|
|
|
*/
|
2021-11-09 02:45:45 +01:00
|
|
|
public function getSamlProviderSettings(int $providerId) {
|
2018-05-13 19:14:05 +02:00
|
|
|
/**
|
|
|
|
* This uses the list of available config parameters from the admin section
|
|
|
|
* and extends it with fields that are not coming from \OCA\User_SAML\Settings\Admin
|
|
|
|
*/
|
|
|
|
$params = $this->admin->getForm()->getParams();
|
|
|
|
$params['idp'] = [
|
2018-07-10 20:08:42 +02:00
|
|
|
'singleLogoutService.url' => ['required' => false],
|
2020-06-22 18:21:30 +02:00
|
|
|
'singleLogoutService.responseUrl' => ['required' => false],
|
2018-07-10 20:08:42 +02:00
|
|
|
'singleSignOnService.url' => ['required' => false],
|
|
|
|
'entityId' => ['required' => false],
|
|
|
|
'x509cert' => ['required' => false],
|
2018-05-13 19:14:05 +02:00
|
|
|
];
|
|
|
|
/* Fetch all config values for the given providerId */
|
2022-02-28 22:45:38 +01:00
|
|
|
|
|
|
|
// initialize settings with default value for option box (others are left empty)
|
|
|
|
$settings['sp']['name-id-format'] = Constants::NAMEID_UNSPECIFIED;
|
2021-11-09 02:45:45 +01:00
|
|
|
$storedSettings = $this->samlSettings->get($providerId);
|
2018-05-13 19:14:05 +02:00
|
|
|
foreach ($params as $category => $content) {
|
2018-07-11 12:22:21 +02:00
|
|
|
if (empty($content) || $category === 'providers' || $category === 'type') {
|
2018-05-13 19:14:05 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
foreach ($content as $setting => $details) {
|
|
|
|
/* use security as category instead of security-* */
|
|
|
|
if (strpos($category, 'security-') === 0) {
|
|
|
|
$category = 'security';
|
|
|
|
}
|
2018-07-11 13:32:07 +02:00
|
|
|
// make sure we properly fetch the attribute mapping
|
|
|
|
// as this is the only category that has the saml- prefix on config keys
|
|
|
|
if (strpos($category, 'attribute-mapping') === 0) {
|
|
|
|
$category = 'attribute-mapping';
|
2021-11-09 02:45:45 +01:00
|
|
|
$key = 'saml-attribute-mapping' . '-' . $setting;
|
2022-03-01 10:15:20 +01:00
|
|
|
} elseif ($category === 'name-id-formats') {
|
2022-02-28 22:45:38 +01:00
|
|
|
if ($setting === $storedSettings['sp-name-id-format']) {
|
|
|
|
$settings['sp']['name-id-format'] = $storedSettings['sp-name-id-format'];
|
|
|
|
//continue 2;
|
|
|
|
}
|
|
|
|
continue;
|
2018-07-11 13:32:07 +02:00
|
|
|
} else {
|
2021-11-09 02:45:45 +01:00
|
|
|
$key = $category . '-' . $setting;
|
|
|
|
}
|
|
|
|
|
2021-12-10 08:16:06 +01:00
|
|
|
if (isset($details['global']) && $details['global']) {
|
2022-01-04 16:50:09 +01:00
|
|
|
// Read legacy data from oc_appconfig
|
2021-11-09 02:45:45 +01:00
|
|
|
$settings[$category][$setting] = $this->config->getAppValue('user_saml', $key, '');
|
|
|
|
} else {
|
|
|
|
$settings[$category][$setting] = $storedSettings[$key] ?? '';
|
2018-07-11 13:32:07 +02:00
|
|
|
}
|
2018-05-13 19:14:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return $settings;
|
|
|
|
}
|
|
|
|
|
2018-07-05 21:54:24 +02:00
|
|
|
public function deleteSamlProviderSettings($providerId) {
|
2021-11-09 02:45:45 +01:00
|
|
|
$this->samlSettings->delete($providerId);
|
|
|
|
return new Response();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setProviderSetting(int $providerId, string $configKey, string $configValue) {
|
|
|
|
$configuration = $this->samlSettings->get($providerId);
|
|
|
|
$configuration[$configKey] = $configValue;
|
|
|
|
$this->samlSettings->set($providerId, $configuration);
|
2018-07-06 20:55:24 +02:00
|
|
|
return new Response();
|
2018-07-05 21:54:24 +02:00
|
|
|
}
|
2021-11-09 02:45:45 +01:00
|
|
|
|
|
|
|
public function newSamlProviderSettingsId() {
|
|
|
|
return new DataResponse(['id' => $this->samlSettings->getNewProviderId()]);
|
|
|
|
}
|
2018-05-13 19:14:05 +02:00
|
|
|
}
|