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 * CookieSessionInitiator.cpp
20 * Cookie-based IdP discovery.
24 #include "Application.h"
25 #include "exceptions.h"
26 #include "handler/AbstractHandler.h"
27 #include "handler/SessionInitiator.h"
30 # include <saml/util/CommonDomainCookie.h>
32 # include "lite/CommonDomainCookie.h"
35 #include <xmltooling/XMLToolingConfig.h>
36 #include <xmltooling/util/URLEncoder.h>
38 using namespace shibsp;
39 using namespace opensaml;
40 using namespace xmltooling;
45 #if defined (_MSC_VER)
46 #pragma warning( push )
47 #pragma warning( disable : 4250 )
50 class SHIBSP_DLLLOCAL CookieSessionInitiator : public SessionInitiator, public AbstractHandler
53 CookieSessionInitiator(const DOMElement* e, const char* appId)
54 : AbstractHandler(e, Category::getInstance(SHIBSP_LOGCAT".SessionInitiator.Cookie")),
55 m_followMultiple(getBool("followMultiple").second) {
56 m_supportedOptions.insert("isPassive");
58 virtual ~CookieSessionInitiator() {}
60 pair<bool,long> run(SPRequest& request, string& entityID, bool isHandler=true) const;
63 bool m_followMultiple;
66 #if defined (_MSC_VER)
67 #pragma warning( pop )
70 SessionInitiator* SHIBSP_DLLLOCAL CookieSessionInitiatorFactory(const pair<const DOMElement*,const char*>& p)
72 return new CookieSessionInitiator(p.first, p.second);
77 pair<bool,long> CookieSessionInitiator::run(SPRequest& request, string& entityID, bool isHandler) const
79 // The IdP CANNOT be specified for us to run.
80 if (!entityID.empty() || !checkCompatibility(request, isHandler))
81 return make_pair(false,0L);
83 // If there's no entityID yet, we can check for cookie processing.
84 CommonDomainCookie cdc(request.getCookie(CommonDomainCookie::CDCName));
85 if ((m_followMultiple && cdc.get().size() > 0) || (!m_followMultiple && cdc.get().size() == 1)) {
86 entityID = cdc.get().back();
87 m_log.info("set entityID (%s) from IdP history cookie", entityID.c_str());
90 return make_pair(false,0L);