parseDescriptorsFile() публичный статический Метод

This function parses a file where the root node is either an EntityDescriptor element or an EntitiesDescriptor element. In both cases it will return an associative array of SAMLParser instances. If the file contains a single EntityDescriptorElement, then the array will contain a single SAMLParser instance.
public static parseDescriptorsFile ( string $file ) : SimpleSAML_Metadata_SAMLParser[]
$file string The path to the file which contains the EntityDescriptor or EntitiesDescriptor element.
Результат SimpleSAML_Metadata_SAMLParser[] An array of SAMLParser instances.
Пример #1
0
 /**
  * This function processes a SAML metadata file.
  *
  * @param $src  Filename of the metadata file.
  */
 public function loadSource($source)
 {
     $entities = array();
     try {
         $entities = SimpleSAML_Metadata_SAMLParser::parseDescriptorsFile($source['src']);
     } catch (Exception $e) {
         SimpleSAML_Logger::warning('metarefresh: Failed to retrieve metadata. ' . $e->getMessage());
     }
     foreach ($entities as $entity) {
         if (array_key_exists('validateFingerprint', $source) && $source['validateFingerprint'] !== NULL) {
             if (!$entity->validateFingerprint($source['validateFingerprint'])) {
                 SimpleSAML_Logger::info('Skipping "' . $entity->getEntityId() . '" - could not verify signature.' . "\n");
                 continue;
             }
         }
         $template = NULL;
         if (array_key_exists('template', $source)) {
             $template = $source['template'];
         }
         $this->addMetadata($source['src'], $entity->getMetadata1xSP(), 'shib13-sp-remote', $template);
         $this->addMetadata($source['src'], $entity->getMetadata1xIdP(), 'shib13-idp-remote', $template);
         $this->addMetadata($source['src'], $entity->getMetadata20SP(), 'saml20-sp-remote', $template);
         $this->addMetadata($source['src'], $entity->getMetadata20IdP(), 'saml20-idp-remote', $template);
         $attributeAuthorities = $entity->getAttributeAuthorities();
         if (!empty($attributeAuthorities)) {
             $this->addMetadata($source['src'], $attributeAuthorities[0], 'attributeauthority-remote', $template);
         }
     }
 }
Пример #2
0
 function __construct($url, $feedId, $enableCacheOnly = false)
 {
     $this->cachedir = Config::get('cachedir');
     if (!is_dir($this->cachedir)) {
         throw new Exception('Cache dir not present');
     }
     if (!is_writable($this->cachedir)) {
         throw new Exception('Cache dir not writable');
     }
     $cachefile = $this->cachedir . $feedId;
     // echo 'Cache dir: ' . $cachefile;
     // exit;
     try {
         if (!$enableCacheOnly) {
             DiscoUtils::debug('Downloading metadata from ' . tc_colored($url, 'green') . " and storing cache at " . tc_colored($cachefile, 'green'));
             $data = @file_get_contents($url);
             if ($data === false) {
                 throw new Exception('Error retrieving metadata from ' . $url);
             }
             file_put_contents($cachefile, $data);
         } else {
             DiscoUtils::debug('Looking up cached metadata from ' . tc_colored($cachefile, 'green'));
         }
     } catch (Exception $e) {
         error_log('Error updating metadata from source ' . $feedId . ' : ' . $e->getMessage());
     }
     if (!file_exists($cachefile)) {
         throw new Exception('Not able to continue processing this feed, because cannot read cached file');
     }
     DiscoUtils::debug('Metadata ready, starting to parse XML and validate document');
     $this->list = array();
     $entities = SimpleSAML_Metadata_SAMLParser::parseDescriptorsFile($cachefile);
     foreach ($entities as $entityId => $entity) {
         $md = $entity->getMetadata1xIdP();
         if ($md !== NULL) {
             $this->list[$entityId] = $md;
         }
         $md = $entity->getMetadata20IdP();
         if ($md !== NULL) {
             $this->list[$entityId] = $md;
         }
         $this->processSPEntity($entity->getMetadata20SP());
     }
     if (count($this->list) === 0) {
         throw new Exception('No entities found at URL ' . $src);
     }
 }
 /**
  * This function initializes the XML metadata source. The configuration must contain one of
  * the following options:
  * - 'file': Path to a file with the metadata. This path is relative to the simpleSAMLphp
  *           base directory.
  * - 'url': URL we should download the metadata from. This is only meant for testing.
  *
  * @param $config  The configuration for this instance of the XML metadata source.
  */
 protected function __construct($config)
 {
     /* Get the configuration. */
     $globalConfig = SimpleSAML_Configuration::getInstance();
     if (array_key_exists('file', $config)) {
         $src = $globalConfig->resolvePath($config['file']);
     } elseif (array_key_exists('url', $config)) {
         $src = $config['url'];
     } else {
         throw new Exception('Missing either \'file\' or \'url\' in XML metadata source configuration.');
     }
     $SP1x = array();
     $IdP1x = array();
     $SP20 = array();
     $IdP20 = array();
     $AAD = array();
     $entities = SimpleSAML_Metadata_SAMLParser::parseDescriptorsFile($src);
     foreach ($entities as $entityId => $entity) {
         $md = $entity->getMetadata1xSP();
         if ($md !== NULL) {
             $SP1x[$entityId] = $md;
         }
         $md = $entity->getMetadata1xIdP();
         if ($md !== NULL) {
             $IdP1x[$entityId] = $md;
         }
         $md = $entity->getMetadata20SP();
         if ($md !== NULL) {
             $SP20[$entityId] = $md;
         }
         $md = $entity->getMetadata20IdP();
         if ($md !== NULL) {
             $IdP20[$entityId] = $md;
         }
         $md = $entity->getAttributeAuthorities();
         if (count($md) > 0) {
             $AAD[$entityId] = $md[0];
         }
     }
     $this->metadata = array('shib13-sp-remote' => $SP1x, 'shib13-idp-remote' => $IdP1x, 'saml20-sp-remote' => $SP20, 'saml20-idp-remote' => $IdP20, 'attributeauthority-remote' => $AAD);
 }