From: Scott Cantor Date: Fri, 5 Jan 2007 04:56:26 +0000 (+0000) Subject: New base class for XMLAAP. X-Git-Tag: 2.0-alpha1~170 X-Git-Url: http://www.project-moonshot.org/gitweb/?a=commitdiff_plain;h=83ebba71b8fab2a1b2c3a8eda01f55d5875cdb18;p=shibboleth%2Fcpp-sp.git New base class for XMLAAP. --- diff --git a/shib-target/shib-target.cpp b/shib-target/shib-target.cpp index b2f3482..33accb9 100644 --- a/shib-target/shib-target.cpp +++ b/shib-target/shib-target.cpp @@ -598,7 +598,7 @@ pair ShibTarget::doExportAssertions(bool requireSession) // Export NameID? while (provs.hasNext()) { IAAP* aap=provs.next(); - Locker locker(aap); + xmltooling::Locker locker(aap); const XMLCh* format = sub.second->getNameIdentifier()->getFormat(); const IAttributeRule* rule=aap->lookup(format ? format : SAMLNameIdentifier::UNSPECIFIED); if (rule && rule->getHeader()) { @@ -631,7 +631,7 @@ pair ShibTarget::doExportAssertions(bool requireSession) provs.reset(); while (provs.hasNext()) { IAAP* aap=provs.next(); - Locker locker(aap); + xmltooling::Locker locker(aap); const IAttributeRule* rule=aap->lookup(attr->getName(),attr->getNamespace()); if (!rule || !rule->getHeader()) continue; @@ -977,7 +977,7 @@ void ShibTargetPriv::clearHeaders(ShibTarget* st) Iterator provs=m_app->getAAPProviders(); while (provs.hasNext()) { IAAP* aap=provs.next(); - Locker locker(aap); + xmltooling::Locker locker(aap); Iterator rules=aap->getAttributeRules(); while (rules.hasNext()) { const char* header=rules.next()->getHeader(); diff --git a/shib/Metadata.cpp b/shib/Metadata.cpp index a87e782..0f39041 100644 --- a/shib/Metadata.cpp +++ b/shib/Metadata.cpp @@ -110,7 +110,7 @@ void AAP::apply(const saml::Iterator& aaps, saml::SAMLAssertion& assertio aaps.reset(); while (aaps.hasNext()) { IAAP* p=aaps.next(); - Locker locker(p); + xmltooling::Locker locker(p); if (p->anyAttribute()) { log.info("any attribute enabled, accepting entire assertion"); return; @@ -135,7 +135,7 @@ void AAP::apply(const saml::Iterator& aaps, saml::SAMLAssertion& assertio aaps.reset(); while (aaps.hasNext()) { IAAP* i=aaps.next(); - Locker locker(i); + xmltooling::Locker locker(i); if (rule=i->lookup(a->getName(),a->getNamespace())) { ruleFound=true; try { diff --git a/shib/shib.h b/shib/shib.h index d07f4f8..44c6e96 100644 --- a/shib/shib.h +++ b/shib/shib.h @@ -65,7 +65,7 @@ namespace shibboleth virtual ~IAttributeRule() {} }; - struct SHIB_EXPORTS IAAP : public virtual saml::ILockable, public virtual saml::IPlugIn + struct SHIB_EXPORTS IAAP : public virtual xmltooling::Lockable, public virtual saml::IPlugIn { virtual bool anyAttribute() const=0; virtual const IAttributeRule* lookup(const XMLCh* attrName, const XMLCh* attrNamespace=NULL) const=0; diff --git a/xmlproviders/Makefile.am b/xmlproviders/Makefile.am index b476b14..e173f74 100644 --- a/xmlproviders/Makefile.am +++ b/xmlproviders/Makefile.am @@ -13,7 +13,6 @@ xmlproviders_la_LIBADD = \ xmlproviders_la_SOURCES = \ TargetedID.cpp \ - XML.cpp \ XMLAAP.cpp \ XMLAccessControl.cpp \ XMLCredentials.cpp \ diff --git a/xmlproviders/XML.cpp b/xmlproviders/XML.cpp deleted file mode 100644 index bf2284f..0000000 --- a/xmlproviders/XML.cpp +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Copyright 2001-2005 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. - */ - -/* XML.cpp - XML constants - - Scott Cantor - 6/4/02 - - $History:$ -*/ - -#include "internal.h" - -// Namespace and schema string literals - -const XMLCh XML::SHIB_NS[] = // urn:mace:shibboleth:1.0 -{ chLatin_u, chLatin_r, chLatin_n, chColon, chLatin_m, chLatin_a, chLatin_c, chLatin_e, chColon, - chLatin_s, chLatin_h, chLatin_i, chLatin_b, chLatin_b, chLatin_o, chLatin_l, chLatin_e, chLatin_t, chLatin_h, chColon, - chDigit_1, chPeriod, chDigit_0, chNull -}; - -const XMLCh XML::SHIB_SCHEMA_ID[] = // shibboleth.xsd -{ chLatin_s, chLatin_h, chLatin_i, chLatin_b, chLatin_b, chLatin_o, chLatin_l, chLatin_e, chLatin_t, chLatin_h, - chPeriod, chLatin_x, chLatin_s, chLatin_d, chNull -}; - -// Shibboleth vocabulary literals - -const XMLCh XML::Literals::Accept[]= -{ chLatin_A, chLatin_c, chLatin_c, chLatin_e, chLatin_p, chLatin_t, chNull }; - -const XMLCh XML::Literals::Alias[]= -{ chLatin_A, chLatin_l, chLatin_i, chLatin_a, chLatin_s, chNull }; - -const XMLCh XML::Literals::AnyAttribute[] = -{ chLatin_A, chLatin_n, chLatin_y, - chLatin_A, chLatin_t, chLatin_t, chLatin_r, chLatin_i, chLatin_b, chLatin_u, chLatin_t, chLatin_e, chNull -}; - -const XMLCh XML::Literals::AnySite[]= -{ chLatin_A, chLatin_n, chLatin_y, chLatin_S, chLatin_i, chLatin_t, chLatin_e, chNull }; - -const XMLCh XML::Literals::AnyValue[]= -{ chLatin_A, chLatin_n, chLatin_y, chLatin_V, chLatin_a, chLatin_l, chLatin_u, chLatin_e, chNull }; - -const XMLCh XML::Literals::AttributeAcceptancePolicy[] = -{ chLatin_A, chLatin_t, chLatin_t, chLatin_r, chLatin_i, chLatin_b, chLatin_u, chLatin_t, chLatin_e, - chLatin_A, chLatin_c, chLatin_c, chLatin_e, chLatin_p, chLatin_t, chLatin_a, chLatin_n, chLatin_c, chLatin_e, - chLatin_P, chLatin_o, chLatin_l, chLatin_i, chLatin_c, chLatin_y, chNull -}; - -const XMLCh XML::Literals::AttributeRule[] = -{ chLatin_A, chLatin_t, chLatin_t, chLatin_r, chLatin_i, chLatin_b, chLatin_u, chLatin_t, chLatin_e, - chLatin_R, chLatin_u, chLatin_l, chLatin_e, chNull -}; - -const XMLCh XML::Literals::CaseSensitive[] = -{ chLatin_C, chLatin_a, chLatin_s, chLatin_e, - chLatin_S, chLatin_e, chLatin_n, chLatin_s, chLatin_i, chLatin_t, chLatin_i, chLatin_v, chLatin_e, chNull -}; - -const XMLCh XML::Literals::Factory[]= -{ chLatin_F, chLatin_a, chLatin_c, chLatin_t, chLatin_o, chLatin_r, chLatin_y, chNull }; - -const XMLCh XML::Literals::Header[]= -{ chLatin_H, chLatin_e, chLatin_a, chLatin_d, chLatin_e, chLatin_r, chNull }; - -const XMLCh XML::Literals::Name[]= -{ chLatin_N, chLatin_a, chLatin_m, chLatin_e, chNull }; - -const XMLCh XML::Literals::Namespace[]= -{ chLatin_N, chLatin_a, chLatin_m, chLatin_e, chLatin_s, chLatin_p, chLatin_a, chLatin_c, chLatin_e, chNull }; - -const XMLCh XML::Literals::Scope[] = { chLatin_S, chLatin_c, chLatin_o, chLatin_p, chLatin_e, chNull }; - -const XMLCh XML::Literals::Scoped[] = { chLatin_S, chLatin_c, chLatin_o, chLatin_p, chLatin_e, chLatin_d, chNull }; - -const XMLCh XML::Literals::SiteRule[] = -{ chLatin_S, chLatin_i, chLatin_t, chLatin_e, chLatin_R, chLatin_u, chLatin_l, chLatin_e, chNull }; - -const XMLCh XML::Literals::Type[]= -{ chLatin_T, chLatin_y, chLatin_p, chLatin_e, chNull }; - -const XMLCh XML::Literals::Value[] = -{ chLatin_V, chLatin_a, chLatin_l, chLatin_u, chLatin_e, chNull }; - -const XMLCh XML::Literals::literal[] = -{ chLatin_l, chLatin_i, chLatin_t, chLatin_e, chLatin_r, chLatin_a, chLatin_l, chNull }; - -const XMLCh XML::Literals::regexp[] = -{ chLatin_r, chLatin_e, chLatin_g, chLatin_e, chLatin_x, chLatin_p, chNull }; - -const XMLCh XML::Literals::xpath[] = -{ chLatin_x, chLatin_p, chLatin_a, chLatin_t, chLatin_h, chNull }; diff --git a/xmlproviders/XMLAAP.cpp b/xmlproviders/XMLAAP.cpp index 342abf1..4fc18f5 100644 --- a/xmlproviders/XMLAAP.cpp +++ b/xmlproviders/XMLAAP.cpp @@ -27,6 +27,8 @@ #include #include #include +#include +#include using namespace shibsp; using namespace shibboleth; @@ -40,14 +42,16 @@ using namespace std; namespace { - class XMLAAPImpl : public ReloadableXMLFileImpl + class XMLAAPImpl { public: - XMLAAPImpl(const char* pathname) : ReloadableXMLFileImpl(pathname), anyAttribute(false) { init(); } - XMLAAPImpl(const DOMElement* e) : ReloadableXMLFileImpl(e), anyAttribute(false) { init(); } - void init(); + XMLAAPImpl(const DOMElement* e); ~XMLAAPImpl(); - + + void setDocument(DOMDocument* doc) { + m_document = doc; + } + class AttributeRule : public IAttributeRule { public: @@ -98,6 +102,7 @@ namespace { sitemap_t m_siteMap; }; + DOMDocument* m_document; bool anyAttribute; vector m_attrs; map m_aliasMap; @@ -109,82 +114,109 @@ namespace { attrmap_t m_attrMap; }; - class XMLAAP : public IAAP, public ReloadableXMLFile +#if defined (_MSC_VER) + #pragma warning( push ) + #pragma warning( disable : 4250 ) +#endif + + class XMLAAP : public IAAP, public xmltooling::ReloadableXMLFile { public: - XMLAAP(const DOMElement* e) : ReloadableXMLFile(e) {} - ~XMLAAP() {} + XMLAAP(const DOMElement* e) : xmltooling::ReloadableXMLFile(e), m_impl(NULL) {} + ~XMLAAP() { + delete m_impl; + } - bool anyAttribute() const {return static_cast(getImplementation())->anyAttribute;} + bool anyAttribute() const {return m_impl->anyAttribute;} const IAttributeRule* lookup(const XMLCh* attrName, const XMLCh* attrNamespace=NULL) const; const IAttributeRule* lookup(const char* alias) const; Iterator getAttributeRules() const; protected: - virtual ReloadableXMLFileImpl* newImplementation(const char* pathname, bool first=true) const; - virtual ReloadableXMLFileImpl* newImplementation(const DOMElement* e, bool first=true) const; + pair load(); + XMLAAPImpl* m_impl; }; +#if defined (_MSC_VER) + #pragma warning( pop ) +#endif + + static const XMLCh Accept[]= UNICODE_LITERAL_6(A,c,c,e,p,t); + static const XMLCh Alias[]= UNICODE_LITERAL_5(A,l,i,a,s); + static const XMLCh AnyAttribute[]= UNICODE_LITERAL_12(A,n,y,A,t,t,r,i,b,u,t,e); + static const XMLCh AnySite[]= UNICODE_LITERAL_7(A,n,y,S,i,t,e); + static const XMLCh AnyValue[]= UNICODE_LITERAL_8(A,n,y,V,a,l,u,e); + static const XMLCh _AttributeRule[]=UNICODE_LITERAL_13(A,t,t,r,i,b,u,t,e,R,u,l,e); + static const XMLCh CaseSensitive[]= UNICODE_LITERAL_13(C,a,s,e,S,e,n,s,i,t,i,v,e); + static const XMLCh Header[]= UNICODE_LITERAL_6(H,e,a,d,e,r); + static const XMLCh Name[]= UNICODE_LITERAL_4(N,a,m,e); + static const XMLCh Namespace[]= UNICODE_LITERAL_9(N,a,m,e,s,p,a,c,e); + static const XMLCh Scoped[]= UNICODE_LITERAL_6(S,c,o,p,e,d); + static const XMLCh _SiteRule[]= UNICODE_LITERAL_8(S,i,t,e,R,u,l,e); + static const XMLCh Type[]= UNICODE_LITERAL_4(T,y,p,e); + static const XMLCh Value[]= UNICODE_LITERAL_5(V,a,l,u,e); + + static const XMLCh _literal[]= UNICODE_LITERAL_7(l,i,t,e,r,a,l); + static const XMLCh _regexp[]= UNICODE_LITERAL_6(r,e,g,e,x,p); + static const XMLCh _xpath[]= UNICODE_LITERAL_5(x,p,a,t,h); } IPlugIn* XMLAAPFactory(const DOMElement* e) { - auto_ptr aap(new XMLAAP(e)); - aap->getImplementation(); - return aap.release(); + return new XMLAAP(e); } -ReloadableXMLFileImpl* XMLAAP::newImplementation(const DOMElement* e, bool first) const +pair XMLAAP::load() { - return new XMLAAPImpl(e); -} + // Load from source using base class. + pair raw = xmltooling::ReloadableXMLFile::load(); + + // If we own it, wrap it. + XercesJanitor docjanitor(raw.first ? raw.second->getOwnerDocument() : NULL); -ReloadableXMLFileImpl* XMLAAP::newImplementation(const char* pathname, bool first) const -{ - return new XMLAAPImpl(pathname); + XMLAAPImpl* impl = new XMLAAPImpl(raw.second); + + // If we held the document, transfer it to the impl. If we didn't, it's a no-op. + impl->setDocument(docjanitor.release()); + + delete m_impl; + m_impl = impl; + + return make_pair(false,(DOMElement*)NULL); } -void XMLAAPImpl::init() +XMLAAPImpl::XMLAAPImpl(const DOMElement* e) : anyAttribute(false), m_document(NULL) { #ifdef _DEBUG - xmltooling::NDC ndc("init"); + xmltooling::NDC ndc("XMLAAPImpl"); #endif Category& log=Category::getInstance(XMLPROVIDERS_LOGCAT".AAP"); - try - { - if (!saml::XML::isElementNamed(m_root,::XML::SHIB_NS,SHIB_L(AttributeAcceptancePolicy))) - { - log.error("Construction requires a valid AAP file: (shib:AttributeAcceptancePolicy as root element)"); - throw MalformedException("Construction requires a valid AAP file: (shib:AttributeAcceptancePolicy as root element)"); - } - + try { // Check for AnyAttribute element. - DOMElement* anyAttr = saml::XML::getFirstChildElement(m_root,::XML::SHIB_NS,SHIB_L(AnyAttribute)); - if (anyAttr) { + if (XMLHelper::getFirstChildElement(e,AnyAttribute)) { anyAttribute = true; log.warn(" found, will short-circuit all attribute value and scope filtering"); } // Loop over the AttributeRule elements. - DOMNodeList* nlist = m_root->getElementsByTagNameNS(::XML::SHIB_NS,SHIB_L(AttributeRule)); - for (XMLSize_t i=0; nlist && igetLength(); i++) - { - AttributeRule* rule=new AttributeRule(static_cast(nlist->item(i))); + e = XMLHelper::getFirstChildElement(e, _AttributeRule); + while (e) { + AttributeRule* rule=new AttributeRule(e); #ifdef HAVE_GOOD_STL xmltooling::xstring key=rule->getName(); key=key + chBang + chBang + (rule->getNamespace() ? rule->getNamespace() : shibspconstants::SHIB1_ATTRIBUTE_NAMESPACE_URI); #else - auto_ptr_char aname(rule->getName()); + xmltooling::auto_ptr_char aname(rule->getName()); string key(aname.get()); key+="!!"; - if (rule->getNamespace()) - { - auto_ptr_char ans(rule->getNamespace()); + if (rule->getNamespace()) { + xmltooling::auto_ptr_char ans(rule->getNamespace()); key+=ans.get(); } - else + else { key+="urn:mace:shibboleth:1.0:attributeNamespace:uri"; + } #endif m_attrMap[key]=rule; m_attrs.push_back(rule); @@ -193,29 +225,26 @@ void XMLAAPImpl::init() if (!strcmp(rule->getAlias(),"user")) { if (strcmp(rule->getHeader(),"REMOTE_USER")) log.error(" cannot specify Alias of 'user', please use alternate value"); - else + else { m_aliasMap[rule->getAlias()]=rule; + } } else { m_aliasMap[rule->getAlias()]=rule; } } + + e = XMLHelper::getNextSiblingElement(e, _AttributeRule); } } - catch (SAMLException& e) - { - log.errorStream() << "Error while parsing AAP: " << e.what() << CategoryStream::ENDLINE; - this->~XMLAAPImpl(); - throw; - } -#ifndef _DEBUG - catch (...) - { - log.error("Unexpected error while parsing AAP"); - this->~XMLAAPImpl(); + catch (exception&) { +#ifdef HAVE_GOOD_STL + for_each(m_attrMap.begin(),m_attrMap.end(),xmltooling::cleanup_pair()); +#else + for_each(m_attrMap.begin(),m_attrMap.end(),xmltooling::cleanup_pair()); +#endif throw; } -#endif } XMLAAPImpl::~XMLAAPImpl() @@ -225,137 +254,132 @@ XMLAAPImpl::~XMLAAPImpl() #else for_each(m_attrMap.begin(),m_attrMap.end(),xmltooling::cleanup_pair()); #endif + if (m_document) + m_document->release(); } XMLAAPImpl::AttributeRule::AttributeRule(const DOMElement* e) : - m_alias(e->hasAttributeNS(NULL,SHIB_L(Alias)) ? e->getAttributeNS(NULL,SHIB_L(Alias)) : NULL), - m_header(e->hasAttributeNS(NULL,SHIB_L(Header)) ? e->getAttributeNS(NULL,SHIB_L(Header)) : NULL), + m_alias(e->hasAttributeNS(NULL,Alias) ? e->getAttributeNS(NULL,Alias) : NULL), + m_header(e->hasAttributeNS(NULL,Header) ? e->getAttributeNS(NULL,Header) : NULL), m_scoped(false) { - m_name=e->getAttributeNS(NULL,SHIB_L(Name)); - m_namespace=e->getAttributeNS(NULL,SHIB_L(Namespace)); + m_name=e->getAttributeNS(NULL,Name); + m_namespace=e->getAttributeNS(NULL,Namespace); if (!m_namespace || !*m_namespace) m_namespace=shibspconstants::SHIB1_ATTRIBUTE_NAMESPACE_URI; - const XMLCh* caseSensitive=e->getAttributeNS(NULL,SHIB_L(CaseSensitive)); + const XMLCh* caseSensitive=e->getAttributeNS(NULL,CaseSensitive); m_caseSensitive=(!caseSensitive || !*caseSensitive || *caseSensitive==chDigit_1 || *caseSensitive==chLatin_t); - const XMLCh* scoped=e->getAttributeNS(NULL,SHIB_L(Scoped)); + const XMLCh* scoped=e->getAttributeNS(NULL,Scoped); m_scoped=(scoped && (*scoped==chDigit_1 || *scoped==chLatin_t)); // Check for an AnySite rule. - DOMElement* anysite = saml::XML::getFirstChildElement(e); - if (anysite && saml::XML::isElementNamed(static_cast(anysite),::XML::SHIB_NS,SHIB_L(AnySite))) - { + const DOMElement* anysite = XMLHelper::getFirstChildElement(e); + if (anysite && XMLString::equals(anysite->getLocalName(),AnySite)) { // Process Scope elements. - DOMNodeList* vlist = static_cast(anysite)->getElementsByTagNameNS(::XML::SHIB_NS,SHIB_L(Scope)); - for (XMLSize_t i=0; vlist && igetLength(); i++) - { + const DOMElement* se = XMLHelper::getFirstChildElement(anysite,Scope::LOCAL_NAME); + while (se) { m_scoped=true; - DOMElement* se=static_cast(vlist->item(i)); DOMNode* valnode=se->getFirstChild(); - if (valnode && valnode->getNodeType()==DOMNode::TEXT_NODE) - { - const XMLCh* accept=se->getAttributeNS(NULL,SHIB_L(Accept)); + if (valnode && valnode->getNodeType()==DOMNode::TEXT_NODE) { + const XMLCh* accept=se->getAttributeNS(NULL,Accept); if (!accept || !*accept || *accept==chDigit_1 || *accept==chLatin_t) m_anySiteRule.scopeAccepts.push_back(pair(toValueType(se),valnode->getNodeValue())); else m_anySiteRule.scopeDenials.push_back(pair(toValueType(se),valnode->getNodeValue())); } + + se = XMLHelper::getNextSiblingElement(se,Scope::LOCAL_NAME); } // Check for an AnyValue rule. - vlist = static_cast(anysite)->getElementsByTagNameNS(::XML::SHIB_NS,SHIB_L(AnyValue)); - if (vlist && vlist->getLength()) - { + if (XMLHelper::getFirstChildElement(anysite,AnyValue)) { m_anySiteRule.anyValue=true; } - else - { + else { // Process each Value element. - vlist = static_cast(anysite)->getElementsByTagNameNS(::XML::SHIB_NS,SHIB_L(Value)); - for (XMLSize_t j=0; vlist && jgetLength(); j++) - { - DOMElement* ve=static_cast(vlist->item(j)); + const DOMElement* ve = XMLHelper::getFirstChildElement(anysite,Value); + while (ve) { DOMNode* valnode=ve->getFirstChild(); if (valnode && valnode->getNodeType()==DOMNode::TEXT_NODE) { - const XMLCh* accept=ve->getAttributeNS(NULL,SHIB_L(Accept)); + const XMLCh* accept=ve->getAttributeNS(NULL,Accept); if (!accept || !*accept || *accept==chDigit_1 || *accept==chLatin_t) m_anySiteRule.valueAccepts.push_back(pair(toValueType(ve),valnode->getNodeValue())); else m_anySiteRule.valueDenials.push_back(pair(toValueType(ve),valnode->getNodeValue())); } + + ve = XMLHelper::getNextSiblingElement(ve,Value); } } } // Loop over the SiteRule elements. - DOMNodeList* slist = e->getElementsByTagNameNS(::XML::SHIB_NS,SHIB_L(SiteRule)); - for (XMLSize_t k=0; slist && kgetLength(); k++) - { - const XMLCh* srulename=static_cast(slist->item(k))->getAttributeNS(NULL,SHIB_L(Name)); + const DOMElement* sr = XMLHelper::getFirstChildElement(e,_SiteRule); + while (sr) { + const XMLCh* srulename=sr->getAttributeNS(NULL,Name); #ifdef HAVE_GOOD_STL m_siteMap[srulename]=SiteRule(); SiteRule& srule=m_siteMap[srulename]; #else - auto_ptr_char srulename2(srulename); + xmltooling::auto_ptr_char srulename2(srulename); m_siteMap[srulename2.get()]=SiteRule(); SiteRule& srule=m_siteMap[srulename2.get()]; #endif // Process Scope elements. - DOMNodeList* vlist = static_cast(slist->item(k))->getElementsByTagNameNS(::XML::SHIB_NS,SHIB_L(Scope)); - for (XMLSize_t i=0; vlist && igetLength(); i++) - { + const DOMElement* se = XMLHelper::getFirstChildElement(sr,Scope::LOCAL_NAME); + while (se) { m_scoped=true; - DOMElement* se=static_cast(vlist->item(i)); DOMNode* valnode=se->getFirstChild(); - if (valnode && valnode->getNodeType()==DOMNode::TEXT_NODE) - { - const XMLCh* accept=se->getAttributeNS(NULL,SHIB_L(Accept)); + if (valnode && valnode->getNodeType()==DOMNode::TEXT_NODE) { + const XMLCh* accept=se->getAttributeNS(NULL,Accept); if (!accept || !*accept || *accept==chDigit_1 || *accept==chLatin_t) srule.scopeAccepts.push_back(pair(toValueType(se),valnode->getNodeValue())); else srule.scopeDenials.push_back(pair(toValueType(se),valnode->getNodeValue())); } + + se = XMLHelper::getNextSiblingElement(se,Scope::LOCAL_NAME); } // Check for an AnyValue rule. - vlist = static_cast(slist->item(k))->getElementsByTagNameNS(::XML::SHIB_NS,SHIB_L(AnyValue)); - if (vlist && vlist->getLength()) - { + if (XMLHelper::getFirstChildElement(sr,AnyValue)) { srule.anyValue=true; } else { // Process each Value element. - vlist = static_cast(slist->item(k))->getElementsByTagNameNS(::XML::SHIB_NS,SHIB_L(Value)); - for (XMLSize_t j=0; vlist && jgetLength(); j++) - { - DOMElement* ve=static_cast(vlist->item(j)); + const DOMElement* ve = XMLHelper::getFirstChildElement(sr,Value); + while (ve) { DOMNode* valnode=ve->getFirstChild(); if (valnode && valnode->getNodeType()==DOMNode::TEXT_NODE) { - const XMLCh* accept=ve->getAttributeNS(NULL,SHIB_L(Accept)); + const XMLCh* accept=ve->getAttributeNS(NULL,Accept); if (!accept || !*accept || *accept==chDigit_1 || *accept==chLatin_t) srule.valueAccepts.push_back(pair(toValueType(ve),valnode->getNodeValue())); else srule.valueDenials.push_back(pair(toValueType(ve),valnode->getNodeValue())); } + + ve = XMLHelper::getNextSiblingElement(ve,Value); } } + + sr = XMLHelper::getNextSiblingElement(sr,_SiteRule); } } XMLAAPImpl::AttributeRule::value_type XMLAAPImpl::AttributeRule::toValueType(const DOMElement* e) { - if (!XMLString::compareString(SHIB_L(literal),e->getAttributeNS(NULL,SHIB_L(Type)))) + if (XMLString::equals(_literal,e->getAttributeNS(NULL,Type))) return literal; - else if (!XMLString::compareString(SHIB_L(regexp),e->getAttributeNS(NULL,SHIB_L(Type)))) + else if (XMLString::equals(_regexp,e->getAttributeNS(NULL,Type))) return regexp; - else if (!XMLString::compareString(SHIB_L(xpath),e->getAttributeNS(NULL,SHIB_L(Type)))) + else if (XMLString::equals(_xpath,e->getAttributeNS(NULL,Type))) return xpath; - throw MalformedException("Found an invalid value or scope rule type."); + throw ConfigurationException("Found an invalid value or scope rule type."); } const IAttributeRule* XMLAAP::lookup(const XMLCh* attrName, const XMLCh* attrNamespace) const @@ -364,32 +388,30 @@ const IAttributeRule* XMLAAP::lookup(const XMLCh* attrName, const XMLCh* attrNam xmltooling::xstring key=attrName; key=key + chBang + chBang + (attrNamespace ? attrNamespace : shibspconstants::SHIB1_ATTRIBUTE_NAMESPACE_URI); #else - auto_ptr_char aname(attrName); + xmltooling::auto_ptr_char aname(attrName); string key=aname.get(); key+="!!"; - if (attrNamespace) - { - auto_ptr_char ans(attrNamespace); + if (attrNamespace) { + xmltooling::auto_ptr_char ans(attrNamespace); key+=ans.get(); } - else + else { key+="urn:mace:shibboleth:1.0:attributeNamespace:uri"; + } #endif - XMLAAPImpl* impl=dynamic_cast(getImplementation()); - XMLAAPImpl::attrmap_t::const_iterator i=impl->m_attrMap.find(key); - return (i==impl->m_attrMap.end()) ? NULL : i->second; + XMLAAPImpl::attrmap_t::const_iterator i=m_impl->m_attrMap.find(key); + return (i==m_impl->m_attrMap.end()) ? NULL : i->second; } const IAttributeRule* XMLAAP::lookup(const char* alias) const { - XMLAAPImpl* impl=dynamic_cast(getImplementation()); - map::const_iterator i=impl->m_aliasMap.find(alias); - return (i==impl->m_aliasMap.end()) ? NULL : i->second; + map::const_iterator i=m_impl->m_aliasMap.find(alias); + return (i==m_impl->m_aliasMap.end()) ? NULL : i->second; } Iterator XMLAAP::getAttributeRules() const { - return dynamic_cast(getImplementation())->m_attrs; + return m_impl->m_attrs; } namespace { @@ -402,7 +424,7 @@ namespace { } catch (XMLException& ex) { xmltooling::auto_ptr_char tmp(ex.getMessage()); - Category::getInstance(XMLPROVIDERS_LOGCAT".XMLAAPImpl").errorStream() + Category::getInstance(XMLPROVIDERS_LOGCAT".AAP").errorStream() << "caught exception while parsing regular expression: " << tmp.get() << CategoryStream::ENDLINE; } return false; @@ -421,7 +443,7 @@ bool XMLAAPImpl::AttributeRule::scopeCheck( Category& log=Category::getInstance(XMLPROVIDERS_LOGCAT".AAP"); // Are we scoped? - const XMLCh* scope=e->getAttributeNS(NULL,SHIB_L(Scope)); + const XMLCh* scope=e->getAttributeNS(NULL,Scope::LOCAL_NAME); if (!scope || !*scope) { // Are we allowed to be unscoped? if (m_scoped && log.isWarnEnabled()) { @@ -437,7 +459,7 @@ bool XMLAAPImpl::AttributeRule::scopeCheck( // Now run any denials. vector >::const_iterator i; for (i=(*rule)->scopeDenials.begin(); i!=(*rule)->scopeDenials.end(); i++) { - if ((i->first==literal && !XMLString::compareString(i->second,scope)) || + if ((i->first==literal && XMLString::equals(i->second,scope)) || (i->first==regexp && match(i->second,scope))) { if (log.isWarnEnabled()) { xmltooling::auto_ptr_char temp(m_name); @@ -452,7 +474,7 @@ bool XMLAAPImpl::AttributeRule::scopeCheck( // Now run any accepts. for (i=(*rule)->scopeAccepts.begin(); i!=(*rule)->scopeAccepts.end(); i++) { - if ((i->first==literal && !XMLString::compareString(i->second,scope)) || + if ((i->first==literal && XMLString::equals(i->second,scope)) || (i->first==regexp && match(i->second,scope))) { log.debug("matching site rule, scope match"); return true; diff --git a/xmlproviders/XMLProviders.cpp b/xmlproviders/XMLProviders.cpp index 8ddbea5..99551f8 100644 --- a/xmlproviders/XMLProviders.cpp +++ b/xmlproviders/XMLProviders.cpp @@ -31,11 +31,9 @@ #include "internal.h" #include #include -#include using namespace saml; using namespace shibboleth; -using namespace log4cpp; using namespace std; // Metadata Factories @@ -47,9 +45,6 @@ PlugManager::Factory XMLAccessControlFactory; extern "C" int XML_EXPORTS saml_extension_init(void*) { - // Register extension schemas. - saml::XML::registerSchema(::XML::SHIB_NS,::XML::SHIB_SCHEMA_ID); - // Register metadata factories (some are legacy aliases) SAMLConfig& conf=SAMLConfig::getConfig(); conf.getPlugMgr().regFactory("edu.internet2.middleware.shibboleth.common.provider.TargetedIDFactory",&TargetedIDFactory); diff --git a/xmlproviders/internal.h b/xmlproviders/internal.h index 9452348..540a4f4 100644 --- a/xmlproviders/internal.h +++ b/xmlproviders/internal.h @@ -43,41 +43,4 @@ #define XMLPROVIDERS_LOGCAT "XMLProviders" -#define SHIB_L(s) ::XML::Literals::s -#define SHIB_L_QNAME(p,s) ::XML::Literals::p##_##s - -class XML -{ -public: - // URI constants - static const XMLCh SHIB_NS[]; - static const XMLCh SHIB_SCHEMA_ID[]; - - struct Literals - { - // SAML attribute constants - static const XMLCh Accept[]; - static const XMLCh Alias[]; - static const XMLCh AnyAttribute[]; - static const XMLCh AnySite[]; - static const XMLCh AnyValue[]; - static const XMLCh AttributeAcceptancePolicy[]; - static const XMLCh AttributeRule[]; - static const XMLCh CaseSensitive[]; - static const XMLCh Factory[]; - static const XMLCh Header[]; - static const XMLCh Name[]; - static const XMLCh Namespace[]; - static const XMLCh Scope[]; - static const XMLCh Scoped[]; - static const XMLCh SiteRule[]; - static const XMLCh Type[]; - static const XMLCh Value[]; - - static const XMLCh literal[]; - static const XMLCh regexp[]; - static const XMLCh xpath[]; - }; -}; - #endif diff --git a/xmlproviders/xmlproviders.vcproj b/xmlproviders/xmlproviders.vcproj index cf8b2d8..dcdd8b2 100644 --- a/xmlproviders/xmlproviders.vcproj +++ b/xmlproviders/xmlproviders.vcproj @@ -228,10 +228,6 @@ > - -