ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
SimpleSAML_Metadata_MetaDataStorageHandlerSerialize Class Reference
+ Inheritance diagram for SimpleSAML_Metadata_MetaDataStorageHandlerSerialize:
+ Collaboration diagram for SimpleSAML_Metadata_MetaDataStorageHandlerSerialize:

Public Member Functions

 __construct ($config)
 Constructor for this metadata handler. More...
 
 getMetadataSets ()
 Retrieve a list of all available metadata sets. More...
 
 getMetadataSet ($set)
 Retrieve a list of all available metadata for a given set. More...
 
 getMetaData ($entityId, $set)
 Retrieve a metadata entry. More...
 
 saveMetadata ($entityId, $set, $metadata)
 Save a metadata entry. More...
 
 deleteMetadata ($entityId, $set)
 Delete a metadata entry. More...
 

Data Fields

const EXTENSION = '.serialized'
 

Private Member Functions

 getMetadataPath ($entityId, $set)
 Helper function for retrieving the path of a metadata file. More...
 

Private Attributes

 $directory
 

Additional Inherited Members

Detailed Description

Definition at line 9 of file MetaDataStorageHandlerSerialize.php.

Constructor & Destructor Documentation

◆ __construct()

SimpleSAML_Metadata_MetaDataStorageHandlerSerialize::__construct (   $config)

Constructor for this metadata handler.

Parses configuration.

Parameters
array$configThe configuration for this metadata handler.

Definition at line 35 of file MetaDataStorageHandlerSerialize.php.

References $config, $globalConfig, SimpleSAML_Configuration\getInstance(), and SimpleSAML_Configuration\loadFromArray().

36  {
37  assert('is_array($config)');
38 
40 
41  $cfgHelp = SimpleSAML_Configuration::loadFromArray($config, 'serialize metadata source');
42 
43  $this->directory = $cfgHelp->getString('directory');
44 
45  /* Resolve this directory relative to the SimpleSAMLphp directory (unless it is
46  * an absolute path).
47  */
48  $this->directory = $globalConfig->resolvePath($this->directory);
49  }
$globalConfig
static loadFromArray($config, $location='[ARRAY]', $instance=null)
Loads a configuration from the given array.
static getInstance($instancename='simplesaml')
Get a configuration file by its instance name.
+ Here is the call graph for this function:

Member Function Documentation

◆ deleteMetadata()

SimpleSAML_Metadata_MetaDataStorageHandlerSerialize::deleteMetadata (   $entityId,
  $set 
)

Delete a metadata entry.

Parameters
string$entityIdThe entityId of the metadata entry.
string$setThe metadata set this metadata entry belongs to.

Definition at line 263 of file MetaDataStorageHandlerSerialize.php.

References $entityId, $error, $res, SimpleSAML\Logger\error(), getMetadataPath(), and SimpleSAML\Logger\warning().

264  {
265  assert('is_string($entityId)');
266  assert('is_string($set)');
267 
268  $filePath = $this->getMetadataPath($entityId, $set);
269 
270  if (!file_exists($filePath)) {
272  'Attempted to erase nonexistent metadata entry '.
273  var_export($entityId, true).' in set '.var_export($set, true).'.'
274  );
275  return;
276  }
277 
278  $res = unlink($filePath);
279  if ($res === false) {
280  $error = error_get_last();
282  'Failed to delete file '.$filePath.
283  ': '.$error['message']
284  );
285  }
286  }
getMetadataPath($entityId, $set)
Helper function for retrieving the path of a metadata file.
$error
Definition: Error.php:17
foreach($_POST as $key=> $value) $res
static warning($string)
Definition: Logger.php:179
static error($string)
Definition: Logger.php:168
if($source===null) if(!($source instanceof sspmod_saml_Auth_Source_SP)) $entityId
Definition: metadata.php:22
+ Here is the call graph for this function:

◆ getMetaData()

SimpleSAML_Metadata_MetaDataStorageHandlerSerialize::getMetaData (   $entityId,
  $set 
)

Retrieve a metadata entry.

