From 85fa459101173475ffbf5e0b67cccbaa1773d78c Mon Sep 17 00:00:00 2001 From: Olav Morken <olav.morken@uninett.no> Date: Thu, 16 Feb 2012 07:30:11 +0000 Subject: [PATCH] Ignore cacheDuration when evaluating validity of metadata. Thanks to Thijs Kinkhorst for providing this patch. git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@3034 44740490-163a-0410-bde0-09ae8108e29a --- docs/simplesamlphp-automated_metadata.txt | 4 ++++ lib/SimpleSAML/Metadata/SAMLParser.php | 22 +++++----------------- modules/aggregator2/lib/EntitySource.php | 13 ------------- 3 files changed, 9 insertions(+), 30 deletions(-) diff --git a/docs/simplesamlphp-automated_metadata.txt b/docs/simplesamlphp-automated_metadata.txt index 8cfd4d763..c2d01b555 100644 --- a/docs/simplesamlphp-automated_metadata.txt +++ b/docs/simplesamlphp-automated_metadata.txt @@ -224,4 +224,8 @@ In config.php: ), +Metadata cacheDuration +---------------------- + +SAML metadata may supply a cacheDuration attribute which indicates the maxium time to cache metadata. Because this module is run from cron, it cannot influence how often it is run and enfore this attribute by itself. Take care that you run metarefresh from cron at least as often as the shortest cacheDuration in your metadata sources. diff --git a/lib/SimpleSAML/Metadata/SAMLParser.php b/lib/SimpleSAML/Metadata/SAMLParser.php index 62d37f32f..f5e089d55 100644 --- a/lib/SimpleSAML/Metadata/SAMLParser.php +++ b/lib/SimpleSAML/Metadata/SAMLParser.php @@ -342,11 +342,8 @@ class SimpleSAML_Metadata_SAMLParser { /** * Determine how long a given element can be cached. * - * This function looks for the 'cacheDuration' and 'validUntil' attributes to determine - * how long a given XML-element is valid. It returns this as na unix timestamp. - * - * If both the 'cacheDuration' and 'validUntil' attributes are present, the shorter of them - * will be returned. + * This function looks for the 'validUntil' attribute to determine + * how long a given XML-element is valid. It returns this as a unix timestamp. * * @param mixed $element The element we should determine the expiry time of. * @param int|NULL $maxExpireTime The maximum expiration time. @@ -354,22 +351,13 @@ class SimpleSAML_Metadata_SAMLParser { * limit is set for the element. */ private static function getExpireTime($element, $maxExpireTime) { + /* validUntil may be NULL */ + $expire = $element->validUntil; - if ($element->cacheDuration !== NULL) { - $expire = SimpleSAML_Utilities::parseDuration($element->cacheDuration, time()); - if ($maxExpireTime !== NULL && $maxExpireTime < $expire) { - $expire = $maxExpireTime; - } - } else { + if ( $maxExpireTime !== NULL && ($expire === NULL || $maxExpireTime < $expire) ) { $expire = $maxExpireTime; } - if ($element->validUntil !== NULL) { - if ($expire === NULL || $expire > $element->validUntil) { - $expire = $element->validUntil; - } - } - return $expire; } diff --git a/modules/aggregator2/lib/EntitySource.php b/modules/aggregator2/lib/EntitySource.php index e849840ab..854147dc2 100644 --- a/modules/aggregator2/lib/EntitySource.php +++ b/modules/aggregator2/lib/EntitySource.php @@ -209,19 +209,6 @@ class sspmod_aggregator2_EntitySource { $expires = $this->metadata->validUntil; } - if ($this->metadata->cacheDuration !== NULL) { - try { - $durationTo = SimpleSAML_Utilities::parseDuration($this->metadata->cacheDuration); - } catch (Exception $e) { - SimpleSAML_Logger::warning($this->logLoc . 'Invalid cacheDuration in metadata from ' . - var_export($this->url, TRUE) . ': ' . var_export($this->metadata->cacheDuration, TRUE)); - return; - } - if ($durationTo < $expires) { - $expires = $durationTo; - } - } - $metadataSerialized = serialize($this->metadata); $this->aggregator->addCacheItem($this->cacheId, $metadataSerialized, $expires, $this->cacheTag); -- GitLab