2 * Licensed to the University Corporation for Advanced Internet
3 * Development, Inc. (UCAID) under one or more contributor license
4 * agreements. See the NOTICE file distributed with this work for
5 * additional information regarding copyright ownership.
7 * UCAID licenses this file to you under the Apache License,
8 * Version 2.0 (the "License"); you may not use this file except
9 * in compliance with the License. You may obtain a copy of the
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
17 * either express or implied. See the License for the specific
18 * language governing permissions and limitations under the License.
22 * ChainingAttributeFilter.cpp
24 * Chains together multiple AttributeFilter plugins.
28 #include "exceptions.h"
29 #include "attribute/filtering/AttributeFilter.h"
30 #include "attribute/filtering/FilteringContext.h"
32 #include <boost/ptr_container/ptr_vector.hpp>
33 #include <xercesc/util/XMLUniDefs.hpp>
34 #include <xmltooling/util/XMLHelper.h>
36 using namespace shibsp;
37 using namespace xmltooling;
38 using namespace boost;
43 class SHIBSP_DLLLOCAL ChainingAttributeFilter : public AttributeFilter
46 ChainingAttributeFilter(const DOMElement* e);
47 virtual ~ChainingAttributeFilter() {}
55 void filterAttributes(const FilteringContext& context, vector<Attribute*>& attributes) const {
56 for (ptr_vector<AttributeFilter>::iterator i = m_filters.begin(); i != m_filters.end(); ++i) {
58 i->filterAttributes(context, attributes);
63 mutable ptr_vector<AttributeFilter> m_filters;
66 static const XMLCh _AttributeFilter[] = UNICODE_LITERAL_15(A,t,t,r,i,b,u,t,e,F,i,l,t,e,r);
67 static const XMLCh _type[] = UNICODE_LITERAL_4(t,y,p,e);
69 AttributeFilter* SHIBSP_DLLLOCAL ChainingAttributeFilterFactory(const DOMElement* const & e)
71 return new ChainingAttributeFilter(e);
75 ChainingAttributeFilter::ChainingAttributeFilter(const DOMElement* e)
77 // Load up the chain of handlers.
78 e = XMLHelper::getFirstChildElement(e, _AttributeFilter);
80 string t(XMLHelper::getAttrString(e, nullptr, _type));
82 Category::getInstance(SHIBSP_LOGCAT".AttributeFilter.Chaining").info("building AttributeFilter of type (%s)...", t.c_str());
83 auto_ptr<AttributeFilter> np(SPConfig::getConfig().AttributeFilterManager.newPlugin(t.c_str(), e));
84 m_filters.push_back(np.get());
87 e = XMLHelper::getNextSiblingElement(e, _AttributeFilter);
89 if (m_filters.empty())
90 throw ConfigurationException("Chaining AttributeFilter plugin requires at least one child plugin.");