2 * Copyright 2001-2010 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 "exceptions.h"
25 #include "attribute/filtering/AttributeFilter.h"
26 #include "attribute/filtering/FilteringContext.h"
28 #include <xercesc/util/XMLUniDefs.hpp>
29 #include <xmltooling/util/XMLHelper.h>
31 using namespace shibsp;
32 using namespace xmltooling;
37 class SHIBSP_DLLLOCAL ChainingAttributeFilter : public AttributeFilter
40 ChainingAttributeFilter(const DOMElement* e);
41 virtual ~ChainingAttributeFilter() {
42 for_each(m_filters.begin(), m_filters.end(), xmltooling::cleanup<AttributeFilter>());
51 void filterAttributes(const FilteringContext& context, vector<Attribute*>& attributes) const {
52 for (vector<AttributeFilter*>::const_iterator i=m_filters.begin(); i!=m_filters.end(); ++i) {
54 (*i)->filterAttributes(context, attributes);
59 vector<AttributeFilter*> m_filters;
62 static const XMLCh _AttributeFilter[] = UNICODE_LITERAL_15(A,t,t,r,i,b,u,t,e,F,i,l,t,e,r);
63 static const XMLCh _type[] = UNICODE_LITERAL_4(t,y,p,e);
65 AttributeFilter* SHIBSP_DLLLOCAL ChainingAttributeFilterFactory(const DOMElement* const & e)
67 return new ChainingAttributeFilter(e);
71 ChainingAttributeFilter::ChainingAttributeFilter(const DOMElement* e)
73 // Load up the chain of handlers.
75 e = XMLHelper::getFirstChildElement(e, _AttributeFilter);
77 string t(XMLHelper::getAttrString(e, nullptr, _type));
79 Category::getInstance(SHIBSP_LOGCAT".AttributeFilter.Chaining").info("building AttributeFilter of type (%s)...", t.c_str());
80 m_filters.push_back(SPConfig::getConfig().AttributeFilterManager.newPlugin(t.c_str(), e));
82 e = XMLHelper::getNextSiblingElement(e, _AttributeFilter);
86 for_each(m_filters.begin(), m_filters.end(), xmltooling::cleanup<AttributeFilter>());
89 if (m_filters.empty())
90 throw ConfigurationException("Chaining AttributeFilter plugin requires at least one child plugin.");