X-Git-Url: http://www.project-moonshot.org/gitweb/?p=shibboleth%2Fcpp-opensaml.git;a=blobdiff_plain;f=saml%2Fsaml2%2Fmetadata%2Fimpl%2FXMLMetadataProvider.cpp;h=1809d3dca3c620c7268a5553267ab519d96054c3;hp=d0d3ad2feafa0604942e2e13adb64bcfcfccfdf3;hb=9247fd98448d17c495f1d811ac1ba82571f7ef98;hpb=0f6286d0ffd9371c187ecb1775cbd199ed051af5 diff --git a/saml/saml2/metadata/impl/XMLMetadataProvider.cpp b/saml/saml2/metadata/impl/XMLMetadataProvider.cpp index d0d3ad2..1809d3d 100644 --- a/saml/saml2/metadata/impl/XMLMetadataProvider.cpp +++ b/saml/saml2/metadata/impl/XMLMetadataProvider.cpp @@ -1,6 +1,6 @@ /* * Copyright 2001-2007 Internet2 - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -16,7 +16,7 @@ /** * XMLMetadataProvider.cpp - * + * * Supplies metadata from an XML file */ @@ -27,6 +27,7 @@ #include #include +#include using namespace opensaml::saml2md; using namespace xmltooling::logging; @@ -45,8 +46,8 @@ namespace opensaml { { public: XMLMetadataProvider(const DOMElement* e) - : AbstractMetadataProvider(e), ReloadableXMLFile(e, Category::getInstance(SAML_LOGCAT".MetadataProvider")), - m_object(NULL) { + : AbstractMetadataProvider(e), ReloadableXMLFile(e, Category::getInstance(SAML_LOGCAT".MetadataProvider.XML")), + m_object(NULL), m_maxCacheDuration(m_reloadInterval) { } virtual ~XMLMetadataProvider() { delete m_object; @@ -55,7 +56,7 @@ namespace opensaml { void init() { load(); // guarantees an exception or the metadata is loaded } - + const XMLObject* getMetadata() const { return m_object; } @@ -66,9 +67,10 @@ namespace opensaml { private: using AbstractMetadataProvider::index; void index(); - + XMLObject* m_object; - }; + time_t m_maxCacheDuration; + }; MetadataProvider* SAML_DLLLOCAL XMLMetadataProviderFactory(const DOMElement* const & e) { @@ -86,10 +88,10 @@ pair XMLMetadataProvider::load() { // Load from source using base class. pair raw = ReloadableXMLFile::load(); - + // If we own it, wrap it for now. XercesJanitor docjanitor(raw.first ? raw.second->getOwnerDocument() : NULL); - + // Unmarshall objects, binding the document. auto_ptr xmlObject(XMLObjectBuilder::buildOneFromElement(raw.second, true)); docjanitor.release(); @@ -98,12 +100,21 @@ pair XMLMetadataProvider::load() throw MetadataException( "Root of metadata instance not recognized: $1", params(1,xmlObject->getElementQName().toString().c_str()) ); - + // Preprocess the metadata. + if (!m_validate) { + try { + SchemaValidators.validate(xmlObject.get()); + } + catch (exception& ex) { + m_log.error("metadata intance failed manual schema validation checking: %s", ex.what()); + throw MetadataException("Metadata instance failed manual schema validation checking."); + } + } doFilters(*xmlObject.get()); xmlObject->releaseThisAndChildrenDOM(); xmlObject->setDocument(NULL); - + // Swap it in. bool changed = m_object!=NULL; delete m_object; @@ -111,17 +122,33 @@ pair XMLMetadataProvider::load() index(); if (changed) emitChangeEvent(); + + // If a remote resource, reduce the reload interval if cacheDuration is set. + if (!m_local) { + const CacheableSAMLObject* cacheable = dynamic_cast(m_object); + if (cacheable && cacheable->getCacheDuration() && cacheable->getCacheDurationEpoch() < m_maxCacheDuration) + m_reloadInterval = cacheable->getCacheDurationEpoch(); + else + m_reloadInterval = m_maxCacheDuration; + } + return make_pair(false,(DOMElement*)NULL); } void XMLMetadataProvider::index() { + time_t exp = SAMLTIME_MAX; + clearDescriptorIndex(); EntitiesDescriptor* group=dynamic_cast(m_object); if (group) { - AbstractMetadataProvider::index(group, SAMLTIME_MAX); + if (!m_local && group->getCacheDuration()) + exp = time(NULL) + group->getCacheDurationEpoch(); + AbstractMetadataProvider::index(group, exp); return; } EntityDescriptor* site=dynamic_cast(m_object); - AbstractMetadataProvider::index(site, SAMLTIME_MAX); + if (!m_local && site->getCacheDuration()) + exp = time(NULL) + site->getCacheDurationEpoch(); + AbstractMetadataProvider::index(site, exp); }