Parameters
string$entityIdThe entityId we are looking up.
string$setThe set we are looking for metadata in.
Returns
array An associative array with metadata for the given entity, or NULL if we are unable to locate the entity.

Definition at line 172 of file MetaDataStorageHandlerSerialize.php.

References $data, $entityId, $error, getMetadataPath(), and SimpleSAML\Logger\warning().

Referenced by getMetadataSet().

173  {
174  assert('is_string($entityId)');
175  assert('is_string($set)');
176 
177  $filePath = $this->getMetadataPath($entityId, $set);
178 
179  if (!file_exists($filePath)) {
180  return null;
181  }
182 
183  $data = @file_get_contents($filePath);
184  if ($data === false) {
185  $error = error_get_last();
187  'Error reading file '.$filePath.': '.$error['message']
188  );
189  return null;
190  }
191 
192  $data = @unserialize($data);
193  if ($data === false) {
194  SimpleSAML\Logger::warning('Error unserializing file: '.$filePath);
195  return null;
196  }
197 
198  if (!array_key_exists('entityid', $data)) {
199  $data['entityid'] = $entityId;
200  }
201 
202  return $data;
203  }
getMetadataPath($entityId, $set)
Helper function for retrieving the path of a metadata file.
$error
Definition: Error.php:17
static warning($string)
Definition: Logger.php:179
if($source===null) if(!($source instanceof sspmod_saml_Auth_Source_SP)) $entityId
Definition: metadata.php:22
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getMetadataPath()

SimpleSAML_Metadata_MetaDataStorageHandlerSerialize::getMetadataPath (   $entityId,
  $set 
)
private

Helper function for retrieving the path of a metadata file.

Parameters
string$entityIdThe entity ID.
string$setThe metadata set.
Returns
string The path to the metadata file.

Definition at line 60 of file MetaDataStorageHandlerSerialize.php.

References $entityId.

Referenced by deleteMetadata(), getMetaData(), and saveMetadata().

61  {
62  assert('is_string($entityId)');
63  assert('is_string($set)');
64 
65  return $this->directory.'/'.rawurlencode($set).'/'.rawurlencode($entityId).self::EXTENSION;
66  }
if($source===null) if(!($source instanceof sspmod_saml_Auth_Source_SP)) $entityId
Definition: metadata.php:22
+ Here is the caller graph for this function:

◆ getMetadataSet()

SimpleSAML_Metadata_MetaDataStorageHandlerSerialize::getMetadataSet (   $set)

Retrieve a list of all available metadata for a given set.

Parameters
string$setThe set we are looking for metadata in.
Returns
array An associative array with all the metadata for the given set.

Definition at line 119 of file MetaDataStorageHandlerSerialize.php.

References $entityId, $file, $ret, array, getMetaData(), and SimpleSAML\Logger\warning().

120  {
121  assert('is_string($set)');
122 
123  $ret = array();
124 
125  $dir = $this->directory.'/'.rawurlencode($set);
126  if (!is_dir($dir)) {
127  // probably some code asked for a metadata set which wasn't available
128  return $ret;
129  }
130 
131  $dh = @opendir($dir);
132  if ($dh === false) {
133  SimpleSAML\Logger::warning('Serialize metadata handler: Unable to open directory: '.var_export($dir, true));
134  return $ret;
135  }
136 
137  $extLen = strlen(self::EXTENSION);
138 
139  while (($file = readdir($dh)) !== false) {
140  if (strlen($file) <= $extLen) {
141  continue;
142  }
143 
144  if (substr($file, -$extLen) !== self::EXTENSION) {
145  continue;
146  }
147 
148  $entityId = substr($file, 0, -$extLen);
149  $entityId = rawurldecode($entityId);
150 
151  $md = $this->getMetaData($entityId, $set);
152  if ($md !== null) {
153  $ret[$entityId] = $md;
154  }
155  }
156 
157  closedir($dh);
158 
159  return $ret;
160  }
static warning($string)
Definition: Logger.php:179
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
$ret
Definition: parser.php:6
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file
+ Here is the call graph for this function:

◆ getMetadataSets()

SimpleSAML_Metadata_MetaDataStorageHandlerSerialize::getMetadataSets ( )

