namespace opensaml {
namespace saml2md {
- static const XMLCh requireValidUntil[] = UNICODE_LITERAL_17(r,e,q,u,i,r,e,V,a,l,i,d,U,n,t,i,l);
-
class SAML_DLLLOCAL XMLMetadataProvider : public AbstractMetadataProvider, public ReloadableXMLFile
{
public:
XMLMetadataProvider(const DOMElement* e)
: AbstractMetadataProvider(e), ReloadableXMLFile(e, Category::getInstance(SAML_LOGCAT".MetadataProvider.XML")),
- m_object(NULL), m_requireValidUntil(false) {
- const XMLCh* flag = e ? e->getAttributeNS(NULL,requireValidUntil) : NULL;
- m_requireValidUntil = (flag && (*flag == chLatin_t || *flag == chDigit_1));
+ m_object(NULL), m_maxCacheDuration(m_reloadInterval) {
}
virtual ~XMLMetadataProvider() {
delete m_object;
void index();
XMLObject* m_object;
- bool m_requireValidUntil;
+ time_t m_maxCacheDuration;
};
MetadataProvider* SAML_DLLLOCAL XMLMetadataProviderFactory(const DOMElement* const & e)
"Root of metadata instance not recognized: $1", params(1,xmlObject->getElementQName().toString().c_str())
);
- if (m_requireValidUntil) {
- const TimeBoundSAMLObject* tbo = dynamic_cast<const TimeBoundSAMLObject*>(xmlObject.get());
- if (!tbo || tbo->getValidUntil() == NULL)
- throw MetadataException("Root of metadata instance does not have validUntil atttribute.");
- }
-
// Preprocess the metadata.
doFilters(*xmlObject.get());
xmlObject->releaseThisAndChildrenDOM();
index();
if (changed)
emitChangeEvent();
+
+ // If a remote resource, reduce the reload interval if cacheDuration is set.
+ if (!m_local) {
+ const CacheableSAMLObject* cacheable = dynamic_cast<const CacheableSAMLObject*>(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<EntitiesDescriptor*>(m_object);
if (group) {
- AbstractMetadataProvider::index(group, SAMLTIME_MAX);
+ if (!m_local && group->getCacheDuration())
+ exp = time_t(NULL) + group->getCacheDurationEpoch();
+ AbstractMetadataProvider::index(group, exp);
return;
}
EntityDescriptor* site=dynamic_cast<EntityDescriptor*>(m_object);
- AbstractMetadataProvider::index(site, SAMLTIME_MAX);
+ if (!m_local && site->getCacheDuration())
+ exp = time_t(NULL) + site->getCacheDurationEpoch();
+ AbstractMetadataProvider::index(site, exp);
}