diff --git a/lib/SimpleSAML/Configuration.php b/lib/SimpleSAML/Configuration.php index f9275d521f0704d3d2499c47b920976f9aac161d..4e885f6ea98073df50b95bffb536f7b8f1d697fe 100644 --- a/lib/SimpleSAML/Configuration.php +++ b/lib/SimpleSAML/Configuration.php @@ -1269,7 +1269,7 @@ class Configuration implements Utils\ClearableState * @param mixed $default The default value. If no default is given, and the option isn't found, an exception will * be thrown. * - * @return array Associative array with language => string pairs. + * @return mixed Associative array with language => string pairs, or the provided default value. * * @throws \Exception If the translation is not an array or a string, or its index or value are not strings. */ diff --git a/lib/SimpleSAML/Metadata/MetaDataStorageHandler.php b/lib/SimpleSAML/Metadata/MetaDataStorageHandler.php index 6e712ea3a3491a332dec2538b5c84a0f88218ab1..a0ee3db680e55e1ac973f90b49e9d4f9a3b072a5 100644 --- a/lib/SimpleSAML/Metadata/MetaDataStorageHandler.php +++ b/lib/SimpleSAML/Metadata/MetaDataStorageHandler.php @@ -19,7 +19,7 @@ class MetaDataStorageHandler implements ClearableState * instance of the metadata handler. This variable will be null if * we haven't instantiated a metadata handler yet. * - * @var MetaDataStorageHandler + * @var MetaDataStorageHandler|null */ private static $metadataHandler = null; @@ -241,7 +241,7 @@ class MetaDataStorageHandler implements ClearableState * @param string $set Which set of metadata we are looking it up in. * @param string $ip IP address * - * @return string The entity id of a entity which have a CIDR hint where the provided + * @return string|null The entity id of a entity which have a CIDR hint where the provided * IP address match. */ public function getPreferredEntityIdFromCIDRhint($set, $ip) @@ -261,7 +261,7 @@ class MetaDataStorageHandler implements ClearableState * This function looks up the metadata for the given entity id in the given set. It will throw an * exception if it is unable to locate the metadata. * - * @param string $index The entity id we are looking up. This parameter may be NULL, in which case we look up + * @param string|null $index The entity id we are looking up. This parameter may be NULL, in which case we look up * the current entity id based on the current hostname/path. * @param string $set The set of metadata we are looking up the entity id in. * @@ -366,6 +366,7 @@ class MetaDataStorageHandler implements ClearableState * Clear any metadata cached. * Allows for metadata configuration to be changed and reloaded during a given request. Most useful * when running phpunit tests and needing to alter config.php and metadata sources between test cases + * @return void */ public static function clearInternalState() { diff --git a/lib/SimpleSAML/Metadata/MetaDataStorageHandlerFlatFile.php b/lib/SimpleSAML/Metadata/MetaDataStorageHandlerFlatFile.php index 2d7883b8c96cfaefc228266581498b5115ca23d3..4664edcab3c1297089865ec2d80b8d605a269fba 100644 --- a/lib/SimpleSAML/Metadata/MetaDataStorageHandlerFlatFile.php +++ b/lib/SimpleSAML/Metadata/MetaDataStorageHandlerFlatFile.php @@ -66,7 +66,7 @@ class MetaDataStorageHandlerFlatFile extends MetaDataStorageSource * * @param string $set The set of metadata we are loading. * - * @return array An associative array with the metadata, or null if we are unable to load metadata from the given + * @return array|null An associative array with the metadata, or null if we are unable to load metadata from the given * file. * @throws Exception If the metadata set cannot be loaded. */ @@ -109,6 +109,7 @@ class MetaDataStorageHandlerFlatFile extends MetaDataStorageSource if ($metadataSet === null) { $metadataSet = []; } + /** @var array $metadataSet */ // add the entity id of an entry to each entry in the metadata foreach ($metadataSet as $entityId => &$entry) { @@ -120,11 +121,15 @@ class MetaDataStorageHandlerFlatFile extends MetaDataStorageSource } $this->cachedMetadata[$set] = $metadataSet; - return $metadataSet; } + /** + * @param string $set + * @throws \Exception + * @return string + */ private function generateDynamicHostedEntityID($set) { // get the configuration diff --git a/lib/SimpleSAML/Metadata/MetaDataStorageHandlerPdo.php b/lib/SimpleSAML/Metadata/MetaDataStorageHandlerPdo.php index 0645a0bec5485e5fb918a6cbba22c5f327b7e3e6..f33f8757089d104189474dd55130e674f1457912 100644 --- a/lib/SimpleSAML/Metadata/MetaDataStorageHandlerPdo.php +++ b/lib/SimpleSAML/Metadata/MetaDataStorageHandlerPdo.php @@ -72,8 +72,8 @@ class MetaDataStorageHandlerPdo extends MetaDataStorageSource * * @param string $set The set of metadata we are loading. * - * @return array $metadata Associative array with the metadata, or NULL if we are unable to load metadata from the - * given file. + * @return array|null $metadata Associative array with the metadata, or NULL if we are unable to load + * metadata from the given file. * * @throws Exception If a database error occurs. * @throws \SimpleSAML\Error\Exception If the metadata can be retrieved from the database, but cannot be decoded. @@ -129,6 +129,7 @@ class MetaDataStorageHandlerPdo extends MetaDataStorageSource if ($metadataSet === null) { $metadataSet = []; } + /** @var array $metadataSet */ foreach ($metadataSet as $entityId => &$entry) { if (preg_match('/__DYNAMIC(:[0-9]+)?__/', $entityId)) { @@ -148,7 +149,7 @@ class MetaDataStorageHandlerPdo extends MetaDataStorageSource * @param string $entityId The entityId we are looking up. * @param string $set The set we are looking for metadata in. * - * @return array An associative array with metadata for the given entity, or NULL if we are unable to + * @return array|null An associative array with metadata for the given entity, or NULL if we are unable to * locate the entity. */ public function getMetaData($entityId, $set) @@ -189,6 +190,11 @@ class MetaDataStorageHandlerPdo extends MetaDataStorageSource } } + /** + * @param string $set + * @throws \Exception + * @return string + */ private function generateDynamicHostedEntityID($set) { assert(is_string($set)); diff --git a/lib/SimpleSAML/Metadata/MetaDataStorageHandlerSerialize.php b/lib/SimpleSAML/Metadata/MetaDataStorageHandlerSerialize.php index 8c050775678d401067097278739cb1e4915680ec..fa57368561aa78726bfbfe527d227c966d024c76 100644 --- a/lib/SimpleSAML/Metadata/MetaDataStorageHandlerSerialize.php +++ b/lib/SimpleSAML/Metadata/MetaDataStorageHandlerSerialize.php @@ -21,7 +21,7 @@ class MetaDataStorageHandlerSerialize extends MetaDataStorageSource /** * The base directory where metadata is stored. * - * @var string + * @var string|null */ private $directory; @@ -168,7 +168,7 @@ class MetaDataStorageHandlerSerialize extends MetaDataStorageSource * @param string $entityId The entityId we are looking up. * @param string $set The set we are looking for metadata in. * - * @return array An associative array with metadata for the given entity, or NULL if we are unable to + * @return array|null An associative array with metadata for the given entity, or NULL if we are unable to * locate the entity. */ public function getMetaData($entityId, $set) @@ -212,7 +212,7 @@ class MetaDataStorageHandlerSerialize extends MetaDataStorageSource * @param string $set The metadata set this metadata entry belongs to. * @param array $metadata The metadata. * - * @return boolean True if successfully saved, false otherwise. + * @return bool True if successfully saved, false otherwise. */ public function saveMetadata($entityId, $set, $metadata) { @@ -261,6 +261,7 @@ class MetaDataStorageHandlerSerialize extends MetaDataStorageSource * * @param string $entityId The entityId of the metadata entry. * @param string $set The metadata set this metadata entry belongs to. + * @return void */ public function deleteMetadata($entityId, $set) { diff --git a/lib/SimpleSAML/Metadata/MetaDataStorageSource.php b/lib/SimpleSAML/Metadata/MetaDataStorageSource.php index 76aeabb635076f76ca54c640aea061331c20d866..ceb10ade551584d873be311773fb0950096b8b07 100644 --- a/lib/SimpleSAML/Metadata/MetaDataStorageSource.php +++ b/lib/SimpleSAML/Metadata/MetaDataStorageSource.php @@ -133,6 +133,7 @@ abstract class MetaDataStorageSource { $metadataSet = $this->getMetadataSet($set); + /** @psalm-suppress DocblockTypeContradiction */ if ($metadataSet === null) { // this metadata source does not have this metadata set return null; @@ -167,7 +168,7 @@ abstract class MetaDataStorageSource * @param string $ip IP address * @param string $type Do you want to return the metaindex or the entityID. [entityid|metaindex] * - * @return string The entity id of a entity which have a CIDR hint where the provided + * @return string|null The entity id of a entity which have a CIDR hint where the provided * IP address match. */ public function getPreferredEntityIdFromCIDRhint($set, $ip, $type = 'entityid') @@ -211,8 +212,10 @@ abstract class MetaDataStorageSource } - /* - * + /** + * @param string $entityId + * @param string $set + * @return mixed|null */ private function lookupIndexFromEntityId($entityId, $set) { @@ -250,7 +253,7 @@ abstract class MetaDataStorageSource * @param string $index The entityId or metaindex we are looking up. * @param string $set The set we are looking for metadata in. * - * @return array An associative array with metadata for the given entity, or NULL if we are unable to + * @return array|null An associative array with metadata for the given entity, or NULL if we are unable to * locate the entity. */ public function getMetaData($index, $set) diff --git a/lib/SimpleSAML/Metadata/SAMLBuilder.php b/lib/SimpleSAML/Metadata/SAMLBuilder.php index 929cb5ebf0678bda483963630dde401a4e2f48c2..733d802f731c4020dc0d0b78c51a9f30802e77f1 100644 --- a/lib/SimpleSAML/Metadata/SAMLBuilder.php +++ b/lib/SimpleSAML/Metadata/SAMLBuilder.php @@ -2,6 +2,8 @@ namespace SimpleSAML\Metadata; +use \SAML2\XML\md\EntityDescriptor; + /** * Class for generating SAML 2.0 metadata from SimpleSAMLphp metadata arrays. * @@ -40,9 +42,10 @@ class SAMLBuilder * Initialize the SAML builder. * * @param string $entityId The entity id of the entity. - * @param double|null $maxCache The maximum time in seconds the metadata should be cached. Defaults to null - * @param double|null $maxDuration The maximum time in seconds this metadata should be considered valid. Defaults + * @param int|null $maxCache The maximum time in seconds the metadata should be cached. Defaults to null + * @param int|null $maxDuration The maximum time in seconds this metadata should be considered valid. Defaults * to null. + * @return void */ public function __construct($entityId, $maxCache = null, $maxDuration = null) { @@ -51,11 +54,15 @@ class SAMLBuilder $this->maxCache = $maxCache; $this->maxDuration = $maxDuration; - $this->entityDescriptor = new \SAML2\XML\md\EntityDescriptor(); + $this->entityDescriptor = new EntityDescriptor(); $this->entityDescriptor->setEntityID($entityId); } + /** + * @param array $metadata + * @return void + */ private function setExpiration($metadata) { if (array_key_exists('expire', $metadata)) { @@ -113,6 +120,7 @@ class SAMLBuilder * Add a SecurityTokenServiceType for ADFS metadata. * * @param array $metadata The metadata with the information about the SecurityTokenServiceType. + * @return void */ public function addSecurityTokenServiceType($metadata) { @@ -136,6 +144,7 @@ class SAMLBuilder * * @param \SimpleSAML\Configuration $metadata The metadata to get extensions from. * @param \SAML2\XML\md\RoleDescriptor $e Reference to the element where the Extensions element should be included. + * @return void */ private function addExtensions(\SimpleSAML\Configuration $metadata, \SAML2\XML\md\RoleDescriptor $e) { @@ -283,6 +292,7 @@ class SAMLBuilder * @param array $orgName An array with the localized OrganizationName. * @param array $orgDisplayName An array with the localized OrganizationDisplayName. * @param array $orgURL An array with the localized OrganizationURL. + * @return void */ public function addOrganization(array $orgName, array $orgDisplayName, array $orgURL) { @@ -300,6 +310,7 @@ class SAMLBuilder * Add an Organization element based on metadata array. * * @param array $metadata The metadata we should extract the organization information from. + * @return void */ public function addOrganizationInfo(array $metadata) { @@ -337,24 +348,6 @@ class SAMLBuilder foreach ($endpoints as &$ep) { if ($indexed) { $t = new \SAML2\XML\md\IndexedEndpointType(); - } else { - $t = new \SAML2\XML\md\EndpointType(); - } - - $t->setBinding($ep['Binding']); - $t->setLocation($ep['Location']); - if (isset($ep['ResponseLocation'])) { - $t->setResponseLocation($ep['ResponseLocation']); - } - if (isset($ep['hoksso:ProtocolBinding'])) { - $t->setAttributeNS( - \SAML2\Constants::NS_HOK, - 'hoksso:ProtocolBinding', - \SAML2\Constants::BINDING_HTTP_REDIRECT - ); - } - - if ($indexed) { if (!isset($ep['index'])) { // Find the maximum index $maxIndex = -1; @@ -372,6 +365,21 @@ class SAMLBuilder } $t->setIndex($ep['index']); + } else { + $t = new \SAML2\XML\md\EndpointType(); + } + + $t->setBinding($ep['Binding']); + $t->setLocation($ep['Location']); + if (isset($ep['ResponseLocation'])) { + $t->setResponseLocation($ep['ResponseLocation']); + } + if (isset($ep['hoksso:ProtocolBinding'])) { + $t->setAttributeNS( + \SAML2\Constants::NS_HOK, + 'hoksso:ProtocolBinding', + \SAML2\Constants::BINDING_HTTP_REDIRECT + ); } $ret[] = $t; @@ -386,6 +394,7 @@ class SAMLBuilder * * @param \SAML2\XML\md\SPSSODescriptor $spDesc The SPSSODescriptor element. * @param \SimpleSAML\Configuration $metadata The metadata. + * @return void */ private function addAttributeConsumingService( \SAML2\XML\md\SPSSODescriptor $spDesc, @@ -441,6 +450,7 @@ class SAMLBuilder * * @param string $set The metadata set this metadata comes from. * @param array $metadata The metadata. + * @return void */ public function addMetadata($set, $metadata) { @@ -476,6 +486,7 @@ class SAMLBuilder * * @param array $metadata The metadata. * @param array $protocols The protocols supported. Defaults to \SAML2\Constants::NS_SAMLP. + * @return void */ public function addMetadataSP20($metadata, $protocols = [\SAML2\Constants::NS_SAMLP]) { @@ -532,6 +543,7 @@ class SAMLBuilder * Add metadata of a SAML 2.0 identity provider. * * @param array $metadata The metadata. + * @return void */ public function addMetadataIdP20($metadata) { @@ -581,6 +593,7 @@ class SAMLBuilder * Add metadata of a SAML 1.1 service provider. * * @param array $metadata The metadata. + * @return void */ public function addMetadataSP11($metadata) { @@ -619,6 +632,7 @@ class SAMLBuilder * Add metadata of a SAML 1.1 identity provider. * * @param array $metadata The metadata. + * @return void */ public function addMetadataIdP11($metadata) { @@ -651,6 +665,7 @@ class SAMLBuilder * * @param array $metadata The AttributeAuthorityDescriptor, in the format returned by * \SimpleSAML\Metadata\SAMLParser. + * @return void */ public function addAttributeAuthority(array $metadata) { @@ -688,6 +703,7 @@ class SAMLBuilder * @param string $type The type of contact. Deprecated. * @param array $details The details about the contact. * + * @return void * @todo Change the signature to remove $type. * @todo Remove the capability to pass a name and parse it inside the method. */ @@ -747,6 +763,7 @@ class SAMLBuilder * @param \SAML2\XML\md\RoleDescriptor $rd The RoleDescriptor the certificate should be added to. * @param string $use The value of the 'use' attribute. * @param string $x509data The certificate data. + * @return void */ private function addX509KeyDescriptor(\SAML2\XML\md\RoleDescriptor $rd, $use, $x509data) { @@ -766,6 +783,7 @@ class SAMLBuilder * * @param \SAML2\XML\md\RoleDescriptor $rd The RoleDescriptor the certificate should be added to. * @param \SimpleSAML\Configuration $metadata The metadata of the entity. + * @return void */ private function addCertificate(\SAML2\XML\md\RoleDescriptor $rd, \SimpleSAML\Configuration $metadata) { diff --git a/lib/SimpleSAML/Metadata/SAMLParser.php b/lib/SimpleSAML/Metadata/SAMLParser.php index 9619717585f1f828134a9d6dc32b63a19ea79e9c..4a9f713753dabbca4d4c1ae29f0afcdddbfbd880 100644 --- a/lib/SimpleSAML/Metadata/SAMLParser.php +++ b/lib/SimpleSAML/Metadata/SAMLParser.php @@ -211,6 +211,7 @@ class SAMLParser */ public static function parseFile($file) { + /** @var string $data */ $data = \SimpleSAML\Utils\HTTP::fetch($file); try { @@ -281,7 +282,7 @@ class SAMLParser * the file contains a single EntityDescriptorElement, then the array will contain a single SAMLParser * instance. * - * @param string $file The path to the file which contains the EntityDescriptor or EntitiesDescriptor element. + * @param string|null $file The path to the file which contains the EntityDescriptor or EntitiesDescriptor element. * * @return SAMLParser[] An array of SAMLParser instances. * @throws \Exception If the file does not parse as XML. @@ -292,6 +293,7 @@ class SAMLParser throw new \Exception('Cannot open file NULL. File name not specified.'); } + /** @var string $data */ $data = \SimpleSAML\Utils\HTTP::fetch($file); try { @@ -408,9 +410,9 @@ class SAMLParser * how long a given XML-element is valid. It returns this as a unix timestamp. * * @param mixed $element The element we should determine the expiry time of. - * @param int|NULL $maxExpireTime The maximum expiration time. + * @param int|null $maxExpireTime The maximum expiration time. * - * @return int The unix timestamp for when the element should expire. Will be NULL if no + * @return int|null The unix timestamp for when the element should expire. Will be NULL if no * limit is set for the element. */ private static function getExpireTime($element, $maxExpireTime) @@ -437,6 +439,9 @@ class SAMLParser } + /** + * @return array + */ private function getMetadataCommon() { $ret = []; @@ -469,6 +474,7 @@ class SAMLParser * * @param array &$metadata The metadata that should be updated. * @param array $roleDescriptor The parsed role descriptor. + * @return void */ private function addExtensions(array &$metadata, array $roleDescriptor) { @@ -519,7 +525,8 @@ class SAMLParser * * Metadata must be loaded with one of the parse functions before this function can be called. * - * @return array An associative array with metadata or NULL if we are unable to generate metadata for a SAML 1.x SP. + * @return array|null An associative array with metadata or NULL if we are unable to + * generate metadata for a SAML 1.x SP. */ public function getMetadata1xSP() { @@ -592,8 +599,8 @@ class SAMLParser * * Metadata must be loaded with one of the parse functions before this function can be called. * - * @return array An associative array with metadata or NULL if we are unable to generate metadata for a SAML 1.x - * IdP. + * @return array|null An associative array with metadata or NULL if we are unable to + * generate metadata for a SAML 1.x IdP. */ public function getMetadata1xIdP() { @@ -649,7 +656,8 @@ class SAMLParser * * Metadata must be loaded with one of the parse functions before this function can be called. * - * @return array An associative array with metadata or NULL if we are unable to generate metadata for a SAML 2.x SP. + * @return array|null An associative array with metadata or NULL if we are unable to + * generate metadata for a SAML 2.x SP. */ public function getMetadata20SP() { @@ -751,8 +759,8 @@ class SAMLParser * * Metadata must be loaded with one of the parse functions before this function can be called. * - * @return array An associative array with metadata or NULL if we are unable to generate metadata for a SAML 2.0 - * IdP. + * @return array|null An associative array with metadata or NULL if we are unable to + * generate metadata for a SAML 2.0 IdP. */ public function getMetadata20IdP() { @@ -827,7 +835,7 @@ class SAMLParser * - 'keys': Array of associative arrays with the elements from parseKeyDescriptor. * * @param \SAML2\XML\md\RoleDescriptor $element The element we should extract metadata from. - * @param int|NULL $expireTime The unix timestamp for when this element should expire, or + * @param int|null $expireTime The unix timestamp for when this element should expire, or * NULL if unknown. * * @return array An associative array with metadata we have extracted from this element. @@ -909,6 +917,7 @@ class SAMLParser * @param \SAML2\XML\md\SPSSODescriptor $element The element which should be parsed. * @param int|NULL $expireTime The unix timestamp for when this element should expire, or * NULL if unknown. + * @return void */ private function processSPSSODescriptor(\SAML2\XML\md\SPSSODescriptor $element, $expireTime) { @@ -945,6 +954,7 @@ class SAMLParser * @param \SAML2\XML\md\IDPSSODescriptor $element The element which should be parsed. * @param int|NULL $expireTime The unix timestamp for when this element should expire, or * NULL if unknown. + * @return void */ private function processIDPSSODescriptor(\SAML2\XML\md\IDPSSODescriptor $element, $expireTime) { @@ -971,6 +981,7 @@ class SAMLParser * @param \SAML2\XML\md\AttributeAuthorityDescriptor $element The element which should be parsed. * @param int|NULL $expireTime The unix timestamp for when this element should * expire, or NULL if unknown. + * @return void */ private function processAttributeAuthorityDescriptor( \SAML2\XML\md\AttributeAuthorityDescriptor $element, @@ -1144,6 +1155,7 @@ class SAMLParser * Parse and process a Organization element. * * @param \SAML2\XML\md\Organization $element The Organization element. + * @return void */ private function processOrganization(\SAML2\XML\md\Organization $element) { @@ -1157,8 +1169,8 @@ class SAMLParser * Parse and process a ContactPerson element. * * @param \SAML2\XML\md\ContactPerson $element The ContactPerson element. + * @return void */ - private function processContactPerson(\SAML2\XML\md\ContactPerson $element) { $contactPerson = []; @@ -1191,6 +1203,7 @@ class SAMLParser * * @param \SAML2\XML\md\AttributeConsumingService $element The AttributeConsumingService to parse. * @param array $sp The array with the SP's metadata. + * @return void */ private static function parseAttributeConsumerService(\SAML2\XML\md\AttributeConsumingService $element, &$sp) { @@ -1337,7 +1350,7 @@ class SAMLParser /** * This function finds SP descriptors which supports one of the given protocols. * - * @param $protocols Array with the protocols we accept. + * @param array $protocols Array with the protocols we accept. * * @return array with SP descriptors which supports one of the given protocols. */ @@ -1361,7 +1374,7 @@ class SAMLParser /** * This function finds IdP descriptors which supports one of the given protocols. * - * @param $protocols Array with the protocols we accept. + * @param array $protocols Array with the protocols we accept. * * @return array with IdP descriptors which supports one of the given protocols. */ diff --git a/lib/SimpleSAML/Metadata/Sources/MDQ.php b/lib/SimpleSAML/Metadata/Sources/MDQ.php index 413846427709d87e28bfeebec1b4148ba0b85fb9..db6a1135487a75c416d60145651d027e7189f805 100644 --- a/lib/SimpleSAML/Metadata/Sources/MDQ.php +++ b/lib/SimpleSAML/Metadata/Sources/MDQ.php @@ -193,6 +193,7 @@ class MDQ extends \SimpleSAML\Metadata\MetaDataStorageSource * @param array $data The associative array with the metadata for this entity. * * @throws \Exception If metadata cannot be written to cache. + * @return void */ private function writeToCache($set, $entityId, $data) { @@ -260,7 +261,7 @@ class MDQ extends \SimpleSAML\Metadata\MetaDataStorageSource * @param string $index The entityId or metaindex we are looking up. * @param string $set The set we are looking for metadata in. * - * @return array An associative array with metadata for the given entity, or NULL if we are unable to + * @return array|null An associative array with metadata for the given entity, or NULL if we are unable to * locate the entity. * @throws \Exception If an error occurs while validating the signature or the metadata is in an * incorrect set.