ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
SimpleSAML\Metadata\Sources\MDQ Class Reference
+ Inheritance diagram for SimpleSAML\Metadata\Sources\MDQ:
+ Collaboration diagram for SimpleSAML\Metadata\Sources\MDQ:

Public Member Functions

 getMetadataSet ($set)
 This function is not implemented. More...
 

Protected Member Functions

 __construct ($config)
 This function initializes the dynamic XML metadata source. More...
 

Private Member Functions

 getCacheFilename ($set, $entityId)
 Find the cache file name for an entity,. More...
 
 getFromCache ($set, $entityId)
 Load a entity from the cache. More...
 
 writeToCache ($set, $entityId, $data)
 Save a entity to the cache. More...
 

Static Private Member Functions

static getParsedSet (\SimpleSAML_Metadata_SAMLParser $entity, $set)
 Retrieve metadata for the correct set from a SAML2Parser. More...
 

Private Attributes

 $server
 
 $validateFingerprint
 
 $cacheDir
 
 $cacheLength
 

Additional Inherited Members

Detailed Description

Definition at line 16 of file MDQ.php.

Constructor & Destructor Documentation

◆ __construct()

SimpleSAML\Metadata\Sources\MDQ::__construct (   $config)
protected

This function initializes the dynamic XML metadata source.

Options:

  • 'server': URL of the MDQ server (url:port). Mandatory.
  • 'validateFingerprint': The fingerprint of the certificate used to sign the metadata. You don't need this option if you don't want to validate the signature on the metadata. Optional.
  • 'cachedir': Directory where metadata can be cached. Optional.
  • 'cachelength': Maximum time metadata cah be cached, in seconds. Default to 24 hours (86400 seconds).
Parameters
array$configThe configuration for this instance of the XML metadata source.
Exceptions

Exception If no server option can be found in the configuration.

Definition at line 66 of file MDQ.php.

67 {
68 assert(is_array($config));
69
70 if (!array_key_exists('server', $config)) {
71 throw new \Exception(__CLASS__.": the 'server' configuration option is not set.");
72 } else {
73 $this->server = $config['server'];
74 }
75
76 if (array_key_exists('validateFingerprint', $config)) {
77 $this->validateFingerprint = $config['validateFingerprint'];
78 } else {
79 $this->validateFingerprint = null;
80 }
81
82 if (array_key_exists('cachedir', $config)) {
84 $this->cacheDir = $globalConfig->resolvePath($config['cachedir']);
85 } else {
86 $this->cacheDir = null;
87 }
88
89 if (array_key_exists('cachelength', $config)) {
90 $this->cacheLength = $config['cachelength'];
91 } else {
92 $this->cacheLength = 86400;
93 }
94 }
static getInstance($instancename='simplesaml')
Get a configuration file by its instance name.
$config
Definition: bootstrap.php:15
$globalConfig

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

+ Here is the call graph for this function:

Member Function Documentation

◆ getCacheFilename()

SimpleSAML\Metadata\Sources\MDQ::getCacheFilename (   $set,
  $entityId 
)
private

Find the cache file name for an entity,.

Parameters
string$setThe metadata set this entity belongs to.
string$entityIdThe entity id of this entity.
Returns
string The full path to the cache file.

Definition at line 119 of file MDQ.php.

120 {
121 assert(is_string($set));
122 assert(is_string($entityId));
123
124 $cachekey = sha1($entityId);
125 return $this->cacheDir.'/'.$set.'-'.$cachekey.'.cached.xml';
126 }
if( $source===null) if(!($source instanceof sspmod_saml_Auth_Source_SP)) $entityId
Definition: metadata.php:22

References $entityId.

Referenced by SimpleSAML\Metadata\Sources\MDQ\getFromCache(), and SimpleSAML\Metadata\Sources\MDQ\writeToCache().

+ Here is the caller graph for this function:

◆ getFromCache()

SimpleSAML\Metadata\Sources\MDQ::getFromCache (   $set,
  $entityId 
)
private

Load a entity from the cache.

Parameters
string$setThe metadata set this entity belongs to.
string$entityIdThe entity id of this entity.
Returns
array|NULL The associative array with the metadata for this entity, or NULL if the entity could not be found.
Exceptions

Exception If an error occurs while loading metadata from cache.

Definition at line 139 of file MDQ.php.

