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 // Make sure new version gets run.
64 extractAttributes(application, nullptr, issuer, xmlObject, attributes);
67 void extractAttributes(
68 const Application& application,
69 const GenericRequest* request,
70 const RoleDescriptor* issuer,
71 const XMLObject& xmlObject,
72 vector<Attribute*>& attributes
74 for (ptr_vector<AttributeExtractor>::iterator i = m_extractors.begin(); i != m_extractors.end(); ++i) {
76 i->extractAttributes(application, request, issuer, xmlObject, attributes);
80 void getAttributeIds(vector<string>& attributes) const {
81 for (ptr_vector<AttributeExtractor>::iterator i = m_extractors.begin(); i != m_extractors.end(); ++i) {
83 i->getAttributeIds(attributes);
87 void generateMetadata(SPSSODescriptor& role) const {
88 for (ptr_vector<AttributeExtractor>::iterator i = m_extractors.begin(); i != m_extractors.end(); ++i) {
90 i->generateMetadata(role);
95 mutable ptr_vector<AttributeExtractor> m_extractors;
98 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);
99 static const XMLCh _type[] = UNICODE_LITERAL_4(t,y,p,e);
101 SHIBSP_DLLLOCAL PluginManager<AttributeExtractor,string,const DOMElement*>::Factory AssertionAttributeExtractorFactory;
102 SHIBSP_DLLLOCAL PluginManager<AttributeExtractor,string,const DOMElement*>::Factory MetadataAttributeExtractorFactory;
103 SHIBSP_DLLLOCAL PluginManager<AttributeExtractor,string,const DOMElement*>::Factory DelegationAttributeExtractorFactory;
104 SHIBSP_DLLLOCAL PluginManager<AttributeExtractor,string,const DOMElement*>::Factory KeyDescriptorAttributeExtractorFactory;
105 SHIBSP_DLLLOCAL PluginManager<AttributeExtractor,string,const DOMElement*>::Factory XMLAttributeExtractorFactory;
106 AttributeExtractor* SHIBSP_DLLLOCAL ChainingExtractorFactory(const DOMElement* const & e)
108 return new ChainingAttributeExtractor(e);
112 void SHIBSP_API shibsp::registerAttributeExtractors()
114 SPConfig::getConfig().AttributeExtractorManager.registerFactory(ASSERTION_ATTRIBUTE_EXTRACTOR, AssertionAttributeExtractorFactory);
115 SPConfig::getConfig().AttributeExtractorManager.registerFactory(METADATA_ATTRIBUTE_EXTRACTOR, MetadataAttributeExtractorFactory);
116 SPConfig::getConfig().AttributeExtractorManager.registerFactory(DELEGATION_ATTRIBUTE_EXTRACTOR, DelegationAttributeExtractorFactory);
117 SPConfig::getConfig().AttributeExtractorManager.registerFactory(KEYDESCRIPTOR_ATTRIBUTE_EXTRACTOR, KeyDescriptorAttributeExtractorFactory);
118 SPConfig::getConfig().AttributeExtractorManager.registerFactory(XML_ATTRIBUTE_EXTRACTOR, XMLAttributeExtractorFactory);
119 SPConfig::getConfig().AttributeExtractorManager.registerFactory(CHAINING_ATTRIBUTE_EXTRACTOR, ChainingExtractorFactory);
122 AttributeExtractor::AttributeExtractor()
126 AttributeExtractor::~AttributeExtractor()
130 void AttributeExtractor::generateMetadata(SPSSODescriptor& role) const
134 void AttributeExtractor::extractAttributes(
135 const Application& application,
136 const GenericRequest* request,
137 const RoleDescriptor* issuer,
138 const XMLObject& xmlObject,
139 vector<Attribute*>& attributes
142 // Default call into deprecated method.
143 extractAttributes(application, issuer, xmlObject, attributes);
146 void AttributeExtractor::extractAttributes(
147 const Application& application,
148 const RoleDescriptor* issuer,
149 const XMLObject& xmlObject,
150 vector<Attribute*>& attributes
153 // Empty default for deprecated method.
156 ChainingAttributeExtractor::ChainingAttributeExtractor(const DOMElement* e)
158 SPConfig& conf = SPConfig::getConfig();
160 // Load up the chain of handlers.
161 e = XMLHelper::getFirstChildElement(e, _AttributeExtractor);
163 string t(XMLHelper::getAttrString(e, nullptr, _type));
166 Category::getInstance(SHIBSP_LOGCAT ".AttributeExtractor.Chaining").info(
167 "building AttributeExtractor of type (%s)...", t.c_str()
169 auto_ptr<AttributeExtractor> np(conf.AttributeExtractorManager.newPlugin(t.c_str(), e));
170 m_extractors.push_back(np.get());
173 catch (exception& ex) {
174 Category::getInstance(SHIBSP_LOGCAT ".AttributeExtractor.Chaining").error(
175 "caught exception processing embedded AttributeExtractor element: %s", ex.what()
179 e = XMLHelper::getNextSiblingElement(e, _AttributeExtractor);