From e19605ae02d69fb4d91ee7212e6dc1b77f2e62aa Mon Sep 17 00:00:00 2001 From: cantor Date: Sun, 3 Feb 2008 05:13:34 +0000 Subject: [PATCH] Add chaining extractor. git-svn-id: https://svn.middleware.georgetown.edu/cpp-sp/trunk@2717 cb58f699-b61c-0410-a6fe-9272a202ed29 --- shibsp/Makefile.am | 1 + shibsp/attribute/resolver/AttributeExtractor.h | 3 + .../resolver/impl/ChainingAttributeExtractor.cpp | 117 +++++++++++++++++++++ .../resolver/impl/XMLAttributeExtractor.cpp | 5 - shibsp/shibsp.vcproj | 4 + 5 files changed, 125 insertions(+), 5 deletions(-) create mode 100644 shibsp/attribute/resolver/impl/ChainingAttributeExtractor.cpp diff --git a/shibsp/Makefile.am b/shibsp/Makefile.am index cb13ffb..f839ff7 100644 --- a/shibsp/Makefile.am +++ b/shibsp/Makefile.am @@ -176,6 +176,7 @@ libshibsp_la_SOURCES = \ attribute/filtering/impl/AttributeScopeMatchesShibMDScopeFunctor.cpp \ attribute/resolver/impl/ChainingAttributeResolver.cpp \ attribute/resolver/impl/QueryAttributeResolver.cpp \ + attribute/resolver/impl/ChainingAttributeExtractor.cpp \ attribute/resolver/impl/XMLAttributeExtractor.cpp \ binding/impl/ArtifactResolver.cpp \ binding/impl/SOAPClient.cpp \ diff --git a/shibsp/attribute/resolver/AttributeExtractor.h b/shibsp/attribute/resolver/AttributeExtractor.h index e5adb5a..a0b0a14 100644 --- a/shibsp/attribute/resolver/AttributeExtractor.h +++ b/shibsp/attribute/resolver/AttributeExtractor.h @@ -75,6 +75,9 @@ namespace shibsp { /** AttributeExtractor based on an XML mapping schema. */ #define XML_ATTRIBUTE_EXTRACTOR "XML" + + /** AttributeExtractor based on chaining together other extractors. */ + #define CHAINING_ATTRIBUTE_EXTRACTOR "Chaining" }; #endif /* __shibsp_extractor_h__ */ diff --git a/shibsp/attribute/resolver/impl/ChainingAttributeExtractor.cpp b/shibsp/attribute/resolver/impl/ChainingAttributeExtractor.cpp new file mode 100644 index 0000000..6c23764 --- /dev/null +++ b/shibsp/attribute/resolver/impl/ChainingAttributeExtractor.cpp @@ -0,0 +1,117 @@ +/* + * Copyright 2001-2007 Internet2 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * ChainingAttributeExtractor.cpp + * + * Chains together multiple AttributeExtractor plugins. + */ + +#include "internal.h" +#include "Application.h" +#include "ServiceProvider.h" +#include "attribute/Attribute.h" +#include "attribute/resolver/AttributeExtractor.h" + +#include +#include + +using namespace shibsp; +using namespace opensaml::saml2md; +using namespace xmltooling; +using namespace std; + +namespace shibsp { + + class SHIBSP_DLLLOCAL ChainingAttributeExtractor : public AttributeExtractor + { + public: + ChainingAttributeExtractor(const DOMElement* e); + virtual ~ChainingAttributeExtractor() { + for_each(m_extractors.begin(), m_extractors.end(), xmltooling::cleanup()); + } + + Lockable* lock() { + return this; + } + void unlock() { + } + + void extractAttributes( + const Application& application, + const RoleDescriptor* issuer, + const XMLObject& xmlObject, + vector& attributes + ) const; + + void getAttributeIds(vector& attributes) const { + for (vector::const_iterator i=m_extractors.begin(); i!=m_extractors.end(); ++i) { + Locker locker(*i); + (*i)->getAttributeIds(attributes); + } + } + + private: + vector m_extractors; + }; + + 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); + static const XMLCh _type[] = UNICODE_LITERAL_4(t,y,p,e); + + SHIBSP_DLLLOCAL PluginManager::Factory XMLAttributeExtractorFactory; + AttributeExtractor* SHIBSP_DLLLOCAL ChainingExtractorFactory(const DOMElement* const & e) + { + return new ChainingAttributeExtractor(e); + } +}; + +void SHIBSP_API shibsp::registerAttributeExtractors() +{ + SPConfig::getConfig().AttributeExtractorManager.registerFactory(XML_ATTRIBUTE_EXTRACTOR, XMLAttributeExtractorFactory); + SPConfig::getConfig().AttributeExtractorManager.registerFactory(CHAINING_ATTRIBUTE_EXTRACTOR, ChainingExtractorFactory); +} + +ChainingAttributeExtractor::ChainingAttributeExtractor(const DOMElement* e) +{ + SPConfig& conf = SPConfig::getConfig(); + + // Load up the chain of handlers. + e = e ? XMLHelper::getFirstChildElement(e, _AttributeExtractor) : NULL; + while (e) { + auto_ptr_char type(e->getAttributeNS(NULL,_type)); + if (type.get() && *(type.get())) { + try { + m_extractors.push_back(conf.AttributeExtractorManager.newPlugin(type.get(),e)); + } + catch (exception& ex) { + Category::getInstance(SHIBSP_LOGCAT".AttributeExtractor").error( + "caught exception processing embedded AttributeExtractor element: %s", ex.what() + ); + } + } + e = XMLHelper::getNextSiblingElement(e, _AttributeExtractor); + } +} + +void ChainingAttributeExtractor::extractAttributes( + const Application& application, const RoleDescriptor* issuer, const XMLObject& xmlObject, vector& attributes + ) const +{ + for (vector::const_iterator i=m_extractors.begin(); i!=m_extractors.end(); ++i) { + Locker locker(*i); + (*i)->extractAttributes(application, issuer, xmlObject, attributes); + } +} diff --git a/shibsp/attribute/resolver/impl/XMLAttributeExtractor.cpp b/shibsp/attribute/resolver/impl/XMLAttributeExtractor.cpp index 972a41f..709beda 100644 --- a/shibsp/attribute/resolver/impl/XMLAttributeExtractor.cpp +++ b/shibsp/attribute/resolver/impl/XMLAttributeExtractor.cpp @@ -141,11 +141,6 @@ namespace shibsp { static const XMLCh nameFormat[] = UNICODE_LITERAL_10(n,a,m,e,F,o,r,m,a,t); }; -void SHIBSP_API shibsp::registerAttributeExtractors() -{ - SPConfig::getConfig().AttributeExtractorManager.registerFactory(XML_ATTRIBUTE_EXTRACTOR, XMLAttributeExtractorFactory); -} - XMLExtractorImpl::XMLExtractorImpl(const DOMElement* e, Category& log) : m_log(log), m_document(NULL) { #ifdef _DEBUG diff --git a/shibsp/shibsp.vcproj b/shibsp/shibsp.vcproj index 86c852e..38ae4c3 100644 --- a/shibsp/shibsp.vcproj +++ b/shibsp/shibsp.vcproj @@ -318,6 +318,10 @@ Name="impl" > + + -- 2.1.4