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 * ChainingLogoutInitiator.cpp
20 * Chains together multiple LogoutInitiator handlers in sequence.
24 #include "exceptions.h"
25 #include "handler/AbstractHandler.h"
26 #include "handler/LogoutInitiator.h"
27 #include "util/SPConstants.h"
29 #include <xercesc/util/XMLUniDefs.hpp>
30 #include <xmltooling/util/XMLHelper.h>
32 using namespace shibsp;
33 using namespace xmltooling;
38 #if defined (_MSC_VER)
39 #pragma warning( push )
40 #pragma warning( disable : 4250 )
43 class SHIBSP_DLLLOCAL ChainingLogoutInitiator : public AbstractHandler, public LogoutInitiator
46 ChainingLogoutInitiator(const DOMElement* e, const char* appId);
47 virtual ~ChainingLogoutInitiator() {
48 for_each(m_handlers.begin(), m_handlers.end(), xmltooling::cleanup<Handler>());
51 pair<bool,long> run(SPRequest& request, bool isHandler=true) const;
54 void generateMetadata(opensaml::saml2md::SPSSODescriptor& role, const char* handlerURL) const {
55 for (vector<Handler*>::const_iterator i = m_handlers.begin(); i!=m_handlers.end(); ++i)
56 (*i)->generateMetadata(role, handlerURL);
61 vector<Handler*> m_handlers;
64 #if defined (_MSC_VER)
65 #pragma warning( pop )
68 static const XMLCh _LogoutInitiator[] = UNICODE_LITERAL_15(L,o,g,o,u,t,I,n,i,t,i,a,t,o,r);
69 static const XMLCh _type[] = UNICODE_LITERAL_4(t,y,p,e);
71 class SHIBSP_DLLLOCAL LogoutInitiatorNodeFilter : public DOMNodeFilter
74 #ifdef SHIBSP_XERCESC_SHORT_ACCEPTNODE
79 acceptNode(const DOMNode* node) const {
80 if (XMLHelper::isNodeNamed(node,shibspconstants::SHIB2SPCONFIG_NS,_LogoutInitiator))
86 static SHIBSP_DLLLOCAL LogoutInitiatorNodeFilter g_LINFilter;
88 Handler* SHIBSP_DLLLOCAL ChainingLogoutInitiatorFactory(const pair<const DOMElement*,const char*>& p)
90 return new ChainingLogoutInitiator(p.first, p.second);
94 ChainingLogoutInitiator::ChainingLogoutInitiator(const DOMElement* e, const char* appId)
95 : AbstractHandler(e, Category::getInstance(SHIBSP_LOGCAT".LogoutInitiator.Chaining"), &g_LINFilter)
97 SPConfig& conf = SPConfig::getConfig();
99 // Load up the chain of handlers.
100 e = XMLHelper::getFirstChildElement(e, _LogoutInitiator);
102 string t(XMLHelper::getAttrString(e, nullptr, _type));
105 m_handlers.push_back(conf.LogoutInitiatorManager.newPlugin(t.c_str(), make_pair(e, appId)));
106 m_handlers.back()->setParent(this);
108 catch (exception& ex) {
109 m_log.error("caught exception processing embedded LogoutInitiator element: %s", ex.what());
112 e = XMLHelper::getNextSiblingElement(e, _LogoutInitiator);
116 pair<bool,long> ChainingLogoutInitiator::run(SPRequest& request, bool isHandler) const
118 // Defer to base class first.
119 pair<bool,long> ret = LogoutHandler::run(request, isHandler);
123 for (vector<Handler*>::const_iterator i = m_handlers.begin(); i!=m_handlers.end(); ++i) {
124 ret = (*i)->run(request, isHandler);
128 throw ConfigurationException("None of the configured LogoutInitiators handled the request.");