SSPCPP-616 - clean up concatenated string literals
[shibboleth/cpp-sp.git] / shibsp / handler / impl / ChainingLogoutInitiator.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  * ChainingLogoutInitiator.cpp
23  * 
24  * Chains together multiple LogoutInitiator handlers in sequence.
25  */
26
27 #include "internal.h"
28 #include "exceptions.h"
29 #include "handler/AbstractHandler.h"
30 #include "handler/LogoutInitiator.h"
31 #include "util/SPConstants.h"
32
33 #include <boost/bind.hpp>
34 #include <boost/ptr_container/ptr_vector.hpp>
35 #include <xercesc/util/XMLUniDefs.hpp>
36 #include <xmltooling/util/XMLHelper.h>
37
38 using namespace shibsp;
39 using namespace xmltooling;
40 using namespace boost;
41 using namespace std;
42
43 namespace shibsp {
44
45 #if defined (_MSC_VER)
46     #pragma warning( push )
47     #pragma warning( disable : 4250 )
48 #endif
49
50     class SHIBSP_DLLLOCAL ChainingLogoutInitiator : public AbstractHandler, public LogoutInitiator
51     {
52     public:
53         ChainingLogoutInitiator(const DOMElement* e, const char* appId);
54         virtual ~ChainingLogoutInitiator() {}
55         
56         pair<bool,long> run(SPRequest& request, bool isHandler=true) const;
57
58 #ifndef SHIBSP_LITE
59         void generateMetadata(opensaml::saml2md::SPSSODescriptor& role, const char* handlerURL) const {
60             for_each(m_handlers.begin(), m_handlers.end(), boost::bind(&Handler::generateMetadata, _1, boost::ref(role), handlerURL));
61         }
62 #endif
63
64     private:
65         ptr_vector<Handler> m_handlers;
66     };
67
68 #if defined (_MSC_VER)
69     #pragma warning( pop )
70 #endif
71
72     static const XMLCh _LogoutInitiator[] =     UNICODE_LITERAL_15(L,o,g,o,u,t,I,n,i,t,i,a,t,o,r);
73     static const XMLCh _type[] =                UNICODE_LITERAL_4(t,y,p,e);
74
75     class SHIBSP_DLLLOCAL LogoutInitiatorNodeFilter : public DOMNodeFilter
76     {
77     public:
78 #ifdef SHIBSP_XERCESC_SHORT_ACCEPTNODE
79         short
80 #else
81         FilterAction
82 #endif
83         acceptNode(const DOMNode* node) const {
84             if (XMLHelper::isNodeNamed(node,shibspconstants::SHIB2SPCONFIG_NS,_LogoutInitiator))
85                 return FILTER_REJECT;
86             return FILTER_ACCEPT;
87         }
88     };
89
90     static SHIBSP_DLLLOCAL LogoutInitiatorNodeFilter g_LINFilter;
91
92     Handler* SHIBSP_DLLLOCAL ChainingLogoutInitiatorFactory(const pair<const DOMElement*,const char*>& p)
93     {
94         return new ChainingLogoutInitiator(p.first, p.second);
95     }
96 };
97
98 ChainingLogoutInitiator::ChainingLogoutInitiator(const DOMElement* e, const char* appId)
99     : AbstractHandler(e, Category::getInstance(SHIBSP_LOGCAT ".LogoutInitiator.Chaining"), &g_LINFilter)
100 {
101     SPConfig& conf = SPConfig::getConfig();
102
103     // Load up the chain of handlers.
104     e = XMLHelper::getFirstChildElement(e, _LogoutInitiator);
105     while (e) {
106         string t(XMLHelper::getAttrString(e, nullptr, _type));
107         if (!t.empty()) {
108             try {
109                 auto_ptr<Handler> np(conf.LogoutInitiatorManager.newPlugin(t.c_str(), make_pair(e, appId)));
110                 m_handlers.push_back(np.get());
111                 np.release();
112                 m_handlers.back().setParent(this);
113             }
114             catch (std::exception& ex) {
115                 m_log.error("caught exception processing embedded LogoutInitiator element: %s", ex.what());
116             }
117         }
118         e = XMLHelper::getNextSiblingElement(e, _LogoutInitiator);
119     }
120 }
121
122 pair<bool,long> ChainingLogoutInitiator::run(SPRequest& request, bool isHandler) const
123 {
124     // Defer to base class first.
125     pair<bool,long> ret = LogoutHandler::run(request, isHandler);
126     if (ret.first)
127         return ret;
128
129     for (ptr_vector<Handler>::const_iterator i = m_handlers.begin(); i != m_handlers.end(); ++i) {
130         ret = i->run(request, isHandler);
131         if (ret.first)
132             return ret;
133     }
134     throw ConfigurationException("None of the configured LogoutInitiators handled the request.");
135 }