2 * Copyright 2001-2007 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 * ChainingSessionInitiator.cpp
20 * Chains together multiple SessionInitiator handlers in sequence.
24 #include "exceptions.h"
25 #include "handler/AbstractHandler.h"
26 #include "util/SPConstants.h"
28 #include <xercesc/util/XMLUniDefs.hpp>
29 #include <xmltooling/util/XMLHelper.h>
31 using namespace shibsp;
32 using namespace xmltooling;
33 using namespace log4cpp;
38 #if defined (_MSC_VER)
39 #pragma warning( push )
40 #pragma warning( disable : 4250 )
43 class SHIBSP_DLLLOCAL ChainingSessionInitiator : public AbstractHandler
46 ChainingSessionInitiator(const DOMElement* e, const char* appId);
47 virtual ~ChainingSessionInitiator() {
48 for_each(m_handlers.begin(), m_handlers.end(), xmltooling::cleanup<Handler>());
51 pair<bool,long> run(SPRequest& request, bool isHandler=true) const;
54 vector<Handler*> m_handlers;
57 #if defined (_MSC_VER)
58 #pragma warning( pop )
61 Handler* SHIBSP_DLLLOCAL ChainingSessionInitiatorFactory(const pair<const DOMElement*,const char*>& p)
63 return new ChainingSessionInitiator(p.first, p.second);
66 static const XMLCh SessionInitiator[] = UNICODE_LITERAL_16(S,e,s,s,i,o,n,I,n,i,t,i,a,t,o,r);
67 static const XMLCh _type[] = UNICODE_LITERAL_4(t,y,p,e);
69 class SHIBSP_DLLLOCAL SessionInitiatorNodeFilter : public DOMNodeFilter
72 short acceptNode(const DOMNode* node) const {
73 if (XMLHelper::isNodeNamed(node,shibspconstants::SHIB2SPCONFIG_NS,SessionInitiator))
79 static SHIBSP_DLLLOCAL SessionInitiatorNodeFilter g_SINFilter;
82 ChainingSessionInitiator::ChainingSessionInitiator(const DOMElement* e, const char* appId)
83 : AbstractHandler(e, Category::getInstance(SHIBSP_LOGCAT".SessionInitiator"), &g_SINFilter)
85 SPConfig& conf = SPConfig::getConfig();
87 // Load up the chain of handlers.
88 e = e ? XMLHelper::getFirstChildElement(e, SessionInitiator) : NULL;
90 auto_ptr_char type(e->getAttributeNS(NULL,_type));
91 if (type.get() && *(type.get())) {
92 m_handlers.push_back(conf.SessionInitiatorManager.newPlugin(type.get(),make_pair(e, appId)));
93 m_handlers.back()->setParent(this);
95 e = XMLHelper::getNextSiblingElement(e, SessionInitiator);
99 pair<bool,long> ChainingSessionInitiator::run(SPRequest& request, bool isHandler) const
102 for (vector<Handler*>::const_iterator i = m_handlers.begin(); i!=m_handlers.end(); ++i) {
103 ret = (*i)->run(request, isHandler);
107 throw ConfigurationException("None of the configured SessionInitiators handled the request.");