getMetadataSet($set); if ($metadataSet === null) { // this metadata source does not have this metadata set return null; } foreach ($metadataSet as $index => $entry) { if (!array_key_exists('host', $entry)) { continue; } if ($hostPath === $entry['host']) { if ($type === 'entityid') { return $entry['entityid']; } else { return $index; } } } // no entries matched, we should return null return null; } /** * This function will go through all the metadata, and check the hint.cidr * parameter, which defines a network space (ip range) for each remote entry. * This function returns the entityID for any of the entities that have an * IP range which the IP falls within. * * @param string $set Which set of metadata we are looking it up in. * @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 * IP address match. */ public function getPreferredEntityIdFromCIDRhint($set, $ip, $type = 'entityid') { $metadataSet = $this->getMetadataSet($set); foreach ($metadataSet as $index => $entry) { if (!array_key_exists('hint.cidr', $entry)) { continue; } if (!is_array($entry['hint.cidr'])) { continue; } foreach ($entry['hint.cidr'] as $hint_entry) { if (SimpleSAML\Utils\Net::ipCIDRcheck($hint_entry, $ip)) { if ($type === 'entityid') { return $entry['entityid']; } else { return $index; } } } } // no entries matched, we should return null return null; } /* * */ private function lookupIndexFromEntityId($entityId, $set) { assert('is_string($entityId)'); assert('isset($set)'); $metadataSet = $this->getMetadataSet($set); // check for hostname $currenthost = \SimpleSAML\Utils\HTTP::getSelfHost(); // sp.example.org foreach ($metadataSet as $index => $entry) { if ($index === $entityId) { return $index; } if ($entry['entityid'] === $entityId) { if ($entry['host'] === '__DEFAULT__' || $entry['host'] === $currenthost) { return $index; } } } return null; } /** * This function retrieves metadata for the given entity id in the given set of metadata. * It will return NULL if it is unable to locate the metadata. * * This class implements this function using the getMetadataSet-function. A subclass should * override this function if it doesn't implement the getMetadataSet function, or if the * implementation of getMetadataSet is slow. * * @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 * locate the entity. */ public function getMetaData($index, $set) { assert('is_string($index)'); assert('isset($set)'); $metadataSet = $this->getMetadataSet($set); if (array_key_exists($index, $metadataSet)) { return $metadataSet[$index]; } $indexlookup = $this->lookupIndexFromEntityId($index, $set); if (isset($indexlookup) && array_key_exists($indexlookup, $metadataSet)) { return $metadataSet[$indexlookup]; } return null; } }