2 * Copyright 2001-2007 Internet2
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 * ChainingAttributeExtractor.cpp
20 * Chains together multiple AttributeExtractor plugins.
24 #include "Application.h"
25 #include "ServiceProvider.h"
26 #include "attribute/Attribute.h"
27 #include "attribute/resolver/AttributeExtractor.h"
29 #include <xercesc/util/XMLUniDefs.hpp>
30 #include <xmltooling/util/XMLHelper.h>
32 using namespace shibsp;
33 using namespace opensaml::saml2md;
34 using namespace xmltooling;
39 class SHIBSP_DLLLOCAL ChainingAttributeExtractor : public AttributeExtractor
42 ChainingAttributeExtractor(const DOMElement* e);
43 virtual ~ChainingAttributeExtractor() {
44 for_each(m_extractors.begin(), m_extractors.end(), xmltooling::cleanup<AttributeExtractor>());
53 void extractAttributes(
54 const Application& application,
55 const RoleDescriptor* issuer,
56 const XMLObject& xmlObject,
57 vector<Attribute*>& attributes
60 void getAttributeIds(vector<string>& attributes) const {
61 for (vector<AttributeExtractor*>::const_iterator i=m_extractors.begin(); i!=m_extractors.end(); ++i) {
63 (*i)->getAttributeIds(attributes);
68 vector<AttributeExtractor*> m_extractors;
71 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);
72 static const XMLCh _type[] = UNICODE_LITERAL_4(t,y,p,e);
74 SHIBSP_DLLLOCAL PluginManager<AttributeExtractor,string,const DOMElement*>::Factory XMLAttributeExtractorFactory;
75 AttributeExtractor* SHIBSP_DLLLOCAL ChainingExtractorFactory(const DOMElement* const & e)
77 return new ChainingAttributeExtractor(e);
81 void SHIBSP_API shibsp::registerAttributeExtractors()
83 SPConfig::getConfig().AttributeExtractorManager.registerFactory(XML_ATTRIBUTE_EXTRACTOR, XMLAttributeExtractorFactory);
84 SPConfig::getConfig().AttributeExtractorManager.registerFactory(CHAINING_ATTRIBUTE_EXTRACTOR, ChainingExtractorFactory);
87 ChainingAttributeExtractor::ChainingAttributeExtractor(const DOMElement* e)
89 SPConfig& conf = SPConfig::getConfig();
91 // Load up the chain of handlers.
92 e = e ? XMLHelper::getFirstChildElement(e, _AttributeExtractor) : NULL;
94 auto_ptr_char type(e->getAttributeNS(NULL,_type));
95 if (type.get() && *(type.get())) {
97 m_extractors.push_back(conf.AttributeExtractorManager.newPlugin(type.get(),e));
99 catch (exception& ex) {
100 Category::getInstance(SHIBSP_LOGCAT".AttributeExtractor").error(
101 "caught exception processing embedded AttributeExtractor element: %s", ex.what()
105 e = XMLHelper::getNextSiblingElement(e, _AttributeExtractor);
109 void ChainingAttributeExtractor::extractAttributes(
110 const Application& application, const RoleDescriptor* issuer, const XMLObject& xmlObject, vector<Attribute*>& attributes
113 for (vector<AttributeExtractor*>::const_iterator i=m_extractors.begin(); i!=m_extractors.end(); ++i) {
115 (*i)->extractAttributes(application, issuer, xmlObject, attributes);