Retrieve a list of all available metadata sets.

Returns
array An array with the available sets.

Definition at line 74 of file MetaDataStorageHandlerSerialize.php.

References $path, $ret, array, and SimpleSAML\Logger\warning().

75  {
76  $ret = array();
77 
78  $dh = @opendir($this->directory);
79  if ($dh === false) {
81  'Serialize metadata handler: Unable to open directory: '.var_export($this->directory, true)
82  );
83  return $ret;
84  }
85 
86  while (($entry = readdir($dh)) !== false) {
87 
88  if ($entry[0] === '.') {
89  // skip '..', '.' and hidden files
90  continue;
91  }
92 
93  $path = $this->directory.'/'.$entry;
94 
95  if (!is_dir($path)) {
97  'Serialize metadata handler: Metadata directory contained a file where only directories should '.
98  'exist: '.var_export($path, true)
99  );
100  continue;
101  }
102 
103  $ret[] = rawurldecode($entry);
104  }
105 
106  closedir($dh);
107 
108  return $ret;
109  }
static warning($string)
Definition: Logger.php:179
Create styles array
The data for the language used.
$ret
Definition: parser.php:6
+ Here is the call graph for this function:

◆ saveMetadata()

SimpleSAML_Metadata_MetaDataStorageHandlerSerialize::saveMetadata (   $entityId,
  $set,
  $metadata 
)

Save a metadata entry.

Parameters
string$entityIdThe entityId of the metadata entry.
string$setThe metadata set this metadata entry belongs to.
array$metadataThe metadata.
Returns
boolean True if successfully saved, false otherwise.

Definition at line 215 of file MetaDataStorageHandlerSerialize.php.

References $data, $entityId, $error, $metadata, $res, SimpleSAML\Logger\debug(), SimpleSAML\Logger\error(), getMetadataPath(), and SimpleSAML\Logger\info().

216  {
217  assert('is_string($entityId)');
218  assert('is_string($set)');
219  assert('is_array($metadata)');
220 
221  $filePath = $this->getMetadataPath($entityId, $set);
222  $newPath = $filePath.'.new';
223 
224  $dir = dirname($filePath);
225  if (!is_dir($dir)) {
226  SimpleSAML\Logger::info('Creating directory: '.$dir);
227  $res = @mkdir($dir, 0777, true);
228  if ($res === false) {
229  $error = error_get_last();
230  SimpleSAML\Logger::error('Failed to create directory '.$dir.': '.$error['message']);
231  return false;
232  }
233  }
234 
235  $data = serialize($metadata);
236 
237  SimpleSAML\Logger::debug('Writing: '.$newPath);
238 
239  $res = file_put_contents($newPath, $data);
240  if ($res === false) {
241  $error = error_get_last();
242  SimpleSAML\Logger::error('Error saving file '.$newPath.': '.$error['message']);
243  return false;
244  }
245 
246  $res = rename($newPath, $filePath);
247  if ($res === false) {
248  $error = error_get_last();
249  SimpleSAML\Logger::error('Error renaming '.$newPath.' to '.$filePath.': '.$error['message']);
250  return false;
251  }
252 
253  return true;
254  }
static debug($string)
Definition: Logger.php:213
getMetadataPath($entityId, $set)
Helper function for retrieving the path of a metadata file.
$metadata['__DYNAMIC:1__']
$error
Definition: Error.php:17
static info($string)
Definition: Logger.php:201
foreach($_POST as $key=> $value) $res
static error($string)
Definition: Logger.php:168
if($source===null) if(!($source instanceof sspmod_saml_Auth_Source_SP)) $entityId
Definition: metadata.php:22
+ Here is the call graph for this function:

Field Documentation

◆ $directory

SimpleSAML_Metadata_MetaDataStorageHandlerSerialize::$directory
private

Definition at line 25 of file MetaDataStorageHandlerSerialize.php.

◆ EXTENSION

const SimpleSAML_Metadata_MetaDataStorageHandlerSerialize::EXTENSION = '.serialized'

Definition at line 17 of file MetaDataStorageHandlerSerialize.php.


The documentation for this class was generated from the following file: