-/*
- * Copyright 2001-2010 Internet2
+/**
+ * Licensed to the University Corporation for Advanced Internet
+ * Development, Inc. (UCAID) under one or more contributor license
+ * agreements. See the NOTICE file distributed with this work for
+ * additional information regarding copyright ownership.
*
- * 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
+ * UCAID licenses this file to you 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
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied. See the License for the specific
+ * language governing permissions and limitations under the License.
*/
/**
#include "saml2/metadata/Metadata.h"
#include "saml2/metadata/MetadataFilter.h"
#include "saml2/metadata/AbstractMetadataProvider.h"
+#include "saml2/metadata/DiscoverableMetadataProvider.h"
#include <fstream>
+#include <xmltooling/XMLToolingConfig.h>
#include <xmltooling/io/HTTPResponse.h>
#include <xmltooling/util/NDC.h>
+#include <xmltooling/util/PathResolver.h>
#include <xmltooling/util/ReloadableXMLFile.h>
#include <xmltooling/util/Threads.h>
#include <xmltooling/validation/ValidatorSuite.h>
+#if defined(OPENSAML_LOG4SHIB)
+# include <log4shib/NDC.hh>
+#elif defined(OPENSAML_LOG4CPP)
+# include <log4cpp/NDC.hh>
+#endif
+
using namespace opensaml::saml2md;
using namespace xmltooling::logging;
using namespace xmltooling;
namespace opensaml {
namespace saml2md {
- static const XMLCh minRefreshDelay[] = UNICODE_LITERAL_15(m,i,n,R,e,f,r,e,s,h,D,e,l,a,y);
- static const XMLCh refreshDelayFactor[] = UNICODE_LITERAL_18(r,e,f,r,e,s,h,D,e,l,a,y,F,a,c,t,o,r);
-
- class SAML_DLLLOCAL XMLMetadataProvider : public AbstractMetadataProvider, public ReloadableXMLFile
+ class SAML_DLLLOCAL XMLMetadataProvider
+ : public AbstractMetadataProvider, public DiscoverableMetadataProvider, public ReloadableXMLFile
{
public:
XMLMetadataProvider(const DOMElement* e);
}
void init() {
- background_load();
- startup();
+ try {
+ if (!m_id.empty()) {
+ string threadid("[");
+ threadid += m_id + ']';
+ logging::NDC::push(threadid);
+ }
+ background_load();
+ startup();
+ }
+ catch (...) {
+ startup();
+ if (!m_id.empty()) {
+ logging::NDC::pop();
+ }
+ throw;
+ }
+
+ if (!m_id.empty()) {
+ logging::NDC::pop();
+ }
+ }
+
+ const char* getId() const {
+ return m_id.c_str();
}
const XMLObject* getMetadata() const {
time_t computeNextRefresh();
XMLObject* m_object;
+ bool m_discoveryFeed;
double m_refreshDelayFactor;
unsigned int m_backoffFactor;
time_t m_minRefreshDelay,m_maxRefreshDelay,m_lastValidUntil;
return new XMLMetadataProvider(e);
}
+ static const XMLCh discoveryFeed[] = UNICODE_LITERAL_13(d,i,s,c,o,v,e,r,y,F,e,e,d);
+ static const XMLCh minRefreshDelay[] = UNICODE_LITERAL_15(m,i,n,R,e,f,r,e,s,h,D,e,l,a,y);
+ static const XMLCh refreshDelayFactor[] = UNICODE_LITERAL_18(r,e,f,r,e,s,h,D,e,l,a,y,F,a,c,t,o,r);
};
};
#endif
XMLMetadataProvider::XMLMetadataProvider(const DOMElement* e)
- : AbstractMetadataProvider(e), ReloadableXMLFile(e, Category::getInstance(SAML_LOGCAT".MetadataProvider.XML"), false),
- m_object(nullptr), m_refreshDelayFactor(0.75), m_backoffFactor(1), m_minRefreshDelay(600),
+ : MetadataProvider(e), AbstractMetadataProvider(e), DiscoverableMetadataProvider(e),
+ ReloadableXMLFile(e, Category::getInstance(SAML_LOGCAT".MetadataProvider.XML"), false),
+ m_object(nullptr), m_discoveryFeed(XMLHelper::getAttrBool(e, true, discoveryFeed)),
+ m_refreshDelayFactor(0.75), m_backoffFactor(1),
+ m_minRefreshDelay(XMLHelper::getAttrInt(e, 600, minRefreshDelay)),
m_maxRefreshDelay(m_reloadInterval), m_lastValidUntil(SAMLTIME_MAX)
{
if (!m_local && m_maxRefreshDelay) {
- const XMLCh* setting = e ? e->getAttributeNS(nullptr, refreshDelayFactor) : NULL;
+ const XMLCh* setting = e->getAttributeNS(nullptr, refreshDelayFactor);
if (setting && *setting) {
auto_ptr_char delay(setting);
m_refreshDelayFactor = atof(delay.get());
m_refreshDelayFactor = 0.75;
}
}
- setting = e ? e->getAttributeNS(nullptr, minRefreshDelay) : NULL;
- if (setting && *setting) {
- m_minRefreshDelay = XMLString::parseInt(setting);
- if (m_minRefreshDelay == 0) {
- m_log.error("invalid minRefreshDelay setting, using default");
- m_minRefreshDelay = 600;
- }
- else if (m_minRefreshDelay > m_maxRefreshDelay) {
- m_log.error("minRefreshDelay setting exceeds maxRefreshDelay/refreshInterval setting, lowering to match it");
- m_minRefreshDelay = m_maxRefreshDelay;
- }
+
+ if (m_minRefreshDelay > m_maxRefreshDelay) {
+ m_log.warn("minRefreshDelay setting exceeds maxRefreshDelay/reloadInterval setting, lowering to match it");
+ m_minRefreshDelay = m_maxRefreshDelay;
}
}
}
pair<bool,DOMElement*> XMLMetadataProvider::load(bool backup)
{
- // Lower the refresh rate in case of an error.
- m_reloadInterval = m_minRefreshDelay;
+ if (!backup) {
+ // Lower the refresh rate in case of an error.
+ m_reloadInterval = m_minRefreshDelay;
+ }
// Call the base class to load/parse the appropriate XML resource.
pair<bool,DOMElement*> raw = ReloadableXMLFile::load(backup);
remove(m_backing.c_str());
if (rename(backupKey.c_str(), m_backing.c_str()) != 0)
m_log.crit("unable to rename metadata backup file");
+ preserveCacheTag();
}
xmlObject->releaseThisAndChildrenDOM();
m_object = xmlObject.release();
m_lastValidUntil = SAMLTIME_MAX;
index(m_lastValidUntil);
+ if (m_discoveryFeed)
+ generateFeed();
if (changed)
emitChangeEvent();
+ m_lastUpdate = time(nullptr);
// Tracking cacheUntil through the tree is TBD, but
// validUntil is the tightest interval amongst the children.
- // If a remote resource, adjust the reload interval.
- if (!backup) {
+ // If a remote resource that's monitored, adjust the reload interval.
+ if (!backup && !m_local && m_lock) {
m_backoffFactor = 1;
m_reloadInterval = computeNextRefresh();
m_log.info("adjusted reload interval to %d seconds", m_reloadInterval);
if (ex == HTTPResponse::XMLTOOLING_HTTP_STATUS_NOTMODIFIED) {
// Unchanged document, so re-establish previous refresh interval.
m_reloadInterval = computeNextRefresh();
- m_log.info("adjusted reload interval to %d seconds", m_reloadInterval);
+ m_log.info("remote resource (%s) unchanged, adjusted reload interval to %u seconds", m_source.c_str(), m_reloadInterval);
}
else {
// Any other status code, just treat as an error.
m_reloadInterval = m_minRefreshDelay * m_backoffFactor++;
if (m_reloadInterval > m_maxRefreshDelay)
m_reloadInterval = m_maxRefreshDelay;
- m_log.warn("adjusted reload interval to %d seconds", m_reloadInterval);
+ m_log.warn("adjusted reload interval to %u seconds", m_reloadInterval);
}
if (!m_loaded && !m_backing.empty())
return load(true);
throw;
}
catch (exception&) {
- m_reloadInterval = m_minRefreshDelay * m_backoffFactor++;
- if (m_reloadInterval > m_maxRefreshDelay)
- m_reloadInterval = m_maxRefreshDelay;
- m_log.warn("adjusted reload interval to %d seconds", m_reloadInterval);
- if (!m_loaded && !m_backing.empty())
- return load(true);
+ if (!m_local) {
+ m_reloadInterval = m_minRefreshDelay * m_backoffFactor++;
+ if (m_reloadInterval > m_maxRefreshDelay)
+ m_reloadInterval = m_maxRefreshDelay;
+ m_log.warn("adjusted reload interval to %u seconds", m_reloadInterval);
+ if (!m_loaded && !m_backing.empty())
+ return load(true);
+ }
throw;
}
}
-void XMLMetadataProvider::index(time_t& validUntil)
-{
- clearDescriptorIndex();
- EntitiesDescriptor* group=dynamic_cast<EntitiesDescriptor*>(m_object);
- if (group) {
- indexGroup(group, validUntil);
- return;
- }
- indexEntity(dynamic_cast<EntityDescriptor*>(m_object), validUntil);
-}
-
time_t XMLMetadataProvider::computeNextRefresh()
{
time_t now = time(nullptr);
return ret;
}
}
+
+void XMLMetadataProvider::index(time_t& validUntil)
+{
+ clearDescriptorIndex();
+ EntitiesDescriptor* group=dynamic_cast<EntitiesDescriptor*>(m_object);
+ if (group) {
+ indexGroup(group, validUntil);
+ return;
+ }
+ indexEntity(dynamic_cast<EntityDescriptor*>(m_object), validUntil);
+}