saml2/metadata/impl/AbstractMetadataProvider.cpp \
saml2/metadata/impl/BlacklistMetadataFilter.cpp \
saml2/metadata/impl/ChainingMetadataProvider.cpp \
- saml2/metadata/impl/FilesystemMetadataProvider.cpp \
saml2/metadata/impl/MetadataImpl.cpp \
saml2/metadata/impl/MetadataProvider.cpp \
saml2/metadata/impl/MetadataSchemaValidators.cpp \
saml2/metadata/impl/ObservableMetadataProvider.cpp \
saml2/metadata/impl/SignatureMetadataFilter.cpp \
saml2/metadata/impl/WhitelistMetadataFilter.cpp \
+ saml2/metadata/impl/XMLMetadataProvider.cpp \
saml2/binding/impl/SAML2Artifact.cpp \
saml2/binding/impl/SAML2ArtifactType0004.cpp \
saml2/binding/impl/SAML2ArtifactDecoder.cpp \
>\r
</File>\r
<File\r
- RelativePath=".\saml2\metadata\impl\FilesystemMetadataProvider.cpp"\r
- >\r
- </File>\r
- <File\r
RelativePath=".\saml2\metadata\impl\MetadataImpl.cpp"\r
>\r
</File>\r
RelativePath=".\saml2\metadata\impl\WhitelistMetadataFilter.cpp"\r
>\r
</File>\r
+ <File\r
+ RelativePath=".\saml2\metadata\impl\XMLMetadataProvider.cpp"\r
+ >\r
+ </File>\r
</Filter>\r
</Filter>\r
<Filter\r
*/
void SAML_API registerMetadataProviders();
- /** MetadataProvider based on local XML files */
- #define FILESYSTEM_METADATA_PROVIDER "org.opensaml.saml2.metadata.provider.FilesystemMetadataProvider"
+ /** MetadataProvider based on local or remote XML file */
+ #define XML_METADATA_PROVIDER "org.opensaml.saml2.metadata.provider.XMLMetadataProvider"
/** MetadataProvider that wraps a sequence of metadata providers. */
#define CHAINING_METADATA_PROVIDER "org.opensaml.saml2.metadata.provider.ChainingMetadataProvider"
+++ /dev/null
-/*
- * Copyright 2001-2006 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
- *
- * 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.
- */
-
-/**
- * FilesystemMetadataProvider.cpp
- *
- * Supplies metadata from a local file, detecting and reloading changes.
- */
-
-#include "internal.h"
-#include "saml2/metadata/Metadata.h"
-#include "saml2/metadata/AbstractMetadataProvider.h"
-
-#include <ctime>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <log4cpp/Category.hh>
-#include <xercesc/framework/LocalFileInputSource.hpp>
-#include <xercesc/framework/Wrapper4InputSource.hpp>
-#include <xercesc/util/XMLUniDefs.hpp>
-#include <xmltooling/util/NDC.h>
-#include <xmltooling/util/Threads.h>
-#include <xmltooling/util/XMLConstants.h>
-
-using namespace opensaml::saml2md;
-using namespace xmltooling;
-using namespace log4cpp;
-using namespace std;
-
-namespace opensaml {
- namespace saml2md {
-
-
- class SAML_DLLLOCAL FilesystemMetadataProvider : public AbstractMetadataProvider
- {
- public:
- FilesystemMetadataProvider(const DOMElement* e);
- ~FilesystemMetadataProvider();
-
- Lockable* lock();
- void unlock() {
- if (m_lock)
- m_lock->unlock();
- }
-
- void init();
-
- const XMLObject* getMetadata() const {
- return m_object;
- }
-
- private:
- XMLObject* load() const;
- void index();
-
- const DOMElement* m_root; // survives only until init() method is done
- std::string m_source;
- time_t m_filestamp;
- bool m_validate;
- RWLock* m_lock;
- XMLObject* m_object;
- };
-
- MetadataProvider* SAML_DLLLOCAL FilesystemMetadataProviderFactory(const DOMElement* const & e)
- {
- return new FilesystemMetadataProvider(e);
- }
-
- };
-};
-
-static const XMLCh uri[] = UNICODE_LITERAL_3(u,r,i);
-static const XMLCh url[] = UNICODE_LITERAL_3(u,r,l);
-static const XMLCh path[] = UNICODE_LITERAL_4(p,a,t,h);
-static const XMLCh pathname[] = UNICODE_LITERAL_8(p,a,t,h,n,a,m,e);
-static const XMLCh file[] = UNICODE_LITERAL_4(f,i,l,e);
-static const XMLCh filename[] = UNICODE_LITERAL_8(f,i,l,e,n,a,m,e);
-static const XMLCh validate[] = UNICODE_LITERAL_8(v,a,l,i,d,a,t,e);
-
-FilesystemMetadataProvider::FilesystemMetadataProvider(const DOMElement* e)
- : AbstractMetadataProvider(e), m_root(e), m_filestamp(0), m_validate(false), m_lock(NULL), m_object(NULL)
-{
-#ifdef _DEBUG
- NDC ndc("FilesystemMetadataProvider");
-#endif
- Category& log=Category::getInstance(SAML_LOGCAT".Metadata");
-
- // Establish source of data...
- const XMLCh* source=e->getAttributeNS(NULL,uri);
- if (!source || !*source) {
- source=e->getAttributeNS(NULL,url);
- if (!source || !*source) {
- source=e->getAttributeNS(NULL,path);
- if (!source || !*source) {
- source=e->getAttributeNS(NULL,pathname);
- if (!source || !*source) {
- source=e->getAttributeNS(NULL,file);
- if (!source || !*source) {
- source=e->getAttributeNS(NULL,filename);
- }
- }
- }
- }
- }
-
- if (source && *source) {
- const XMLCh* valflag=e->getAttributeNS(NULL,validate);
- m_validate=(XMLString::equals(valflag,xmlconstants::XML_TRUE) || XMLString::equals(valflag,xmlconstants::XML_ONE));
-
- auto_ptr_char temp(source);
- m_source=temp.get();
- log.debug("using external metadata file (%s)", temp.get());
-
-#ifdef WIN32
- struct _stat stat_buf;
- if (_stat(m_source.c_str(), &stat_buf) == 0)
-#else
- struct stat stat_buf;
- if (stat(m_source.c_str(), &stat_buf) == 0)
-#endif
- m_filestamp=stat_buf.st_mtime;
- m_lock=RWLock::create();
- }
- else
- log.debug("no file path/name supplied, will look for metadata inline");
-}
-
-FilesystemMetadataProvider::~FilesystemMetadataProvider()
-{
- delete m_lock;
- delete m_object;
-}
-
-void FilesystemMetadataProvider::init()
-{
- m_object=load();
- index();
-}
-
-XMLObject* FilesystemMetadataProvider::load() const
-{
-#ifdef _DEBUG
- NDC ndc("load");
-#endif
- Category& log=Category::getInstance(SAML_LOGCAT".Metadata");
-
- try {
- XMLObject* xmlObject=NULL;
-
- if (!m_source.empty()) {
- // Data comes from a file we have to parse.
- log.debug("loading metadata from file...");
- auto_ptr_XMLCh widenit(m_source.c_str());
- LocalFileInputSource src(widenit.get());
- Wrapper4InputSource dsrc(&src,false);
- DOMDocument* doc=NULL;
- if (m_validate)
- doc=XMLToolingConfig::getConfig().getValidatingParser().parse(dsrc);
- else
- doc=XMLToolingConfig::getConfig().getParser().parse(dsrc);
- XercesJanitor<DOMDocument> docjanitor(doc);
- log.infoStream() << "loaded and parsed XML file (" << m_source << ")" << CategoryStream::ENDLINE;
-
- // Unmarshall objects, binding the document.
- xmlObject = XMLObjectBuilder::buildOneFromElement(doc->getDocumentElement(), true);
- docjanitor.release();
- }
- else {
- // Data comes from the DOM we were handed.
- log.debug("loading inline metadata...");
- DOMElement* child = XMLHelper::getFirstChildElement(m_root);
- if (!child)
- throw XMLToolingException("No metadata was found inline.");
- xmlObject = XMLObjectBuilder::buildOneFromElement(child);
- }
-
- auto_ptr<XMLObject> xmlObjectPtr(xmlObject);
-
- doFilters(*xmlObject);
-
- xmlObjectPtr->releaseThisAndChildrenDOM();
- xmlObjectPtr->setDocument(NULL);
- return xmlObjectPtr.release();
- }
- catch (XMLException& e) {
- auto_ptr_char msg(e.getMessage());
- log.errorStream() << "Xerces parser error while loading metadata from ("
- << (m_source.empty() ? "inline" : m_source) << "): " << msg.get() << CategoryStream::ENDLINE;
- throw XMLParserException(msg.get());
- }
- catch (XMLToolingException& e) {
- log.errorStream() << "error while loading metadata from ("
- << (m_source.empty() ? "inline" : m_source) << "): " << e.what() << CategoryStream::ENDLINE;
- throw;
- }
-}
-
-Lockable* FilesystemMetadataProvider::lock()
-{
- if (!m_lock)
- return this;
-
- m_lock->rdlock();
-
- // Check if we need to refresh.
-#ifdef WIN32
- struct _stat stat_buf;
- if (_stat(m_source.c_str(), &stat_buf) == 0)
-#else
- struct stat stat_buf;
- if (stat(m_source.c_str(), &stat_buf) == 0)
-#endif
- {
- if (m_filestamp>0 && m_filestamp<stat_buf.st_mtime) {
- // Elevate lock and recheck.
- m_lock->unlock();
- m_lock->wrlock();
- if (m_filestamp>0 && m_filestamp<stat_buf.st_mtime) {
- SharedLock lockwrap(m_lock,false); // pops write lock
- try {
- // Update the timestamp regardless. No point in repeatedly trying.
- m_filestamp=stat_buf.st_mtime;
- XMLObject* newstuff = load();
- delete m_object;
- m_object = newstuff;
- index();
- emitChangeEvent();
- }
- catch(XMLToolingException& e) {
- Category::getInstance(SAML_LOGCAT".Metadata").error("failed to reload metadata from file, sticking with what we have: %s", e.what());
- }
- }
- else {
- m_lock->unlock();
- }
- m_lock->rdlock();
- }
- }
- return this;
-}
-
-void FilesystemMetadataProvider::index()
-{
- clearDescriptorIndex();
- EntitiesDescriptor* group=dynamic_cast<EntitiesDescriptor*>(m_object);
- if (group) {
- AbstractMetadataProvider::index(group, SAMLTIME_MAX);
- return;
- }
- EntityDescriptor* site=dynamic_cast<EntityDescriptor*>(m_object);
- AbstractMetadataProvider::index(site, SAMLTIME_MAX);
-}
namespace opensaml {
namespace saml2md {
- SAML_DLLLOCAL PluginManager<MetadataProvider,const DOMElement*>::Factory FilesystemMetadataProviderFactory;
+ SAML_DLLLOCAL PluginManager<MetadataProvider,const DOMElement*>::Factory XMLMetadataProviderFactory;
SAML_DLLLOCAL PluginManager<MetadataProvider,const DOMElement*>::Factory ChainingMetadataProviderFactory;
SAML_DLLLOCAL PluginManager<MetadataFilter,const DOMElement*>::Factory BlacklistMetadataFilterFactory;
SAML_DLLLOCAL PluginManager<MetadataFilter,const DOMElement*>::Factory WhitelistMetadataFilterFactory;
void SAML_API opensaml::saml2md::registerMetadataProviders()
{
SAMLConfig& conf=SAMLConfig::getConfig();
- conf.MetadataProviderManager.registerFactory(FILESYSTEM_METADATA_PROVIDER, FilesystemMetadataProviderFactory);
+ conf.MetadataProviderManager.registerFactory(XML_METADATA_PROVIDER, XMLMetadataProviderFactory);
conf.MetadataProviderManager.registerFactory(CHAINING_METADATA_PROVIDER, ChainingMetadataProviderFactory);
- conf.MetadataProviderManager.registerFactory("edu.internet2.middleware.shibboleth.metadata.provider.XMLMetadata", FilesystemMetadataProviderFactory);
- conf.MetadataProviderManager.registerFactory("edu.internet2.middleware.shibboleth.common.provider.XMLMetadata", FilesystemMetadataProviderFactory);
+ conf.MetadataProviderManager.registerFactory("edu.internet2.middleware.shibboleth.metadata.provider.XMLMetadata", XMLMetadataProviderFactory);
+ conf.MetadataProviderManager.registerFactory("edu.internet2.middleware.shibboleth.common.provider.XMLMetadata", XMLMetadataProviderFactory);
}
void SAML_API opensaml::saml2md::registerMetadataFilters()
--- /dev/null
+/*
+ * Copyright 2001-2006 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
+ *
+ * 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.
+ */
+
+/**
+ * XMLMetadataProvider.cpp
+ *
+ * Supplies metadata from an XML file
+ */
+
+#include "internal.h"
+#include "saml2/metadata/Metadata.h"
+#include "saml2/metadata/AbstractMetadataProvider.h"
+
+#include <log4cpp/Category.hh>
+#include <xmltooling/util/NDC.h>
+#include <xmltooling/util/ReloadableXMLFile.h>
+#include <xmltooling/util/XMLConstants.h>
+
+using namespace opensaml::saml2md;
+using namespace xmltooling;
+using namespace log4cpp;
+using namespace std;
+
+#if defined (_MSC_VER)
+ #pragma warning( push )
+ #pragma warning( disable : 4250 )
+#endif
+
+namespace opensaml {
+ namespace saml2md {
+
+ class SAML_DLLLOCAL XMLMetadataProvider : public AbstractMetadataProvider, public ReloadableXMLFile
+ {
+ public:
+ XMLMetadataProvider(const DOMElement* e) : AbstractMetadataProvider(e), ReloadableXMLFile(e), m_object(NULL) {}
+ virtual ~XMLMetadataProvider() {
+ delete m_object;
+ }
+
+ void init() {
+ load(); // guarantees an exception or the metadata is loaded
+ }
+
+ pair<bool,DOMElement*> load();
+
+ const XMLObject* getMetadata() const {
+ return m_object;
+ }
+
+ private:
+ void index();
+
+ XMLObject* m_object;
+ };
+
+ MetadataProvider* SAML_DLLLOCAL XMLMetadataProviderFactory(const DOMElement* const & e)
+ {
+ return new XMLMetadataProvider(e);
+ }
+
+ };
+};
+
+#if defined (_MSC_VER)
+ #pragma warning( pop )
+#endif
+
+pair<bool,DOMElement*> XMLMetadataProvider::load()
+{
+#ifdef _DEBUG
+ NDC ndc("load");
+#endif
+
+ try {
+ // 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.
+ XMLObject* xmlObject=XMLObjectBuilder::buildOneFromElement(raw.second, true);
+ docjanitor.release();
+
+ // Preprocess the metadata.
+ auto_ptr<XMLObject> xmlObjectPtr(xmlObject);
+ doFilters(*xmlObject);
+ xmlObjectPtr->releaseThisAndChildrenDOM();
+ xmlObjectPtr->setDocument(NULL);
+
+ // Swap it in.
+ bool changed = m_object!=NULL;
+ delete m_object;
+ m_object = xmlObjectPtr.release();
+ index();
+ if (changed)
+ emitChangeEvent();
+ return make_pair(false,(DOMElement*)NULL);
+ }
+ catch (XMLToolingException& e) {
+ Category::getInstance(SAML_LOGCAT".Metadata").error("error while loading metadata: %s", e.what());
+ throw;
+ }
+}
+
+void XMLMetadataProvider::index()
+{
+ clearDescriptorIndex();
+ EntitiesDescriptor* group=dynamic_cast<EntitiesDescriptor*>(m_object);
+ if (group) {
+ AbstractMetadataProvider::index(group, SAMLTIME_MAX);
+ return;
+ }
+ EntityDescriptor* site=dynamic_cast<EntityDescriptor*>(m_object);
+ AbstractMetadataProvider::index(site, SAMLTIME_MAX);
+}
saml2/binding/SAML2ArtifactTest.h \
saml2/binding/SAML2POSTTest.h \
saml2/binding/SAML2RedirectTest.h \
- saml2/metadata/FilesystemMetadataProviderTest.h
+ saml2/metadata/XMLMetadataProviderTest.h
noinst_HEADERS = \
binding.h \
doc->getDocumentElement()->setAttributeNS(NULL,path.get(),file.get());\r
\r
m_metadata = SAMLConfig::getConfig().MetadataProviderManager.newPlugin(\r
- FILESYSTEM_METADATA_PROVIDER,doc->getDocumentElement()\r
+ XML_METADATA_PROVIDER,doc->getDocumentElement()\r
);\r
m_metadata->init();\r
\r
* limitations under the License.
*/
+#ifdef WIN32\r
+# define _CRT_SECURE_NO_DEPRECATE 1\r
+# define _CRT_NONSTDC_NO_DEPRECATE 1\r
+#endif\r
+
#include <cxxtest/TestSuite.h>
#include <fstream>
using namespace opensaml::saml2md;
using namespace opensaml::saml2p;
-class FilesystemMetadataProviderTest : public CxxTest::TestSuite, public SAMLObjectBaseTestCase {
+class XMLMetadataProviderTest : public CxxTest::TestSuite, public SAMLObjectBaseTestCase {
XMLCh* entityID;
XMLCh* entityID2;
XMLCh* supportedProtocol;
SAMLObjectBaseTestCase::tearDown();
}
- void testFilesystemProvider() {
- string config = data_path + "saml2/metadata/FilesystemMetadataProvider.xml";
+ void testXMLProvider() {
+ string config = data_path + "saml2/metadata/XMLMetadataProvider.xml";
ifstream in(config.c_str());
DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(in);
XercesJanitor<DOMDocument> janitor(doc);
doc->getDocumentElement()->setAttributeNS(NULL,path.get(),file.get());
auto_ptr<MetadataProvider> metadataProvider(
- SAMLConfig::getConfig().MetadataProviderManager.newPlugin(FILESYSTEM_METADATA_PROVIDER,doc->getDocumentElement())
+ SAMLConfig::getConfig().MetadataProviderManager.newPlugin(XML_METADATA_PROVIDER,doc->getDocumentElement())
);
try {
metadataProvider->init();
assertEquals("Entity's ID does not match requested ID", entityID, descriptor->getEntityID());
}
- void testFilesystemWithBlacklists() {
- string config = data_path + "saml2/metadata/FilesystemWithBlacklists.xml";
+ void testXMLWithBlacklists() {
+ string config = data_path + "saml2/metadata/XMLWithBlacklists.xml";
ifstream in(config.c_str());
DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(in);
XercesJanitor<DOMDocument> janitor(doc);
doc->getDocumentElement()->setAttributeNS(NULL,path.get(),file.get());
auto_ptr<MetadataProvider> metadataProvider(
- SAMLConfig::getConfig().MetadataProviderManager.newPlugin(FILESYSTEM_METADATA_PROVIDER,doc->getDocumentElement())
+ SAMLConfig::getConfig().MetadataProviderManager.newPlugin(XML_METADATA_PROVIDER,doc->getDocumentElement())
);
try {
metadataProvider->init();
assertEquals("Entity's ID does not match requested ID", entityID2, descriptor->getEntityID());
}
- void testFilesystemWithWhitelists() {
- string config = data_path + "saml2/metadata/FilesystemWithWhitelists.xml";
+ void testXMLWithWhitelists() {
+ string config = data_path + "saml2/metadata/XMLWithWhitelists.xml";
ifstream in(config.c_str());
DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(in);
XercesJanitor<DOMDocument> janitor(doc);
doc->getDocumentElement()->setAttributeNS(NULL,path.get(),file.get());
auto_ptr<MetadataProvider> metadataProvider(
- SAMLConfig::getConfig().MetadataProviderManager.newPlugin(FILESYSTEM_METADATA_PROVIDER,doc->getDocumentElement())
+ SAMLConfig::getConfig().MetadataProviderManager.newPlugin(XML_METADATA_PROVIDER,doc->getDocumentElement())
);
try {
metadataProvider->init();
Name="metadata"\r
>\r
<File\r
- RelativePath=".\saml2\metadata\FilesystemMetadataProviderTest.cpp"\r
+ RelativePath=".\saml2\metadata\XMLMetadataProviderTest.cpp"\r
>\r
</File>\r
</Filter>\r
Name="metadata"\r
>\r
<File\r
- RelativePath=".\saml2\metadata\FilesystemMetadataProviderTest.h"\r
+ RelativePath=".\saml2\metadata\XMLMetadataProviderTest.h"\r
>\r
<FileConfiguration\r
Name="Debug|Win32"\r
}
void testExplicitKeyTrustEngine() {
- string config = data_path + "security/FilesystemMetadataProvider.xml";
+ string config = data_path + "security/XMLMetadataProvider.xml";
ifstream in(config.c_str());
DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(in);
XercesJanitor<DOMDocument> janitor(doc);
// Build metadata provider.
auto_ptr<MetadataProvider> metadataProvider(
- SAMLConfig::getConfig().MetadataProviderManager.newPlugin(FILESYSTEM_METADATA_PROVIDER,doc->getDocumentElement())
+ SAMLConfig::getConfig().MetadataProviderManager.newPlugin(XML_METADATA_PROVIDER,doc->getDocumentElement())
);
try {
metadataProvider->init();
}
void testExplicitKeyTrustEngine() {
- string config = data_path + "security/FilesystemMetadataProvider.xml";
+ string config = data_path + "security/XMLMetadataProvider.xml";
ifstream in(config.c_str());
DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(in);
XercesJanitor<DOMDocument> janitor(doc);
// Build metadata provider.
auto_ptr<MetadataProvider> metadataProvider(
- SAMLConfig::getConfig().MetadataProviderManager.newPlugin(FILESYSTEM_METADATA_PROVIDER,doc->getDocumentElement())
+ SAMLConfig::getConfig().MetadataProviderManager.newPlugin(XML_METADATA_PROVIDER,doc->getDocumentElement())
);
try {
metadataProvider->init();