From d1478182b31564a3a05ba3716d127762785e180d Mon Sep 17 00:00:00 2001 From: Ioannis Igoumenos Date: Thu, 9 Jan 2025 15:23:42 +0200 Subject: [PATCH] Create an enum list of configuration options that are allowed to be overriden. --- src/Cas/ServiceValidator.php | 11 ++++++++++- src/Controller/LoginController.php | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/Cas/ServiceValidator.php b/src/Cas/ServiceValidator.php index cb968ca..d3cb673 100644 --- a/src/Cas/ServiceValidator.php +++ b/src/Cas/ServiceValidator.php @@ -6,6 +6,7 @@ use SimpleSAML\Configuration; use SimpleSAML\Logger; +use SimpleSAML\Module\casserver\Codebooks\OverrideConfigPropertiesEnum; /** * Validates if a CAS service can use server @@ -93,7 +94,15 @@ public function checkServiceURL(string $service): ?Configuration 'matchingUrl' => $legalUrl, 'serviceUrl' => $service, ]; - if ($configOverride) { + if ($configOverride !== null) { + // We need to remove all the unsupported configuration keys + $supportedProperties = array_column(OverrideConfigPropertiesEnum::cases(), 'value'); + $configOverride = array_filter( + $configOverride, + static fn($property) => \in_array($property, $supportedProperties, true), + ARRAY_FILTER_USE_KEY, + ); + // Merge the configurations $serviceConfig = array_merge($serviceConfig, $configOverride); } return Configuration::loadFromArray($serviceConfig); diff --git a/src/Controller/LoginController.php b/src/Controller/LoginController.php index 0bd1ecc..d1a0ab3 100644 --- a/src/Controller/LoginController.php +++ b/src/Controller/LoginController.php @@ -91,7 +91,7 @@ public function __construct( ? Configuration::getConfig('module_casserver.php') : $casConfig; // Saml Validate Responsder $this->samlValidateResponder = new SamlValidateResponder(); - // Service Validator needs the generic casserver configuration. We do not need + // Service Validator needs the generic casserver configuration. $this->serviceValidator = new ServiceValidator($this->casConfig); $this->authSource = $source ?? new Simple($this->casConfig->getValue('authsource')); $this->httpUtils = $httpUtils ?? new Utils\HTTP();