ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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.

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 }
static getInstance($instancename='simplesaml')
Get a configuration file by its instance name.
static loadFromArray($config, $location='[ARRAY]', $instance=null)
Loads a configuration from the given array.
$config
Definition: bootstrap.php:15
$globalConfig

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

+ 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 262 of file MetaDataStorageHandlerSerialize.php.

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

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

+ 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.

Reimplemented from SimpleSAML_Metadata_MetaDataStorageSource.

Definition at line 171 of file MetaDataStorageHandlerSerialize.php.

172 {
173 assert(is_string($entityId));
174 assert(is_string($set));
175
176 $filePath = $this->getMetadataPath($entityId, $set);
177
178 if (!file_exists($filePath)) {
179 return null;
180 }
181
182 $data = @file_get_contents($filePath);
183 if ($data === false) {
184 $error = error_get_last();
186 'Error reading file '.$filePath.': '.$error['message']
187 );
188 return null;
189 }
190
191 $data = @unserialize($data);
192 if ($data === false) {
193 SimpleSAML\Logger::warning('Error unserializing file: '.$filePath);
194 return null;
195 }
196
197 if (!array_key_exists('entityid', $data)) {
198 $data['entityid'] = $entityId;
199 }
200
201 return $data;
202 }
$data
Definition: bench.php:6

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

Referenced by getMetadataSet().

+ 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.

61 {
62 assert(is_string($entityId));
63 assert(is_string($set));
64
65 return $this->directory.'/'.rawurlencode($set).'/'.rawurlencode($entityId).self::EXTENSION;
66 }

References $entityId.

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

+ 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.

Reimplemented from SimpleSAML_Metadata_MetaDataStorageSource.

Definition at line 118 of file MetaDataStorageHandlerSerialize.php.

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

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

+ 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.

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 if ($entry[0] === '.') {
88 // skip '..', '.' and hidden files
89 continue;
90 }
91
92 $path = $this->directory.'/'.$entry;
93
94 if (!is_dir($path)) {
96 'Serialize metadata handler: Metadata directory contained a file where only directories should '.
97 'exist: '.var_export($path, true)
98 );
99 continue;
100 }
101
102 $ret[] = rawurldecode($entry);
103 }
104
105 closedir($dh);
106
107 return $ret;
108 }
$path
Definition: aliased.php:25

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

+ 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 214 of file MetaDataStorageHandlerSerialize.php.

215 {
216 assert(is_string($entityId));
217 assert(is_string($set));
218 assert(is_array($metadata));
219
220 $filePath = $this->getMetadataPath($entityId, $set);
221 $newPath = $filePath.'.new';
222
223 $dir = dirname($filePath);
224 if (!is_dir($dir)) {
225 SimpleSAML\Logger::info('Creating directory: '.$dir);
226 $res = @mkdir($dir, 0777, true);
227 if ($res === false) {
228 $error = error_get_last();
229 SimpleSAML\Logger::error('Failed to create directory '.$dir.': '.$error['message']);
230 return false;
231 }
232 }
233
234 $data = serialize($metadata);
235
236 SimpleSAML\Logger::debug('Writing: '.$newPath);
237
238 $res = file_put_contents($newPath, $data);
239 if ($res === false) {
240 $error = error_get_last();
241 SimpleSAML\Logger::error('Error saving file '.$newPath.': '.$error['message']);
242 return false;
243 }
244
245 $res = rename($newPath, $filePath);
246 if ($res === false) {
247 $error = error_get_last();
248 SimpleSAML\Logger::error('Error renaming '.$newPath.' to '.$filePath.': '.$error['message']);
249 return false;
250 }
251
252 return true;
253 }
$metadata['__DYNAMIC:1__']
static info($string)
Definition: Logger.php:199
static debug($string)
Definition: Logger.php:211

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

+ 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: