Skip to content
Snippets Groups Projects
Commit 695bcb34 authored by Olav Morken's avatar Olav Morken
Browse files

metarefresh: Restructure MetaLoader to return early on error/not modified.

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@3086 44740490-163a-0410-bde0-09ae8108e29a
parent 1b086424
No related branches found
No related tags found
No related merge requests found
...@@ -56,68 +56,68 @@ class sspmod_metarefresh_MetaLoader { ...@@ -56,68 +56,68 @@ class sspmod_metarefresh_MetaLoader {
} }
// We have response headers, so the request succeeded // We have response headers, so the request succeeded
if(isset($responseHeaders)) { if(!isset($responseHeaders)) {
// No response headers, this means the request failed in some way, so re-use old data
// 200 OK SimpleSAML_Logger::debug('No response from ' . $source['src'] . ' - attempting to re-use cached metadata');
if(preg_match('@^HTTP/1\.[01]\s200\s@', $responseHeaders[0])) { $this->addCachedMetadata($source);
return;
if (isset($source['conditionalGET']) && $source['conditionalGET']) { } elseif(preg_match('@^HTTP/1\.[01]\s304\s@', $responseHeaders[0])) {
// Stale or no metadata, so a fresh copy // 304 response
SimpleSAML_Logger::debug('Downloaded fresh copy'); SimpleSAML_Logger::debug('Received HTTP 304 (Not Modified) - attempting to re-use cached metadata');
} $this->addCachedMetadata($source);
return;
$entities = $this->loadXML($data, $source); } elseif(!preg_match('@^HTTP/1\.[01]\s200\s@', $responseHeaders[0])) {
// Other error.
foreach($entities as $entity) { SimpleSAML_Logger::debug('Error from ' . $source['src'] . ' - attempting to re-use cached metadata');
$this->addCachedMetadata($source);
if(isset($source['blacklist'])) { return;
if(!empty($source['blacklist']) && in_array($entity->getEntityID(), $source['blacklist'])) { }
SimpleSAML_Logger::info('Skipping "' . $entity->getEntityID() . '" - blacklisted.' . "\n");
continue;
}
}
if(isset($source['whitelist'])) { /* Everything OK. Proceed. */
if(!empty($source['whitelist']) && !in_array($entity->getEntityID(), $source['whitelist'])) { if (isset($source['conditionalGET']) && $source['conditionalGET']) {
SimpleSAML_Logger::info('Skipping "' . $entity->getEntityID() . '" - not in the whitelist.' . "\n"); // Stale or no metadata, so a fresh copy
continue; SimpleSAML_Logger::debug('Downloaded fresh copy');
} }
}
if(array_key_exists('validateFingerprint', $source) && $source['validateFingerprint'] !== NULL) { $entities = $this->loadXML($data, $source);
if(!$entity->validateFingerprint($source['validateFingerprint'])) {
SimpleSAML_Logger::info('Skipping "' . $entity->getEntityId() . '" - could not verify signature.' . "\n");
continue;
}
}
$template = NULL; foreach($entities as $entity) {
if (array_key_exists('template', $source)) $template = $source['template'];
$this->addMetadata($source['src'], $entity->getMetadata1xSP(), 'shib13-sp-remote', $template); if(isset($source['blacklist'])) {
$this->addMetadata($source['src'], $entity->getMetadata1xIdP(), 'shib13-idp-remote', $template); if(!empty($source['blacklist']) && in_array($entity->getEntityID(), $source['blacklist'])) {
$this->addMetadata($source['src'], $entity->getMetadata20SP(), 'saml20-sp-remote', $template); SimpleSAML_Logger::info('Skipping "' . $entity->getEntityID() . '" - blacklisted.' . "\n");
$this->addMetadata($source['src'], $entity->getMetadata20IdP(), 'saml20-idp-remote', $template); continue;
$attributeAuthorities = $entity->getAttributeAuthorities();
if (!empty($attributeAuthorities)) {
$this->addMetadata($source['src'], $attributeAuthorities[0], 'attributeauthority-remote', $template);
}
} }
}
$this->saveState($source, $responseHeaders); if(isset($source['whitelist'])) {
if(!empty($source['whitelist']) && !in_array($entity->getEntityID(), $source['whitelist'])) {
SimpleSAML_Logger::info('Skipping "' . $entity->getEntityID() . '" - not in the whitelist.' . "\n");
continue;
}
} }
// 304 response if(array_key_exists('validateFingerprint', $source) && $source['validateFingerprint'] !== NULL) {
if(preg_match('@^HTTP/1\.[01]\s304\s@', $responseHeaders[0])) { if(!$entity->validateFingerprint($source['validateFingerprint'])) {
SimpleSAML_Logger::debug('Received HTTP 304 (Not Modified) - attempting to re-use cached metadata'); SimpleSAML_Logger::info('Skipping "' . $entity->getEntityId() . '" - could not verify signature.' . "\n");
$this->addCachedMetadata($source); continue;
}
} }
} else { $template = NULL;
// No response headers, this means the request failed in some way, so re-use old data if (array_key_exists('template', $source)) $template = $source['template'];
SimpleSAML_Logger::debug('No response from ' . $source['src'] . ' - attempting to re-use cached metadata');
$this->addCachedMetadata($source); $this->addMetadata($source['src'], $entity->getMetadata1xSP(), 'shib13-sp-remote', $template);
$this->addMetadata($source['src'], $entity->getMetadata1xIdP(), 'shib13-idp-remote', $template);
$this->addMetadata($source['src'], $entity->getMetadata20SP(), 'saml20-sp-remote', $template);
$this->addMetadata($source['src'], $entity->getMetadata20IdP(), 'saml20-idp-remote', $template);
$attributeAuthorities = $entity->getAttributeAuthorities();
if (!empty($attributeAuthorities)) {
$this->addMetadata($source['src'], $attributeAuthorities[0], 'attributeauthority-remote', $template);
}
} }
$this->saveState($source, $responseHeaders);
} }
/** /**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment