68 assert(
'is_array($config)');
70 if (!array_key_exists(
'server',
$config)) {
71 throw new \Exception(__CLASS__.
": the 'server' configuration option is not set.");
73 $this->server =
$config[
'server'];
76 if (array_key_exists(
'validateFingerprint',
$config)) {
77 $this->validateFingerprint =
$config[
'validateFingerprint'];
79 $this->validateFingerprint = null;
82 if (array_key_exists(
'cachedir',
$config)) {
86 $this->cacheDir = null;
89 if (array_key_exists(
'cachelength',
$config)) {
90 $this->cacheLength =
$config[
'cachelength'];
92 $this->cacheLength = 86400;
121 assert(
'is_string($set)');
122 assert(
'is_string($entityId)');
125 return $this->cacheDir.
'/'.$set.
'-'.$cachekey.
'.cached.xml';
141 assert(
'is_string($set)');
142 assert(
'is_string($entityId)');
144 if (empty($this->cacheDir)) {
149 if (!file_exists($cachefilename)) {
152 if (!is_readable($cachefilename)) {
153 throw new \Exception(__CLASS__.
': could not read cache file for entity ['.$cachefilename.
']');
161 $stat = stat($cachefilename);
162 if ($stat[
'mtime'] + $this->cacheLength <=
time()) {
163 Logger::debug(__CLASS__.
': cache file older that the cachelength option allows.');
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']
175 $data = unserialize($rawData);
176 if (
$data ===
false) {
177 throw new \Exception(__CLASS__.
': error unserializing cached data from file "'.$cachefilename.
'".');
180 if (!is_array(
$data)) {
181 throw new \Exception(__CLASS__.
': Cached metadata from "'.$cachefilename.
'" wasn\'t an array.');
199 assert(
'is_string($set)');
200 assert(
'is_string($entityId)');
201 assert(
'is_array($data)');
203 if (empty($this->cacheDir)) {
208 if (!is_writable(dirname($cachefilename))) {
209 throw new \Exception(__CLASS__.
': could not write cache file for entity ['.$cachefilename.
']');
212 file_put_contents($cachefilename, serialize(
$data));
227 assert(
'is_string($set)');
230 case 'saml20-idp-remote':
232 case 'saml20-sp-remote':
234 case 'shib13-idp-remote':
236 case 'shib13-sp-remote':
238 case 'attributeauthority-remote':
267 public function getMetaData($index, $set) 269 assert('is_string(
$index)
'); 270 assert('is_string($set)
'); 272 Logger::info(__CLASS__.': loading metadata entity [
'.$index.'] from [
'.$set.']
'); 274 // read from cache if possible 275 $data = $this->getFromCache($set, $index); 277 if ($data !== null && array_key_exists('expires
', $data) && $data['expires
'] < time()) { 278 // metadata has expired 283 // metadata found in cache and not expired 284 Logger::debug(__CLASS__.':
using cached metadata
for:
'.$index.'.
'); 288 // look at Metadata Query Protocol: https://github.com/iay/md-query/blob/master/draft-young-md-query.txt 289 $mdq_url = $this->server.'/entities/
'.urlencode($index); 291 Logger::debug(__CLASS__.': downloading metadata
for "'.$index.'" from [
'.$mdq_url.']
'); 293 $xmldata = HTTP::fetch($mdq_url); 294 } catch (\Exception $e) { 295 Logger::warning('Fetching metadata
for '.$index.':
'.$e->getMessage()); 298 if (empty($xmldata)) { 299 $error = error_get_last(); 300 throw new \Exception( 301 'Error downloading metadata
for "'.$index.'" from
"'.$mdq_url.'":
'.$error['message
'] 306 $entity = \SimpleSAML_Metadata_SAMLParser::parseString($xmldata); 307 Logger::debug(__CLASS__.': completed parsing of [
'.$mdq_url.']
'); 309 if ($this->validateFingerprint !== null) { 310 if (!$entity->validateFingerprint($this->validateFingerprint)) { 311 throw new \Exception(__CLASS__.': error, could not verify signature
for entity:
'.$index.'".'); 315 $data = self::getParsedSet($entity, $set); 316 if ($data === null) { 317 throw new \Exception(__CLASS__.': no metadata for set "'.$set.'" available from "'.$index.'".'); 320 $this->writeToCache($set, $index, $data);
Create styles array
The data for the language used.
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
static getInstance($instancename='simplesaml')
Get a configuration file by its instance name.