SSPCPP-616 - clean up concatenated string literals
[shibboleth/cpp-sp.git] / shibsp / attribute / filtering / impl / ChainingAttributeFilter.cpp
1 /**
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.
6  *
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
10  * License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
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.
19  */
20
21 /**
22  * ChainingAttributeFilter.cpp
23  * 
24  * Chains together multiple AttributeFilter plugins.
25  */
26
27 #include "internal.h"
28 #include "exceptions.h"
29 #include "attribute/filtering/AttributeFilter.h"
30 #include "attribute/filtering/FilteringContext.h"
31
32 #include <boost/ptr_container/ptr_vector.hpp>
33 #include <xercesc/util/XMLUniDefs.hpp>
34 #include <xmltooling/util/XMLHelper.h>
35
36 using namespace shibsp;
37 using namespace xmltooling;
38 using namespace boost;
39 using namespace std;
40
41 namespace shibsp {
42
43     class SHIBSP_DLLLOCAL ChainingAttributeFilter : public AttributeFilter
44     {
45     public:
46         ChainingAttributeFilter(const DOMElement* e);
47         virtual ~ChainingAttributeFilter() {}
48         
49         Lockable* lock() {
50             return this;
51         }
52         void unlock() {
53         }
54         
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) {
57                 Locker locker(&(*i));
58                 i->filterAttributes(context, attributes);
59             }
60         }
61
62     private:
63         mutable ptr_vector<AttributeFilter> m_filters;
64     };
65
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);
68
69     AttributeFilter* SHIBSP_DLLLOCAL ChainingAttributeFilterFactory(const DOMElement* const & e)
70     {
71         return new ChainingAttributeFilter(e);
72     }
73 };
74
75 ChainingAttributeFilter::ChainingAttributeFilter(const DOMElement* e)
76 {
77     // Load up the chain of handlers.
78     e = XMLHelper::getFirstChildElement(e, _AttributeFilter);
79     while (e) {
80         string t(XMLHelper::getAttrString(e, nullptr, _type));
81         if (!t.empty()) {
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());
85             np.release();
86         }
87         e = XMLHelper::getNextSiblingElement(e, _AttributeFilter);
88     }
89     if (m_filters.empty())
90         throw ConfigurationException("Chaining AttributeFilter plugin requires at least one child plugin.");
91 }