2 * Licensed to the University Corporation for Advanced Internet
3 * Development, Inc. (UCAID) under one or more contributor license
4 * agreements. See the NOTICE file distributed with this work for
5 * additional information regarding copyright ownership.
7 * UCAID licenses this file to you under the Apache License,
8 * Version 2.0 (the "License"); you may not use this file except
9 * in compliance with the License. You may obtain a copy of the
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
17 * either express or implied. See the License for the specific
18 * language governing permissions and limitations under the License.
22 * NameEntityMatcher.cpp
24 * EntityMatcher that matches based on name.
28 #include "saml2/metadata/EntityMatcher.h"
29 #include "saml2/metadata/Metadata.h"
31 using namespace opensaml::saml2md;
32 using namespace opensaml;
33 using namespace xmltooling;
38 class SAML_DLLLOCAL NameEntityMatcher : public EntityMatcher
41 NameEntityMatcher(const DOMElement* e)
42 : m_name(e ? e->getAttributeNS(nullptr, EntitiesDescriptor::NAME_ATTRIB_NAME) : nullptr) {
43 if (!m_name || !*m_name)
44 throw XMLToolingException("Name EntityMatcher missing required Name attribute.");
46 ~NameEntityMatcher() {}
48 bool matches(const EntityDescriptor& entity) const;
54 EntityMatcher* SAML_DLLLOCAL NameEntityMatcherFactory(const DOMElement* const & e)
56 return new NameEntityMatcher(e);
59 SAML_DLLLOCAL PluginManager<EntityMatcher,string,const DOMElement*>::Factory EntityAttributesEntityMatcherFactory;
63 void SAML_API opensaml::saml2md::registerEntityMatchers()
65 SAMLConfig::getConfig().EntityMatcherManager.registerFactory(NAME_ENTITY_MATCHER, NameEntityMatcherFactory);
66 SAMLConfig::getConfig().EntityMatcherManager.registerFactory(ENTITYATTR_ENTITY_MATCHER, EntityAttributesEntityMatcherFactory);
69 EntityMatcher::EntityMatcher()
73 EntityMatcher::~EntityMatcher()
77 bool NameEntityMatcher::matches(const EntityDescriptor& entity) const
79 if (XMLString::equals(m_name, entity.getEntityID()))
81 const EntitiesDescriptor* group = dynamic_cast<EntitiesDescriptor*>(entity.getParent());
83 if (XMLString::equals(m_name, group->getName()))
85 group = dynamic_cast<EntitiesDescriptor*>(group->getParent());