/*
* 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
/**
* XMLMetadataProvider.cpp
- *
+ *
* Supplies metadata from an XML file
*/
{
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;
void init() {
load(); // guarantees an exception or the metadata is loaded
}
-
+
const XMLObject* getMetadata() const {
return m_object;
}
private:
using AbstractMetadataProvider::index;
void index();
-
+
XMLObject* m_object;
- };
+ time_t m_maxCacheDuration;
+ };
MetadataProvider* SAML_DLLLOCAL XMLMetadataProviderFactory(const DOMElement* const & e)
{
{
// Load from source using base class.
pair<bool,DOMElement*> raw = ReloadableXMLFile::load();
-
+
// If we own it, wrap it for now.
XercesJanitor<DOMDocument> docjanitor(raw.first ? raw.second->getOwnerDocument() : NULL);
-
+
// Unmarshall objects, binding the document.
auto_ptr<XMLObject> xmlObject(XMLObjectBuilder::buildOneFromElement(raw.second, true));
docjanitor.release();
throw MetadataException(
"Root of metadata instance not recognized: $1", params(1,xmlObject->getElementQName().toString().c_str())
);
-
+
// Preprocess the metadata.
doFilters(*xmlObject.get());
xmlObject->releaseThisAndChildrenDOM();
xmlObject->setDocument(NULL);
-
+
// Swap it in.
bool changed = m_object!=NULL;
delete m_object;
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);
}