X-Git-Url: http://www.project-moonshot.org/gitweb/?p=shibboleth%2Fcpp-opensaml.git;a=blobdiff_plain;f=saml%2Fsaml2%2Fmetadata%2Fimpl%2FWhitelistMetadataFilter.cpp;h=f671edcb3857721e24d33fab28d5aa3b51535bdc;hp=76d6de3426d0310443aa8e173d7aa743fd8f9139;hb=735e90e92f411650f0d707de997591cf01bb7348;hpb=932cfaae2176c2eba1a9938dc420591a9551a7f3 diff --git a/saml/saml2/metadata/impl/WhitelistMetadataFilter.cpp b/saml/saml2/metadata/impl/WhitelistMetadataFilter.cpp index 76d6de3..f671edc 100644 --- a/saml/saml2/metadata/impl/WhitelistMetadataFilter.cpp +++ b/saml/saml2/metadata/impl/WhitelistMetadataFilter.cpp @@ -1,22 +1,26 @@ -/* - * 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 +/** + * 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. + * + * 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. */ /** * WhitelistMetadataFilter.cpp - * + * * Removes non-whitelisted entities from a metadata instance */ @@ -24,46 +28,40 @@ #include "saml2/metadata/Metadata.h" #include "saml2/metadata/MetadataFilter.h" -#include +#include +#include +#include #include using namespace opensaml::saml2md; +using namespace xmltooling::logging; using namespace xmltooling; -using namespace log4cpp; +using namespace boost; using namespace std; namespace opensaml { namespace saml2md { - + class SAML_DLLLOCAL WhitelistMetadataFilter : public MetadataFilter { public: WhitelistMetadataFilter(const DOMElement* e); ~WhitelistMetadataFilter() {} - + const char* getId() const { return WHITELIST_METADATA_FILTER; } void doFilter(XMLObject& xmlObject) const; private: void doFilter(EntitiesDescriptor& entities) const; - + bool found(const XMLCh* id) const { if (!id) return false; -#ifdef HAVE_GOOD_STL return m_set.count(id)==1; -#else - auto_ptr_char id2(id); - return m_set.count(id2.get())==1; -#endif } -#ifdef HAVE_GOOD_STL set m_set; -#else - set m_set; -#endif - }; + }; MetadataFilter* SAML_DLLLOCAL WhitelistMetadataFilterFactory(const DOMElement* const & e) { @@ -80,12 +78,7 @@ WhitelistMetadataFilter::WhitelistMetadataFilter(const DOMElement* e) e = XMLHelper::getFirstChildElement(e); while (e) { if (XMLString::equals(e->getLocalName(), Include) && e->hasChildNodes()) { -#ifdef HAVE_GOOD_STL - m_set.insert(e->getFirstChild()->getNodeValue()); -#else - auto_ptr_char id(e->getFirstChild()->getNodeValue()); - m_set.insert(id.get()); -#endif + m_set.insert(e->getFirstChild()->getTextContent()); } e = XMLHelper::getNextSiblingElement(e); } @@ -96,30 +89,30 @@ void WhitelistMetadataFilter::doFilter(XMLObject& xmlObject) const #ifdef _DEBUG NDC ndc("doFilter"); #endif - + try { doFilter(dynamic_cast(xmlObject)); return; } - catch (bad_cast) { + catch (bad_cast&) { } try { EntityDescriptor& entity = dynamic_cast(xmlObject); if (!found(entity.getEntityID())) - throw MetadataFilterException("WhitelistMetadataFilter instructed to filter the root/only entity in the metadata."); + throw MetadataFilterException(WHITELIST_METADATA_FILTER" MetadataFilter instructed to filter the root/only entity in the metadata."); return; } - catch (bad_cast) { + catch (bad_cast&) { } - - throw MetadataFilterException("WhitelistMetadataFilter was given an improper metadata instance to filter."); + + throw MetadataFilterException(WHITELIST_METADATA_FILTER" MetadataFilter was given an improper metadata instance to filter."); } void WhitelistMetadataFilter::doFilter(EntitiesDescriptor& entities) const { - Category& log=Category::getInstance(SAML_LOGCAT".Metadata"); - + Category& log=Category::getInstance(SAML_LOGCAT".MetadataFilter."WHITELIST_METADATA_FILTER); + VectorOf(EntityDescriptor) v=entities.getEntityDescriptors(); for (VectorOf(EntityDescriptor)::size_type i=0; igetEntityID(); @@ -134,6 +127,10 @@ void WhitelistMetadataFilter::doFilter(EntitiesDescriptor& entities) const } const vector& groups=const_cast(entities).getEntitiesDescriptors(); - for (vector::const_iterator j=groups.begin(); j!=groups.end(); j++) - doFilter(*(*j)); + for_each( + make_indirect_iterator(groups.begin()), make_indirect_iterator(groups.end()), + boost::bind( + static_cast(&WhitelistMetadataFilter::doFilter), this, _1 + ) + ); }