ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
MetaDataStorageSource.php
Go to the documentation of this file.
1 <?php
2 
3 
16 {
17 
18 
31  public static function parseSources($sourcesConfig)
32  {
33  assert('is_array($sourcesConfig)');
34 
35  $sources = array();
36 
37  foreach ($sourcesConfig as $sourceConfig) {
38  if (!is_array($sourceConfig)) {
39  throw new Exception("Found an element in metadata source configuration which wasn't an array.");
40  }
41 
42  $sources[] = self::getSource($sourceConfig);
43  }
44 
45  return $sources;
46  }
47 
48 
60  public static function getSource($sourceConfig)
61  {
62  assert(is_array($sourceConfig));
63 
64  if (array_key_exists('type', $sourceConfig)) {
65  $type = $sourceConfig['type'];
66  } else {
67  $type = 'flatfile';
68  }
69 
70  switch ($type) {
71  case 'flatfile':
73  case 'xml':
74  return new SimpleSAML_Metadata_MetaDataStorageHandlerXML($sourceConfig);
75  case 'serialize':
77  case 'mdx':
78  case 'mdq':
79  return new \SimpleSAML\Metadata\Sources\MDQ($sourceConfig);
80  case 'pdo':
81  return new SimpleSAML_Metadata_MetaDataStorageHandlerPdo($sourceConfig);
82  default:
83  // metadata store from module
84  try {
86  $type,
87  'MetadataStore',
88  'SimpleSAML_Metadata_MetaDataStorageSource'
89  );
90  } catch (Exception $e) {
92  "Invalid 'type' for metadata source. Cannot find store '$type'.",
93  null
94  );
95  }
96  return new $className($sourceConfig);
97  }
98  }
99 
100 
112  public function getMetadataSet($set)
113  {
114  return array();
115  }
116 
117 
132  public function getEntityIdFromHostPath($hostPath, $set, $type = 'entityid')
133  {
134 
135  $metadataSet = $this->getMetadataSet($set);
136  if ($metadataSet === null) {
137  // this metadata source does not have this metadata set
138  return null;
139  }
140 
141  foreach ($metadataSet as $index => $entry) {
142 
143  if (!array_key_exists('host', $entry)) {
144  continue;
145  }
146 
147  if ($hostPath === $entry['host']) {
148  if ($type === 'entityid') {
149  return $entry['entityid'];
150  } else {
151  return $index;
152  }
153  }
154  }
155 
156  // no entries matched, we should return null
157  return null;
158  }
159 
160 
174  public function getPreferredEntityIdFromCIDRhint($set, $ip, $type = 'entityid')
175  {
176 
177  $metadataSet = $this->getMetadataSet($set);
178 
179  foreach ($metadataSet as $index => $entry) {
180 
181  if (!array_key_exists('hint.cidr', $entry)) {
182  continue;
183  }
184  if (!is_array($entry['hint.cidr'])) {
185  continue;
186  }
187 
188  foreach ($entry['hint.cidr'] as $hint_entry) {
189  if (SimpleSAML\Utils\Net::ipCIDRcheck($hint_entry, $ip)) {
190  if ($type === 'entityid') {
191  return $entry['entityid'];
192  } else {
193  return $index;
194  }
195  }
196  }
197  }
198 
199  // no entries matched, we should return null
200  return null;
201  }
202 
203 
204  /*
205  *
206  */
207  private function lookupIndexFromEntityId($entityId, $set)
208  {
209  assert('is_string($entityId)');
210  assert('isset($set)');
211 
212  $metadataSet = $this->getMetadataSet($set);
213 
214  // check for hostname
215  $currenthost = \SimpleSAML\Utils\HTTP::getSelfHost(); // sp.example.org
216 
217  foreach ($metadataSet as $index => $entry) {
218  if ($index === $entityId) {
219  return $index;
220  }
221  if ($entry['entityid'] === $entityId) {
222  if ($entry['host'] === '__DEFAULT__' || $entry['host'] === $currenthost) {
223  return $index;
224  }
225  }
226  }
227 
228  return null;
229  }
230 
231 
246  public function getMetaData($index, $set)
247  {
248 
249  assert('is_string($index)');
250  assert('isset($set)');
251 
252  $metadataSet = $this->getMetadataSet($set);
253 
254  if (array_key_exists($index, $metadataSet)) {
255  return $metadataSet[$index];
256  }
257 
258  $indexlookup = $this->lookupIndexFromEntityId($index, $set);
259  if (isset($indexlookup) && array_key_exists($indexlookup, $metadataSet)) {
260  return $metadataSet[$indexlookup];
261  }
262 
263  return null;
264  }
265 
266 }
$type
getEntityIdFromHostPath($hostPath, $set, $type='entityid')
This function resolves an host/path combination to an entity id.
$index
Definition: metadata.php:60
Attribute-related utility methods.
getMetadataSet($set)
This function attempts to generate an associative array with metadata for all entities in the given s...
getPreferredEntityIdFromCIDRhint($set, $ip, $type='entityid')
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.
getMetaData($index, $set)
This function retrieves metadata for the given entity id in the given set of metadata.
static getSelfHost()
Retrieve our own host.
Definition: HTTP.php:699
static getSource($sourceConfig)
This function creates a metadata source based on the given configuration.
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
static resolveClass($id, $type, $subclass=null)
Resolve module class.
Definition: Module.php:252
static parseSources($sourcesConfig)
Parse array with metadata sources.