From: Scott Cantor Date: Thu, 28 Dec 2006 18:47:07 +0000 (+0000) Subject: Finished adding new metadata/trust plugins to config. X-Git-Tag: 2.0-alpha1~183 X-Git-Url: http://www.project-moonshot.org/gitweb/?a=commitdiff_plain;h=82fd9acc995f222136c0a8ec6b3789c6603f3d97;p=shibboleth%2Fcpp-sp.git Finished adding new metadata/trust plugins to config. --- diff --git a/shib-target/shib-ini.cpp b/shib-target/shib-ini.cpp index 7d1f2bd..f6bd9c2 100644 --- a/shib-target/shib-ini.cpp +++ b/shib-target/shib-ini.cpp @@ -30,6 +30,8 @@ #include #include #include +#include +#include #include #include #include @@ -38,12 +40,11 @@ using namespace shibsp; using namespace shibtarget; using namespace shibboleth; using namespace saml; +using namespace opensaml::saml2md; using namespace xmltooling; using namespace log4cpp; using namespace std; -using opensaml::saml2md::MetadataProvider; - namespace shibtarget { // Application configuration wrapper @@ -256,6 +257,7 @@ XMLApplication::XMLApplication( SPConfig& conf=SPConfig::getConfig(); XMLToolingConfig& xmlConf=XMLToolingConfig::getConfig(); + opensaml::SAMLConfig& samlConf=opensaml::SAMLConfig::getConfig(); SAMLConfig& shibConf=SAMLConfig::getConfig(); // Process handlers. @@ -423,12 +425,14 @@ XMLApplication::XMLApplication( } if (conf.isEnabled(SPConfig::Metadata)) { + vector os2providers; nlist=e->getElementsByTagNameNS(shibtarget::XML::SHIBTARGET_NS,SHIBT_L(MetadataProvider)); for (i=0; nlist && igetLength(); i++) { if (nlist->item(i)->getParentNode()->isSameNode(e)) { xmltooling::auto_ptr_char type(static_cast(nlist->item(i))->getAttributeNS(NULL,SHIBT_L(type))); log.info("building metadata provider of type %s...",type.get()); try { + // Old plugins...TODO: remove IPlugIn* plugin=shibConf.getPlugMgr().newPlugin(type.get(),static_cast(nlist->item(i))); IMetadata* md=dynamic_cast(plugin); if (md) @@ -437,43 +441,59 @@ XMLApplication::XMLApplication( delete plugin; log.crit("plugin was not a metadata provider"); } + + // New plugins... + if (!strcmp(type.get(),"edu.internet2.middleware.shibboleth.common.provider.XMLMetadata") || + !strcmp(type.get(),"edu.internet2.middleware.shibboleth.metadata.provider.XMLMetadata")) { + os2providers.push_back( + samlConf.MetadataProviderManager.newPlugin( + FILESYSTEM_METADATA_PROVIDER,static_cast(nlist->item(i)) + ) + ); + } + else { + os2providers.push_back( + samlConf.MetadataProviderManager.newPlugin(type.get(),static_cast(nlist->item(i))) + ); + } + } + catch (XMLToolingException& ex) { + log.crit("error building metadata provider: %s",ex.what()); + for_each(os2providers.begin(), os2providers.end(), xmltooling::cleanup()); } catch (SAMLException& ex) { log.crit("error building metadata provider: %s",ex.what()); } } } - nlist=e->getElementsByTagNameNS(shibtarget::XML::SHIBTARGET_NS,SHIBT_L(FederationProvider)); - for (i=0; nlist && igetLength(); i++) { - if (nlist->item(i)->getParentNode()->isSameNode(e)) { - xmltooling::auto_ptr_char type(static_cast(nlist->item(i))->getAttributeNS(NULL,SHIBT_L(type))); - log.info("building metadata provider of type %s...",type.get()); - try { - IPlugIn* plugin=shibConf.getPlugMgr().newPlugin(type.get(),static_cast(nlist->item(i))); - IMetadata* md=dynamic_cast(plugin); - if (md) - m_metadatas.push_back(md); - else { - delete plugin; - log.crit("plugin was not a metadata provider"); - } - } - catch (SAMLException& ex) { - log.crit("error building metadata provider: %s",ex.what()); + + if (os2providers.size()==1) + m_metadata=os2providers.front(); + else { + try { + m_metadata = samlConf.MetadataProviderManager.newPlugin(CHAINING_METADATA_PROVIDER,NULL); + ChainingMetadataProvider* chainMeta = dynamic_cast(m_metadata); + while (!os2providers.empty()) { + chainMeta->addMetadataProvider(os2providers.back()); + os2providers.pop_back(); } } + catch (XMLToolingException& ex) { + log.crit("error building metadata provider: %s",ex.what()); + for_each(os2providers.begin(), os2providers.end(), xmltooling::cleanup()); + } } } if (conf.isEnabled(SPConfig::Trust)) { - // First build the old plugins. - // TODO: remove this later + ChainingTrustEngine* chainTrust = NULL; nlist=e->getElementsByTagNameNS(shibtarget::XML::SHIBTARGET_NS,SHIBT_L(TrustProvider)); for (i=0; nlist && igetLength(); i++) { if (nlist->item(i)->getParentNode()->isSameNode(e)) { xmltooling::auto_ptr_char type(static_cast(nlist->item(i))->getAttributeNS(NULL,SHIBT_L(type))); log.info("building trust provider of type %s...",type.get()); try { + // Old plugins...TODO: remove IPlugIn* plugin=shibConf.getPlugMgr().newPlugin(type.get(),static_cast(nlist->item(i))); ITrust* trust=dynamic_cast(plugin); if (trust) @@ -482,25 +502,11 @@ XMLApplication::XMLApplication( delete plugin; log.crit("plugin was not a trust provider"); } - } - catch (SAMLException& ex) { - log.crit("error building trust provider: %s",ex.what()); - } - } - } - - // Loop again to build the new engines. - ChainingTrustEngine* chainTrust = NULL; - for (i=0; nlist && igetLength(); i++) { - if (nlist->item(i)->getParentNode()->isSameNode(e)) { - - // For compatibility with old engine types, we're assuming a Shib engine is likely, - // which requires chaining, so we'll build that regardless. - xmltooling::auto_ptr_char type(static_cast(nlist->item(i))->getAttributeNS(NULL,SHIBT_L(type))); - log.info("building trust engine of type %s...",type.get()); - try { + // New plugins... if (!m_trust) { + // For compatibility with old engine types, we're assuming a Shib engine is likely, + // which requires chaining, so we'll build that regardless. m_trust = xmlConf.TrustEngineManager.newPlugin(CHAINING_TRUSTENGINE,NULL); chainTrust = dynamic_cast(m_trust); } @@ -532,6 +538,9 @@ XMLApplication::XMLApplication( catch (XMLToolingException& ex) { log.crit("error building trust provider: %s",ex.what()); } + catch (SAMLException& ex) { + log.crit("error building trust provider: %s",ex.what()); + } } } }