140 {
141 assert(is_string($set));
142 assert(is_string($entityId));
143
144 if (empty($this->cacheDir)) {
145 return null;
146 }
147
148 $cachefilename = $this->getCacheFilename($set, $entityId);
149 if (!file_exists($cachefilename)) {
150 return null;
151 }
152 if (!is_readable($cachefilename)) {
153 throw new \Exception(__CLASS__.': could not read cache file for entity ['.$cachefilename.']');
154 }
155 Logger::debug(__CLASS__.': reading cache ['.$entityId.'] => ['.$cachefilename.']');
156
157 /* Ensure that this metadata isn't older that the cachelength option allows. This
158 * must be verified based on the file, since this option may be changed after the
159 * file is written.
160 */
161 $stat = stat($cachefilename);
162 if ($stat['mtime'] + $this->cacheLength <= time()) {
163 Logger::debug(__CLASS__.': cache file older that the cachelength option allows.');
164 return null;
165 }
166
167 $rawData = file_get_contents($cachefilename);
168 if (empty($rawData)) {
169 $error = error_get_last();
170 throw new \Exception(
171 __CLASS__.': error reading metadata from cache file "'.$cachefilename.'": '.$error['message']
172 );
173 }
174
175 $data = unserialize($rawData);
176 if ($data === false) {
177 throw new \Exception(__CLASS__.': error unserializing cached data from file "'.$cachefilename.'".');
178 }
179
180 if (!is_array($data)) {
181 throw new \Exception(__CLASS__.': Cached metadata from "'.$cachefilename.'" wasn\'t an array.');
182 }
183
184 return $data;
185 }
static debug($string)
Definition: Logger.php:211
getCacheFilename($set, $entityId)
Find the cache file name for an entity,.
Definition: MDQ.php:119
$data
Definition: bench.php:6

References $data, $entityId, SimpleSAML\Logger\debug(), and SimpleSAML\Metadata\Sources\MDQ\getCacheFilename().

+ Here is the call graph for this function:

◆ getMetadataSet()

SimpleSAML\Metadata\Sources\MDQ::getMetadataSet (   $set)

This function is not implemented.

Parameters
string$setThe set we want to list metadata for.
Returns
array An empty array.

Reimplemented from SimpleSAML_Metadata_MetaDataStorageSource.

Definition at line 104 of file MDQ.php.

105 {
106 // we don't have this metadata set
107 return array();
108 }

◆ getParsedSet()

static SimpleSAML\Metadata\Sources\MDQ::getParsedSet ( \SimpleSAML_Metadata_SAMLParser  $entity,
  $set 
)
staticprivate

Retrieve metadata for the correct set from a SAML2Parser.

Parameters
\SimpleSAML_Metadata_SAMLParser$entityA SAML2Parser representing an entity.
string$setThe metadata set we are looking for.
Returns
array|NULL The associative array with the metadata, or NULL if no metadata for the given set was found.

Definition at line 225 of file MDQ.php.

226 {
227 assert(is_string($set));
228
229 switch ($set) {
230 case 'saml20-idp-remote':
231 return $entity->getMetadata20IdP();
232 case 'saml20-sp-remote':
233 return $entity->getMetadata20SP();
234 case 'shib13-idp-remote':
235 return $entity->getMetadata1xIdP();
236 case 'shib13-sp-remote':
237 return $entity->getMetadata1xSP();
238 case 'attributeauthority-remote':
239 $ret = $entity->getAttributeAuthorities();
240 return $ret[0];
241
242 default:
243 Logger::warning(__CLASS__.': unknown metadata set: \''.$set.'\'.');
244 }
245
246 return null;
247 }
static warning($string)
Definition: Logger.php:177
$ret
Definition: parser.php:6

References $ret, error(), SimpleSAML_Metadata_SAMLParser\getAttributeAuthorities(), SimpleSAML_Metadata_SAMLParser\getMetadata1xIdP(), SimpleSAML_Metadata_SAMLParser\getMetadata1xSP(), SimpleSAML_Metadata_SAMLParser\getMetadata20IdP(), SimpleSAML_Metadata_SAMLParser\getMetadata20SP(), and SimpleSAML\Logger\warning().

+ Here is the call graph for this function:

◆ writeToCache()

SimpleSAML\Metadata\Sources\MDQ::writeToCache (   $set,
  $entityId,
  $data 
)
private

Save a entity to the cache.

Parameters
string$setThe metadata set this entity belongs to.
string$entityIdThe entity id of this entity.
array$dataThe associative array with the metadata for this entity.
Exceptions

Exception If metadata cannot be written to cache.

Definition at line 197 of file MDQ.php.

198 {
199 assert(is_string($set));
200 assert(is_string($entityId));
201 assert(is_array($data));
202
203 if (empty($this->cacheDir)) {
204 return;
205 }
206
207 $cachefilename = $this->getCacheFilename($set, $entityId);
208 if (!is_writable(dirname($cachefilename))) {
209 throw new \Exception(__CLASS__.': could not write cache file for entity ['.$cachefilename.']');
210 }
211 Logger::debug(__CLASS__.': Writing cache ['.$entityId.'] => ['.$cachefilename.']');
212 file_put_contents($cachefilename, serialize($data));
213 }

References $data, $entityId, SimpleSAML\Logger\debug(), and SimpleSAML\Metadata\Sources\MDQ\getCacheFilename().

+ Here is the call graph for this function:

Field Documentation

◆ $cacheDir

SimpleSAML\Metadata\Sources\MDQ::$cacheDir
private

Definition at line 39 of file MDQ.php.

◆ $cacheLength

SimpleSAML\Metadata\Sources\MDQ::$cacheLength
private

Definition at line 47 of file MDQ.php.

◆ $server

SimpleSAML\Metadata\Sources\MDQ::$server
private

Definition at line 24 of file MDQ.php.

◆ $validateFingerprint

SimpleSAML\Metadata\Sources\MDQ::$validateFingerprint
private

Definition at line 32 of file MDQ.php.


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