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 * ChainingAttributeFilter.cpp
20 * Chains together multiple AttributeFilter plugins.
24 #include "attribute/filtering/AttributeFilter.h"
25 #include "attribute/filtering/FilteringContext.h"
27 #include <log4cpp/Category.hh>
28 #include <xercesc/util/XMLUniDefs.hpp>
29 #include <xmltooling/util/XMLHelper.h>
31 using namespace shibsp;
32 using namespace xmltooling;
33 using namespace log4cpp;
38 class SHIBSP_DLLLOCAL ChainingAttributeFilter : public AttributeFilter
41 ChainingAttributeFilter(const DOMElement* e);
42 virtual ~ChainingAttributeFilter() {
43 for_each(m_filters.begin(), m_filters.end(), xmltooling::cleanup<AttributeFilter>());
52 void filterAttributes(const FilteringContext& context, multimap<string,Attribute*>& attributes) const {
53 for (vector<AttributeFilter*>::const_iterator i=m_filters.begin(); i!=m_filters.end(); ++i) {
55 (*i)->filterAttributes(context, attributes);
60 vector<AttributeFilter*> m_filters;
63 static const XMLCh _AttributeFilter[] = UNICODE_LITERAL_15(A,t,t,r,i,b,u,t,e,F,i,l,t,e,r);
64 static const XMLCh _type[] = UNICODE_LITERAL_4(t,y,p,e);
66 AttributeFilter* SHIBSP_DLLLOCAL ChainingAttributeFilterFactory(const DOMElement* const & e)
68 return new ChainingAttributeFilter(e);
72 ChainingAttributeFilter::ChainingAttributeFilter(const DOMElement* e)
74 SPConfig& conf = SPConfig::getConfig();
76 // Load up the chain of handlers.
77 e = e ? XMLHelper::getFirstChildElement(e, _AttributeFilter) : NULL;
79 auto_ptr_char type(e->getAttributeNS(NULL,_type));
80 if (type.get() && *(type.get())) {
82 m_filters.push_back(conf.AttributeFilterManager.newPlugin(type.get(),e));
84 catch (exception& ex) {
85 Category::getInstance(SHIBSP_LOGCAT".AttributeFilter").error(
86 "caught exception processing embedded AttributeFilter element: %s", ex.what()
90 e = XMLHelper::getNextSiblingElement(e, _AttributeFilter);