[cpp-opensaml COMMIT] /branches/REL_2/saml/saml2/metadata/impl/WhitelistMetadataFilter.cpp
noreply at shibboleth.net
noreply at shibboleth.net
Wed Feb 22 23:04:46 GMT 2012
Author: scantor
Date: Wed Feb 22 23:04:45 2012
New Revision: 709
URL: http://svn.shibboleth.net/view/cpp-opensaml?rev=709&view=rev
Log:
https://issues.shibboleth.net/jira/browse/SSPCPP-342
Modified:
branches/REL_2/saml/saml2/metadata/impl/WhitelistMetadataFilter.cpp
Modified: branches/REL_2/saml/saml2/metadata/impl/WhitelistMetadataFilter.cpp
URL: http://svn.shibboleth.net/view/cpp-opensaml/branches/REL_2/saml/saml2/metadata/impl/WhitelistMetadataFilter.cpp?rev=709&r1=708&r2=709&view=diff
==============================================================================
--- branches/REL_2/saml/saml2/metadata/impl/WhitelistMetadataFilter.cpp (original)
+++ branches/REL_2/saml/saml2/metadata/impl/WhitelistMetadataFilter.cpp Wed Feb 22 23:04:45 2012
@@ -28,20 +28,23 @@
#include "saml2/metadata/Metadata.h"
#include "saml2/metadata/MetadataFilter.h"
-#include <boost/bind.hpp>
+#include <boost/lambda/bind.hpp>
+#include <boost/lambda/casts.hpp>
+#include <boost/lambda/lambda.hpp>
+#include <boost/shared_ptr.hpp>
#include <boost/iterator/indirect_iterator.hpp>
#include <xmltooling/logging.h>
-#include <xmltooling/util/NDC.h>
-
+
+using namespace opensaml::saml2;
using namespace opensaml::saml2md;
using namespace xmltooling::logging;
using namespace xmltooling;
+using namespace boost::lambda;
using namespace boost;
using namespace std;
namespace opensaml {
namespace saml2md {
-
class SAML_DLLLOCAL WhitelistMetadataFilter : public MetadataFilter
{
public:
@@ -52,15 +55,13 @@
void doFilter(XMLObject& xmlObject) const;
private:
- void doFilter(EntitiesDescriptor& entities) const;
-
- bool found(const XMLCh* id) const {
- if (!id)
- return false;
- return m_set.count(id)==1;
- }
-
- set<xstring> m_set;
+ void filterGroup(EntitiesDescriptor&) const;
+ bool included(const EntityDescriptor&) const;
+ bool matches(const EntityAttributes*, const Attribute*) const;
+
+ set<xstring> m_entities;
+ bool m_trimTags;
+ vector< boost::shared_ptr<Attribute> > m_tags;
};
MetadataFilter* SAML_DLLLOCAL WhitelistMetadataFilterFactory(const DOMElement* const & e)
@@ -68,57 +69,55 @@
return new WhitelistMetadataFilter(e);
}
+ static const XMLCh Include[] = UNICODE_LITERAL_7(I,n,c,l,u,d,e);
+ static const XMLCh trimTags[] = UNICODE_LITERAL_8(t,r,i,m,T,a,g,s);
};
};
-static const XMLCh Include[] = UNICODE_LITERAL_7(I,n,c,l,u,d,e);
WhitelistMetadataFilter::WhitelistMetadataFilter(const DOMElement* e)
-{
- e = XMLHelper::getFirstChildElement(e);
- while (e) {
- if (XMLString::equals(e->getLocalName(), Include) && e->hasChildNodes()) {
- m_set.insert(e->getFirstChild()->getTextContent());
- }
- e = XMLHelper::getNextSiblingElement(e);
+ : m_trimTags(XMLHelper::getAttrBool(e, false, trimTags))
+{
+ DOMElement* child = XMLHelper::getFirstChildElement(e);
+ while (child) {
+ if (XMLString::equals(child->getLocalName(), Include) && child->hasChildNodes()) {
+ m_entities.insert(child->getFirstChild()->getTextContent());
+ }
+ else if (XMLHelper::isNodeNamed(child, samlconstants::SAML20_NS, Attribute::LOCAL_NAME)) {
+ boost::shared_ptr<XMLObject> obj(AttributeBuilder::buildOneFromElement(child));
+ m_tags.push_back(boost::shared_dynamic_cast<Attribute>(obj));
+ }
+ child = XMLHelper::getNextSiblingElement(child);
}
}
void WhitelistMetadataFilter::doFilter(XMLObject& xmlObject) const
{
-#ifdef _DEBUG
- NDC ndc("doFilter");
-#endif
-
- try {
- doFilter(dynamic_cast<EntitiesDescriptor&>(xmlObject));
- return;
- }
- catch (bad_cast&) {
- }
-
- try {
- EntityDescriptor& entity = dynamic_cast<EntityDescriptor&>(xmlObject);
- if (!found(entity.getEntityID()))
- throw MetadataFilterException(WHITELIST_METADATA_FILTER" MetadataFilter instructed to filter the root/only entity in the metadata.");
- return;
- }
- catch (bad_cast&) {
- }
-
- throw MetadataFilterException(WHITELIST_METADATA_FILTER" MetadataFilter was given an improper metadata instance to filter.");
-}
-
-void WhitelistMetadataFilter::doFilter(EntitiesDescriptor& entities) const
+ EntitiesDescriptor* group = dynamic_cast<EntitiesDescriptor*>(&xmlObject);
+ if (group) {
+ filterGroup(*group);
+ }
+ else {
+ EntityDescriptor* entity = dynamic_cast<EntityDescriptor*>(&xmlObject);
+ if (entity) {
+ if (!included(*entity))
+ throw MetadataFilterException(WHITELIST_METADATA_FILTER" MetadataFilter instructed to filter the root/only entity in the metadata.");
+ }
+ else {
+ throw MetadataFilterException(WHITELIST_METADATA_FILTER" MetadataFilter was given an improper metadata instance to filter.");
+ }
+ }
+}
+
[... 126 lines stripped ...]
More information about the commits
mailing list