diff --git a/lib/SimpleSAML/Configuration.php b/lib/SimpleSAML/Configuration.php index 60513d29cf4a3be959cae2927d89dbfd6b4a0c0e..cdb75671dc49752662ee14da28c42f25911c00af 100644 --- a/lib/SimpleSAML/Configuration.php +++ b/lib/SimpleSAML/Configuration.php @@ -876,21 +876,40 @@ class Configuration implements Utils\ClearableState * If the configuration option isn't an array, it will be converted to an array. * * @param string $name The name of the option. - * @param mixed $default A default value which will be returned if the option isn't found. The option will be - * required if this parameter isn't given. The default value can be any value, including - * null. * - * @return mixed The option with the given name, or $default if the option isn't found and $default is specified. + * @return mixed The option with the given name. */ - public function getArrayize(string $name, $default = self::REQUIRED_OPTION) + public function getArrayize(string $name): array { - $ret = $this->getValue($name, $default); + $ret = $this->getValue($name); - if ($ret === $default) { + if (!is_array($ret)) { + $ret = [$ret]; + } + + return $ret; + } + + + /** + * This function retrieves an array configuration option. + * + * If the configuration option isn't an array, it will be converted to an array. + * + * @param string $name The name of the option. + * @param mixed $default A default value which will be returned if the option isn't found. + * The default value can be null or an array. + * + * @return mixed The option with the given name, or $default if the option isn't found and $default is specified. + */ + public function getOptionalArrayize(string $name, $default): ?array + { + if (!$this->hasValue($name)) { // the option wasn't found, or it matches the default value. In any case, return this value - return $ret; + return $default; } + $ret = $this->getValue($name); if (!is_array($ret)) { $ret = [$ret]; } diff --git a/lib/SimpleSAML/Metadata/SAMLBuilder.php b/lib/SimpleSAML/Metadata/SAMLBuilder.php index 7e4933078324f9d9d8b4d101df0b9144dcef0f02..d37f65e9f2e23c6d1db6c3b2fa762dae71ac5b9b 100644 --- a/lib/SimpleSAML/Metadata/SAMLBuilder.php +++ b/lib/SimpleSAML/Metadata/SAMLBuilder.php @@ -518,10 +518,10 @@ class SAMLBuilder $e->setSingleLogoutService(self::createEndpoints($metadata->getEndpoints('SingleLogoutService'), false)); - $e->setNameIDFormat($metadata->getArrayizeString('NameIDFormat', [])); + $e->setNameIDFormat($metadata->getOptionalArrayizeString('NameIDFormat', [])); $endpoints = $metadata->getEndpoints('AssertionConsumerService'); - foreach ($metadata->getArrayizeString('AssertionConsumerService.artifact', []) as $acs) { + foreach ($metadata->getOptionalArrayizeString('AssertionConsumerService.artifact', []) as $acs) { $endpoints[] = [ 'Binding' => Constants::BINDING_HTTP_ARTIFACT, 'Location' => $acs, @@ -575,7 +575,7 @@ class SAMLBuilder $e->setSingleLogoutService(self::createEndpoints($metadata->getEndpoints('SingleLogoutService'), false)); - $e->setNameIDFormat($metadata->getArrayizeString('NameIDFormat', [])); + $e->setNameIDFormat($metadata->getOptionalArrayizeString('NameIDFormat', [])); $e->setSingleSignOnService(self::createEndpoints($metadata->getEndpoints('SingleSignOnService'), false)); @@ -614,7 +614,7 @@ class SAMLBuilder false )); - $e->setNameIDFormat($metadata->getArrayizeString('NameIDFormat', [])); + $e->setNameIDFormat($metadata->getOptionalArrayizeString('NameIDFormat', [])); $this->entityDescriptor->addRoleDescriptor($e); } diff --git a/modules/saml/lib/IdP/SAML2.php b/modules/saml/lib/IdP/SAML2.php index c068e524e1347d1e24ab6a3a6de39508160800a3..620d7893b9f2d3bae29e22db58943cecea82f845 100644 --- a/modules/saml/lib/IdP/SAML2.php +++ b/modules/saml/lib/IdP/SAML2.php @@ -456,7 +456,7 @@ class SAML2 throw new Exception('Unable to use any of the ACS endpoints found for SP \'' . $spEntityId . '\''); } - $IDPList = array_unique(array_merge($IDPList, $spMetadata->getArrayizeString('IDPList', []))); + $IDPList = array_unique(array_merge($IDPList, $spMetadata->getOptionalArrayizeString('IDPList', []))); if ($ProxyCount === null) { $ProxyCount = $spMetadata->getOptionalInteger('ProxyCount', null); } @@ -796,7 +796,7 @@ class SAML2 'entityid' => $entityid, 'SingleSignOnService' => $sso, 'SingleLogoutService' => $slo, - 'NameIDFormat' => $config->getArrayizeString('NameIDFormat', [Constants::NAMEID_TRANSIENT]), + 'NameIDFormat' => $config->getOptionalArrayizeString('NameIDFormat', [Constants::NAMEID_TRANSIENT]), ]; $cryptoUtils = new Utils\Crypto(); @@ -1254,9 +1254,11 @@ class SAML2 if ($nameIdFormat === null || !isset($state['saml:NameID'][$nameIdFormat])) { // either not set in request, or not set to a format we supply. Fall back to old generation method - $nameIdFormat = current($spMetadata->getArrayizeString('NameIDFormat', [])); + $nameIdFormat = current($spMetadata->getOptionalArrayizeString('NameIDFormat', [])); if ($nameIdFormat === false) { - $nameIdFormat = current($idpMetadata->getArrayizeString('NameIDFormat', [Constants::NAMEID_TRANSIENT])); + $nameIdFormat = current( + $idpMetadata->getOptionalArrayizeString('NameIDFormat', [Constants::NAMEID_TRANSIENT]) + ); } }