mirror of
https://github.com/netzbegruenung/user_saml.git
synced 2024-04-27 14:54:53 +02:00
add occ commands for config manipulation
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
This commit is contained in:
parent
be6a8e97fe
commit
7bdad55dc9
|
@ -36,6 +36,10 @@ While theoretically any other authentication provider implementing either one of
|
|||
<nextcloud min-version="21" max-version="24" />
|
||||
</dependencies>
|
||||
<commands>
|
||||
<command>OCA\User_SAML\Command\ConfigCreate</command>
|
||||
<command>OCA\User_SAML\Command\ConfigDelete</command>
|
||||
<command>OCA\User_SAML\Command\ConfigGet</command>
|
||||
<command>OCA\User_SAML\Command\ConfigSet</command>
|
||||
<command>OCA\User_SAML\Command\GetMetadata</command>
|
||||
</commands>
|
||||
<settings>
|
||||
|
|
53
lib/Command/ConfigCreate.php
Normal file
53
lib/Command/ConfigCreate.php
Normal file
|
@ -0,0 +1,53 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @copyright Copyright (c) 2021 Arthur Schiwon <blizzz@arthur-schiwon.de>
|
||||
*
|
||||
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
|
||||
*
|
||||
* @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 <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OCA\User_SAML\Command;
|
||||
|
||||
use OC\Core\Command\Base;
|
||||
use OCA\User_SAML\SAMLSettings;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
class ConfigCreate extends Base {
|
||||
|
||||
/** @var SAMLSettings */
|
||||
private $samlSettings;
|
||||
|
||||
public function __construct(SAMLSettings $samlSettings) {
|
||||
parent::__construct();
|
||||
$this->samlSettings = $samlSettings;
|
||||
}
|
||||
|
||||
protected function configure() {
|
||||
$this->setName('saml:config:create');
|
||||
$this->setDescription('Creates a new config and prints the new provider ID');
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int {
|
||||
$output->writeln($this->samlSettings->getNewProviderId());
|
||||
return 0;
|
||||
}
|
||||
}
|
59
lib/Command/ConfigDelete.php
Normal file
59
lib/Command/ConfigDelete.php
Normal file
|
@ -0,0 +1,59 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @copyright Copyright (c) 2021 Arthur Schiwon <blizzz@arthur-schiwon.de>
|
||||
*
|
||||
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
|
||||
*
|
||||
* @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 <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OCA\User_SAML\Command;
|
||||
|
||||
use OC\Core\Command\Base;
|
||||
use OCA\User_SAML\SAMLSettings;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
class ConfigDelete extends Base {
|
||||
/** @var SAMLSettings */
|
||||
private $samlSettings;
|
||||
|
||||
public function __construct(SAMLSettings $samlSettings) {
|
||||
parent::__construct();
|
||||
$this->samlSettings = $samlSettings;
|
||||
}
|
||||
|
||||
protected function configure() {
|
||||
$this->setName('saml:config:delete');
|
||||
|
||||
$this->addArgument(
|
||||
'providerId',
|
||||
InputArgument::REQUIRED,
|
||||
'ProviderID of the SAML config to edit'
|
||||
);
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int {
|
||||
$pId = (int)$input->getArgument('providerId');
|
||||
$this->samlSettings->delete($pId);
|
||||
return 0;
|
||||
}
|
||||
}
|
74
lib/Command/ConfigGet.php
Normal file
74
lib/Command/ConfigGet.php
Normal file
|
@ -0,0 +1,74 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @copyright Copyright (c) 2021 Arthur Schiwon <blizzz@arthur-schiwon.de>
|
||||
*
|
||||
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
|
||||
*
|
||||
* @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 <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OCA\User_SAML\Command;
|
||||
|
||||
use OC\Core\Command\Base;
|
||||
use OCA\User_SAML\SAMLSettings;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
class ConfigGet extends Base {
|
||||
|
||||
/** @var SAMLSettings */
|
||||
private $samlSettings;
|
||||
|
||||
public function __construct(SAMLSettings $samlSettings) {
|
||||
parent::__construct();
|
||||
$this->samlSettings = $samlSettings;
|
||||
}
|
||||
|
||||
protected function configure() {
|
||||
$this->setName('saml:config:get');
|
||||
|
||||
$this->addOption(
|
||||
'providerId',
|
||||
'p',
|
||||
InputOption::VALUE_REQUIRED,
|
||||
'ProviderID of a SAML config to print'
|
||||
);
|
||||
parent::configure();
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int {
|
||||
$providerId = (int)$input->getOption('providerId');
|
||||
if (!empty($providerId)) {
|
||||
$providerIds = [$providerId];
|
||||
} else {
|
||||
$providerIds = array_keys($this->samlSettings->getListOfIdps());
|
||||
}
|
||||
|
||||
$settings = [];
|
||||
foreach ($providerIds as $pid) {
|
||||
$settings[$pid] = $this->samlSettings->get($pid);
|
||||
}
|
||||
|
||||
$this->writeArrayInOutputFormat($input, $output, $settings);
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
84
lib/Command/ConfigSet.php
Normal file
84
lib/Command/ConfigSet.php
Normal file
|
@ -0,0 +1,84 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @copyright Copyright (c) 2021 Arthur Schiwon <blizzz@arthur-schiwon.de>
|
||||
*
|
||||
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
|
||||
*
|
||||
* @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 <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OCA\User_SAML\Command;
|
||||
|
||||
use OC\Core\Command\Base;
|
||||
use OCA\User_SAML\SAMLSettings;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
class ConfigSet extends Base {
|
||||
|
||||
/** @var SAMLSettings */
|
||||
private $samlSettings;
|
||||
|
||||
public function __construct(SAMLSettings $samlSettings) {
|
||||
parent::__construct();
|
||||
$this->samlSettings = $samlSettings;
|
||||
}
|
||||
|
||||
protected function configure() {
|
||||
$this->setName('saml:config:set');
|
||||
|
||||
$this->addArgument(
|
||||
'providerId',
|
||||
InputArgument::REQUIRED,
|
||||
'ProviderID of the SAML config to edit'
|
||||
);
|
||||
|
||||
foreach (SAMLSettings::IDP_CONFIG_KEYS as $key) {
|
||||
$this->addOption(
|
||||
$key,
|
||||
null,
|
||||
InputOption::VALUE_REQUIRED,
|
||||
);
|
||||
}
|
||||
|
||||
parent::configure();
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int {
|
||||
$pId = (int)$input->getArgument('providerId');
|
||||
$settings = $this->samlSettings->get($pId);
|
||||
|
||||
foreach ($input->getOptions() as $key => $value) {
|
||||
if(!in_array($key, SAMLSettings::IDP_CONFIG_KEYS) || $value === null) {
|
||||
continue;
|
||||
}
|
||||
if ($value === '') {
|
||||
unset($settings[$key]);
|
||||
continue;
|
||||
}
|
||||
$settings[$key] = $value;
|
||||
}
|
||||
$this->samlSettings->set($pId, $settings);
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
|
@ -74,6 +74,15 @@ class FeatureContext implements Context {
|
|||
)
|
||||
);
|
||||
}
|
||||
|
||||
shell_exec(
|
||||
sprintf(
|
||||
'sudo -u apache %s %s saml:config:delete 1',
|
||||
PHP_BINARY,
|
||||
__DIR__ . '/../../../../../../occ',
|
||||
)
|
||||
);
|
||||
|
||||
$this->changedSettings = [];
|
||||
}
|
||||
|
||||
|
@ -85,14 +94,34 @@ class FeatureContext implements Context {
|
|||
*/
|
||||
public function theSettingIsSetTo($settingName,
|
||||
$value) {
|
||||
$this->changedSettings[] = $settingName;
|
||||
|
||||
if (in_array($settingName, [
|
||||
'type',
|
||||
'general-require_provisioned_account',
|
||||
'general-allow_multiple_user_back_ends',
|
||||
'general-use_saml_auth_for_desktop'
|
||||
])) {
|
||||
$this->changedSettings[] = $settingName;
|
||||
shell_exec(
|
||||
sprintf(
|
||||
'sudo -u apache %s %s config:app:set --value="%s" user_saml %s',
|
||||
PHP_BINARY,
|
||||
__DIR__ . '/../../../../../../occ',
|
||||
$value,
|
||||
$settingName
|
||||
)
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
shell_exec(
|
||||
sprintf(
|
||||
'sudo -u apache %s %s config:app:set --value="%s" user_saml %s',
|
||||
'sudo -u apache %s %s saml:config:set --"%s"="%s" %d',
|
||||
PHP_BINARY,
|
||||
__DIR__ . '/../../../../../../occ',
|
||||
$settingName,
|
||||
$value,
|
||||
$settingName
|
||||
1
|
||||
)
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue