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 "attribute/filtering/AttributeFilter.h"
25 #include "attribute/filtering/FilteringContext.h"
27 #include <xercesc/util/XMLUniDefs.hpp>
28 #include <xmltooling/util/XMLHelper.h>
30 using namespace shibsp;
31 using namespace xmltooling;
36 class SHIBSP_DLLLOCAL ChainingAttributeFilter : public AttributeFilter
39 ChainingAttributeFilter(const DOMElement* e);
40 virtual ~ChainingAttributeFilter() {
41 for_each(m_filters.begin(), m_filters.end(), xmltooling::cleanup<AttributeFilter>());
50 void filterAttributes(const FilteringContext& context, vector<Attribute*>& attributes) const {
51 for (vector<AttributeFilter*>::const_iterator i=m_filters.begin(); i!=m_filters.end(); ++i) {
53 (*i)->filterAttributes(context, attributes);
58 vector<AttributeFilter*> m_filters;
61 static const XMLCh _AttributeFilter[] = UNICODE_LITERAL_15(A,t,t,r,i,b,u,t,e,F,i,l,t,e,r);
62 static const XMLCh _type[] = UNICODE_LITERAL_4(t,y,p,e);
64 AttributeFilter* SHIBSP_DLLLOCAL ChainingAttributeFilterFactory(const DOMElement* const & e)
66 return new ChainingAttributeFilter(e);
70 ChainingAttributeFilter::ChainingAttributeFilter(const DOMElement* e)
72 SPConfig& conf = SPConfig::getConfig();
74 // Load up the chain of handlers.
75 e = XMLHelper::getFirstChildElement(e, _AttributeFilter);
77 string t(XMLHelper::getAttrString(e, nullptr, _type));
80 m_filters.push_back(conf.AttributeFilterManager.newPlugin(t.c_str(), e));
82 catch (exception& ex) {
83 Category::getInstance(SHIBSP_LOGCAT".AttributeFilter").error(
84 "caught exception processing embedded AttributeFilter element: %s", ex.what()
88 e = XMLHelper::getNextSiblingElement(e, _AttributeFilter);