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=adcdee8dd802f6809bb94b9a69e759969f96d184;hp=49f8c2ce2af50b1955d0a81f6dc0cbee749439cb;hb=ec8536a30d9adac2b7fc870405ee8f8482e249a6;hpb=d4c3a64c4a416dd664ef28fa4437de1d5c7851f4 diff --git a/saml/saml2/metadata/impl/XMLMetadataProvider.cpp b/saml/saml2/metadata/impl/XMLMetadataProvider.cpp index 49f8c2c..adcdee8 100644 --- a/saml/saml2/metadata/impl/XMLMetadataProvider.cpp +++ b/saml/saml2/metadata/impl/XMLMetadataProvider.cpp @@ -1,6 +1,6 @@ /* - * Copyright 2001-2006 Internet2 - * + * 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,21 +16,21 @@ /** * XMLMetadataProvider.cpp - * + * * Supplies metadata from an XML file */ #include "internal.h" #include "saml2/metadata/Metadata.h" +#include "saml2/metadata/MetadataFilter.h" #include "saml2/metadata/AbstractMetadataProvider.h" -#include #include #include using namespace opensaml::saml2md; +using namespace xmltooling::logging; using namespace xmltooling; -using namespace log4cpp; using namespace std; #if defined (_MSC_VER) @@ -41,10 +41,17 @@ using namespace std; 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), m_object(NULL) {} + 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)); + } virtual ~XMLMetadataProvider() { delete m_object; } @@ -52,7 +59,7 @@ namespace opensaml { void init() { load(); // guarantees an exception or the metadata is loaded } - + const XMLObject* getMetadata() const { return m_object; } @@ -60,16 +67,13 @@ namespace opensaml { protected: pair load(); - bool isValid() const { - const TimeBoundSAMLObject* bound=dynamic_cast(m_object); - return bound ? bound->isValid() : false; - } - private: + using AbstractMetadataProvider::index; void index(); - + XMLObject* m_object; - }; + bool m_requireValidUntil; + }; MetadataProvider* SAML_DLLLOCAL XMLMetadataProviderFactory(const DOMElement* const & e) { @@ -87,10 +91,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(); @@ -99,12 +103,18 @@ pair XMLMetadataProvider::load() throw MetadataException( "Root of metadata instance not recognized: $1", params(1,xmlObject->getElementQName().toString().c_str()) ); - + + if (m_requireValidUntil) { + const TimeBoundSAMLObject* tbo = dynamic_cast(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(); xmlObject->setDocument(NULL); - + // Swap it in. bool changed = m_object!=NULL; delete m_object;