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 * ChainingAttributeExtractor.cpp
24 * Chains together multiple AttributeExtractor plugins.
28 #include "Application.h"
29 #include "ServiceProvider.h"
30 #include "attribute/Attribute.h"
31 #include "attribute/resolver/AttributeExtractor.h"
33 #include <boost/ptr_container/ptr_vector.hpp>
34 #include <xercesc/util/XMLUniDefs.hpp>
35 #include <xmltooling/util/XMLHelper.h>
37 using namespace shibsp;
38 using namespace opensaml::saml2md;
39 using namespace xmltooling;
40 using namespace boost;
45 class SHIBSP_DLLLOCAL ChainingAttributeExtractor : public AttributeExtractor
48 ChainingAttributeExtractor(const DOMElement* e);
49 virtual ~ChainingAttributeExtractor() {}
57 void extractAttributes(
58 const Application& application,
59 const RoleDescriptor* issuer,
60 const XMLObject& xmlObject,
61 vector<Attribute*>& attributes
63 for (ptr_vector<AttributeExtractor>::iterator i = m_extractors.begin(); i != m_extractors.end(); ++i) {
65 i->extractAttributes(application, issuer, xmlObject, attributes);
69 void getAttributeIds(vector<string>& attributes) const {
70 for (ptr_vector<AttributeExtractor>::iterator i = m_extractors.begin(); i != m_extractors.end(); ++i) {
72 i->getAttributeIds(attributes);
76 void generateMetadata(SPSSODescriptor& role) const {
77 for (ptr_vector<AttributeExtractor>::iterator i = m_extractors.begin(); i != m_extractors.end(); ++i) {
79 i->generateMetadata(role);
84 mutable ptr_vector<AttributeExtractor> m_extractors;
87 static const XMLCh _AttributeExtractor[] = UNICODE_LITERAL_18(A,t,t,r,i,b,u,t,e,E,x,t,r,a,c,t,o,r);
88 static const XMLCh _type[] = UNICODE_LITERAL_4(t,y,p,e);
90 SHIBSP_DLLLOCAL PluginManager<AttributeExtractor,string,const DOMElement*>::Factory AssertionAttributeExtractorFactory;
91 SHIBSP_DLLLOCAL PluginManager<AttributeExtractor,string,const DOMElement*>::Factory DelegationAttributeExtractorFactory;
92 SHIBSP_DLLLOCAL PluginManager<AttributeExtractor,string,const DOMElement*>::Factory KeyDescriptorAttributeExtractorFactory;
93 SHIBSP_DLLLOCAL PluginManager<AttributeExtractor,string,const DOMElement*>::Factory XMLAttributeExtractorFactory;
94 AttributeExtractor* SHIBSP_DLLLOCAL ChainingExtractorFactory(const DOMElement* const & e)
96 return new ChainingAttributeExtractor(e);
100 void SHIBSP_API shibsp::registerAttributeExtractors()
102 SPConfig::getConfig().AttributeExtractorManager.registerFactory(ASSERTION_ATTRIBUTE_EXTRACTOR, AssertionAttributeExtractorFactory);
103 SPConfig::getConfig().AttributeExtractorManager.registerFactory(DELEGATION_ATTRIBUTE_EXTRACTOR, DelegationAttributeExtractorFactory);
104 SPConfig::getConfig().AttributeExtractorManager.registerFactory(KEYDESCRIPTOR_ATTRIBUTE_EXTRACTOR, KeyDescriptorAttributeExtractorFactory);
105 SPConfig::getConfig().AttributeExtractorManager.registerFactory(XML_ATTRIBUTE_EXTRACTOR, XMLAttributeExtractorFactory);
106 SPConfig::getConfig().AttributeExtractorManager.registerFactory(CHAINING_ATTRIBUTE_EXTRACTOR, ChainingExtractorFactory);
109 AttributeExtractor::AttributeExtractor()
113 AttributeExtractor::~AttributeExtractor()
117 void AttributeExtractor::generateMetadata(SPSSODescriptor& role) const
121 ChainingAttributeExtractor::ChainingAttributeExtractor(const DOMElement* e)
123 SPConfig& conf = SPConfig::getConfig();
125 // Load up the chain of handlers.
126 e = XMLHelper::getFirstChildElement(e, _AttributeExtractor);
128 string t(XMLHelper::getAttrString(e, nullptr, _type));
131 Category::getInstance(SHIBSP_LOGCAT".AttributeExtractor.Chaining").info(
132 "building AttributeExtractor of type (%s)...", t.c_str()
134 auto_ptr<AttributeExtractor> np(conf.AttributeExtractorManager.newPlugin(t.c_str(), e));
135 m_extractors.push_back(np);
137 catch (exception& ex) {
138 Category::getInstance(SHIBSP_LOGCAT".AttributeExtractor.Chaining").error(
139 "caught exception processing embedded AttributeExtractor element: %s", ex.what()
143 e = XMLHelper::getNextSiblingElement(e, _AttributeExtractor);