ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
MetaDataStorageHandlerFlatFile.php
Go to the documentation of this file.
1 <?php
2 
3 
13 {
14 
21  private $directory;
22 
23 
29  private $cachedMetadata = array();
30 
31 
41  protected function __construct($config)
42  {
43  assert('is_array($config)');
44 
45  // get the configuration
47 
48  // find the path to the directory we should search for metadata in
49  if (array_key_exists('directory', $config)) {
50  $this->directory = $config['directory'];
51  } else {
52  $this->directory = $globalConfig->getString('metadatadir', 'metadata/');
53  }
54 
55  /* Resolve this directory relative to the SimpleSAMLphp directory (unless it is
56  * an absolute path).
57  */
58  $this->directory = $globalConfig->resolvePath($this->directory).'/';
59  }
60 
61 
72  private function load($set)
73  {
74  $metadatasetfile = $this->directory.$set.'.php';
75 
76  if (!file_exists($metadatasetfile)) {
77  return null;
78  }
79 
80  $metadata = array();
81 
82  include($metadatasetfile);
83 
84  if (!is_array($metadata)) {
85  throw new Exception('Could not load metadata set ['.$set.'] from file: '.$metadatasetfile);
86  }
87 
88  return $metadata;
89  }
90 
91 
101  public function getMetadataSet($set)
102  {
103  if (array_key_exists($set, $this->cachedMetadata)) {
104  return $this->cachedMetadata[$set];
105  }
106 
107  $metadataSet = $this->load($set);
108  if ($metadataSet === null) {
109  $metadataSet = array();
110  }
111 
112  // add the entity id of an entry to each entry in the metadata
113  foreach ($metadataSet as $entityId => &$entry) {
114  if (preg_match('/__DYNAMIC(:[0-9]+)?__/', $entityId)) {
115  $entry['entityid'] = $this->generateDynamicHostedEntityID($set);
116  } else {
117  $entry['entityid'] = $entityId;
118  }
119  }
120 
121  $this->cachedMetadata[$set] = $metadataSet;
122 
123  return $metadataSet;
124  }
125 
126 
127  private function generateDynamicHostedEntityID($set)
128  {
129  // get the configuration
131 
132  if ($set === 'saml20-idp-hosted') {
133  return $baseurl.'saml2/idp/metadata.php';
134  } elseif ($set === 'shib13-idp-hosted') {
135  return $baseurl.'shib13/idp/metadata.php';
136  } elseif ($set === 'wsfed-sp-hosted') {
137  return 'urn:federation:'.\SimpleSAML\Utils\HTTP::getSelfHost();
138  } elseif ($set === 'adfs-idp-hosted') {
139  return 'urn:federation:'.\SimpleSAML\Utils\HTTP::getSelfHost().':idp';
140  } else {
141  throw new Exception('Can not generate dynamic EntityID for metadata of this type: ['.$set.']');
142  }
143  }
144 }
$baseurl
Definition: demo.php:25
__construct($config)
This constructor initializes the flatfile metadata storage handler with the specified configuration...
$metadata['__DYNAMIC:1__']
load($set)
This function loads the given set of metadata from a file our metadata directory. ...
getMetadataSet($set)
This function retrieves the given set of metadata.
Create styles array
The data for the language used.
if($source===null) if(!($source instanceof sspmod_saml_Auth_Source_SP)) $entityId
Definition: metadata.php:22
$globalConfig
static getBaseURL()
Retrieve the base URL of the SimpleSAMLphp installation.
Definition: HTTP.php:598
static getInstance($instancename='simplesaml')
Get a configuration file by its instance name.